Save This Page
Home » jcommon-1.0.13 » org.jfree » chart » renderer » xy » junit » [javadoc | source]
    1   /* ===========================================================
    2    * JFreeChart : a free chart library for the Java(tm) platform
    3    * ===========================================================
    4    *
    5    * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
    6    *
    7    * Project Info:  http://www.jfree.org/jfreechart/index.html
    8    *
    9    * This library is free software; you can redistribute it and/or modify it 
   10    * under the terms of the GNU Lesser General Public License as published by 
   11    * the Free Software Foundation; either version 2.1 of the License, or 
   12    * (at your option) any later version.
   13    *
   14    * This library is distributed in the hope that it will be useful, but 
   15    * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
   16    * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
   17    * License for more details.
   18    *
   19    * You should have received a copy of the GNU Lesser General Public License 
   20    * along with this library; if not, write to the Free Software Foundation, 
   21    * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
   22    *
   23    * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
   24    * in the United States and other countries.]
   25    *
   26    * --------------------------------
   27    * StandardXYItemRendererTests.java
   28    * --------------------------------
   29    * (C) Copyright 2003, 2004, by Object Refinery Limited and Contributors.
   30    *
   31    * Original Author:  David Gilbert (for Object Refinery Limited);
   32    * Contributor(s):   -;
   33    *
   34    * $Id: StandardXYItemRendererTests.java,v 1.4 2005/06/02 09:14:45 mungady Exp $
   35    *
   36    * Changes
   37    * -------
   38    * 25-Mar-2003 : Version 1 (DG);
   39    * 22-Oct-2003 : Added hashCode test (DG);
   40    * 08-Oct-2004 : Strengthened test for equals() method (DG);
   41    * 
   42    */
   43   
   44   package org.jfree.chart.renderer.xy.junit;
   45   
   46   import java.awt.geom.Line2D;
   47   import java.io.ByteArrayInputStream;
   48   import java.io.ByteArrayOutputStream;
   49   import java.io.ObjectInput;
   50   import java.io.ObjectInputStream;
   51   import java.io.ObjectOutput;
   52   import java.io.ObjectOutputStream;
   53   
   54   import junit.framework.Test;
   55   import junit.framework.TestCase;
   56   import junit.framework.TestSuite;
   57   
   58   import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
   59   import org.jfree.util.UnitType;
   60   
   61   /**
   62    * Tests for the {@link StandardXYItemRenderer} class.
   63    */
   64   public class StandardXYItemRendererTests extends TestCase {
   65   
   66       /**
   67        * Returns the tests as a test suite.
   68        *
   69        * @return The test suite.
   70        */
   71       public static Test suite() {
   72           return new TestSuite(StandardXYItemRendererTests.class);
   73       }
   74   
   75       /**
   76        * Constructs a new set of tests.
   77        *
   78        * @param name  the name of the tests.
   79        */
   80       public StandardXYItemRendererTests(String name) {
   81           super(name);
   82       }
   83   
   84       /**
   85        * Test that the equals() method distinguishes all fields.
   86        */
   87       public void testEquals() {
   88           StandardXYItemRenderer r1 = new StandardXYItemRenderer();
   89           StandardXYItemRenderer r2 = new StandardXYItemRenderer();
   90           assertEquals(r1, r2);
   91           
   92           r1.setPlotShapes(true);
   93           assertFalse(r1.equals(r2));
   94           r2.setPlotShapes(true);
   95           assertTrue(r1.equals(r2));
   96           
   97           r1.setPlotLines(false);
   98           assertFalse(r1.equals(r2));
   99           r2.setPlotLines(false);
  100           assertTrue(r1.equals(r2));
  101   
  102           r1.setPlotImages(true);
  103           assertFalse(r1.equals(r2));
  104           r2.setPlotImages(true);
  105           assertTrue(r1.equals(r2));
  106   
  107           r1.setShapesFilled(false);
  108           assertFalse(r1.equals(r2));
  109           r2.setShapesFilled(false);
  110           assertTrue(r1.equals(r2));
  111           
  112           r1.setGapThresholdType(UnitType.ABSOLUTE);
  113           assertFalse(r1.equals(r2));
  114           r2.setGapThresholdType(UnitType.ABSOLUTE);
  115           assertTrue(r1.equals(r2));
  116           
  117           r1.setGapThreshold(1.23);
  118           assertFalse(r1.equals(r2));
  119           r2.setGapThreshold(1.23);
  120           assertTrue(r1.equals(r2));
  121           
  122           r1.setLegendLine(new Line2D.Double(1.0, 2.0, 3.0, 4.0));
  123           assertFalse(r1.equals(r2));
  124           r2.setLegendLine(new Line2D.Double(1.0, 2.0, 3.0, 4.0));
  125           assertTrue(r1.equals(r2));
  126       }
  127   
  128       /**
  129        * Two objects that are equal are required to return the same hashCode. 
  130        */
  131       public void testHashcode() {
  132           StandardXYItemRenderer r1 = new StandardXYItemRenderer();
  133           StandardXYItemRenderer r2 = new StandardXYItemRenderer();
  134           assertTrue(r1.equals(r2));
  135           int h1 = r1.hashCode();
  136           int h2 = r2.hashCode();
  137           assertEquals(h1, h2);
  138       }
  139       
  140       /**
  141        * Confirm that cloning works.
  142        */
  143       public void testCloning() {
  144           StandardXYItemRenderer r1 = new StandardXYItemRenderer();
  145           StandardXYItemRenderer r2 = null;
  146           try {
  147               r2 = (StandardXYItemRenderer) r1.clone();
  148           }
  149           catch (CloneNotSupportedException e) {
  150               System.err.println("Failed to clone.");
  151           }
  152           assertTrue(r1 != r2);
  153           assertTrue(r1.getClass() == r2.getClass());
  154           assertTrue(r1.equals(r2));
  155       }
  156   
  157       /**
  158        * Serialize an instance, restore it, and check for equality.
  159        */
  160       public void testSerialization() {
  161   
  162           StandardXYItemRenderer r1 = new StandardXYItemRenderer();
  163           StandardXYItemRenderer r2 = null;
  164   
  165           try {
  166               ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  167               ObjectOutput out = new ObjectOutputStream(buffer);
  168               out.writeObject(r1);
  169               out.close();
  170   
  171               ObjectInput in = new ObjectInputStream(
  172                   new ByteArrayInputStream(buffer.toByteArray())
  173               );
  174               r2 = (StandardXYItemRenderer) in.readObject();
  175               in.close();
  176           }
  177           catch (Exception e) {
  178               System.out.println(e.toString());
  179           }
  180           assertEquals(r1, r2);
  181   
  182       }
  183   
  184   }

Save This Page
Home » jcommon-1.0.13 » org.jfree » chart » renderer » xy » junit » [javadoc | source]