Save This Page
Home » jcommon-1.0.13 » org.jfree » chart » renderer » category » 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    * BoxAndWhiskerRendererTests.java
   28    * -------------------------------
   29    * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
   30    *
   31    * Original Author:  David Gilbert (for Object Refinery Limited);
   32    * Contributor(s):   -;
   33    *
   34    * $Id: BoxAndWhiskerRendererTests.java,v 1.3 2005/03/08 10:35:26 mungady Exp $
   35    *
   36    * Changes
   37    * -------
   38    * 22-Oct-2003 : Version 1 (DG);
   39    * 23-Apr-2004 : Extended testEquals() method (DG);
   40    *
   41    */
   42   
   43   package org.jfree.chart.renderer.category.junit;
   44   
   45   import java.awt.Color;
   46   import java.io.ByteArrayInputStream;
   47   import java.io.ByteArrayOutputStream;
   48   import java.io.ObjectInput;
   49   import java.io.ObjectInputStream;
   50   import java.io.ObjectOutput;
   51   import java.io.ObjectOutputStream;
   52   
   53   import junit.framework.Test;
   54   import junit.framework.TestCase;
   55   import junit.framework.TestSuite;
   56   
   57   import org.jfree.chart.renderer.category.BoxAndWhiskerRenderer;
   58   
   59   /**
   60    * Tests for the {@link BoxAndWhiskerRenderer} class.
   61    */
   62   public class BoxAndWhiskerRendererTests extends TestCase {
   63   
   64       /**
   65        * Returns the tests as a test suite.
   66        *
   67        * @return The test suite.
   68        */
   69       public static Test suite() {
   70           return new TestSuite(BoxAndWhiskerRendererTests.class);
   71       }
   72   
   73       /**
   74        * Constructs a new set of tests.
   75        *
   76        * @param name  the name of the tests.
   77        */
   78       public BoxAndWhiskerRendererTests(String name) {
   79           super(name);
   80       }
   81   
   82       /**
   83        * Test that the equals() method distinguishes all fields.
   84        */
   85       public void testEquals() {
   86           BoxAndWhiskerRenderer r1 = new BoxAndWhiskerRenderer();
   87           BoxAndWhiskerRenderer r2 = new BoxAndWhiskerRenderer();
   88           assertEquals(r1, r2);
   89           
   90           r1.setArtifactPaint(Color.yellow);
   91           assertFalse(r1.equals(r2));
   92           r2.setArtifactPaint(Color.yellow);
   93           assertEquals(r1, r2);
   94           
   95           r1.setFillBox(!r1.getFillBox());
   96           assertFalse(r1.equals(r2));
   97           r2.setFillBox(!r2.getFillBox());
   98           assertEquals(r1, r2);
   99           
  100           r1.setItemMargin(0.11);
  101           assertFalse(r1.equals(r2));
  102           r2.setItemMargin(0.11);
  103           assertEquals(r1, r2);
  104           
  105       }
  106   
  107       /**
  108        * Two objects that are equal are required to return the same hashCode. 
  109        */
  110       public void testHashcode() {
  111           BoxAndWhiskerRenderer r1 = new BoxAndWhiskerRenderer();
  112           BoxAndWhiskerRenderer r2 = new BoxAndWhiskerRenderer();
  113           assertTrue(r1.equals(r2));
  114           int h1 = r1.hashCode();
  115           int h2 = r2.hashCode();
  116           assertEquals(h1, h2);
  117       }
  118       
  119       /**
  120        * Confirm that cloning works.
  121        */
  122       public void testCloning() {
  123           BoxAndWhiskerRenderer r1 = new BoxAndWhiskerRenderer();
  124           BoxAndWhiskerRenderer r2 = null;
  125           try {
  126               r2 = (BoxAndWhiskerRenderer) r1.clone();
  127           }
  128           catch (CloneNotSupportedException e) {
  129               System.err.println("Failed to clone.");
  130           }
  131           assertTrue(r1 != r2);
  132           assertTrue(r1.getClass() == r2.getClass());
  133           assertTrue(r1.equals(r2));
  134       }
  135   
  136       /**
  137        * Serialize an instance, restore it, and check for equality.
  138        */
  139       public void testSerialization() {
  140   
  141           BoxAndWhiskerRenderer r1 = new BoxAndWhiskerRenderer();
  142           BoxAndWhiskerRenderer r2 = null;
  143   
  144           try {
  145               ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  146               ObjectOutput out = new ObjectOutputStream(buffer);
  147               out.writeObject(r1);
  148               out.close();
  149   
  150               ObjectInput in = new ObjectInputStream(
  151                   new ByteArrayInputStream(buffer.toByteArray())
  152               );
  153               r2 = (BoxAndWhiskerRenderer) in.readObject();
  154               in.close();
  155           }
  156           catch (Exception e) {
  157               System.out.println(e.toString());
  158           }
  159           assertEquals(r1, r2);
  160   
  161       }
  162   
  163   }

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