Save This Page
Home » jcommon-1.0.13 » org.jfree » chart » block » 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    * BlockContainerTests.java
   28    * ------------------------
   29    * (C) Copyright 2005, by Object Refinery Limited and Contributors.
   30    *
   31    * Original Author:  David Gilbert (for Object Refinery Limited);
   32    * Contributor(s):   -;
   33    *
   34    * $Id: BlockContainerTests.java,v 1.2 2005/05/03 13:23:22 mungady Exp $
   35    *
   36    * Changes
   37    * -------
   38    * 04-Feb-2005 : Version 1 (DG);
   39    *
   40    */
   41   
   42   package org.jfree.chart.block.junit;
   43   
   44   import java.io.ByteArrayInputStream;
   45   import java.io.ByteArrayOutputStream;
   46   import java.io.ObjectInput;
   47   import java.io.ObjectInputStream;
   48   import java.io.ObjectOutput;
   49   import java.io.ObjectOutputStream;
   50   
   51   import junit.framework.Test;
   52   import junit.framework.TestCase;
   53   import junit.framework.TestSuite;
   54   
   55   import org.jfree.chart.block.BlockContainer;
   56   import org.jfree.chart.block.ColumnArrangement;
   57   import org.jfree.chart.block.EmptyBlock;
   58   import org.jfree.chart.block.FlowArrangement;
   59   
   60   /**
   61    * Tests for the {@link BlockContainer} class.
   62    */
   63   public class BlockContainerTests extends TestCase {
   64       
   65       /**
   66        * Returns the tests as a test suite.
   67        *
   68        * @return The test suite.
   69        */
   70       public static Test suite() {
   71           return new TestSuite(BlockContainerTests.class);
   72       }
   73   
   74       /**
   75        * Constructs a new set of tests.
   76        *
   77        * @param name  the name of the tests.
   78        */
   79       public BlockContainerTests(String name) {
   80           super(name);
   81       }
   82       
   83       /**
   84        * Confirm that the equals() method can distinguish all the required fields.
   85        */
   86       public void testEquals() {
   87           BlockContainer c1 = new BlockContainer(new FlowArrangement());
   88           BlockContainer c2 = new BlockContainer(new FlowArrangement());
   89           assertTrue(c1.equals(c2));
   90           assertTrue(c2.equals(c2));
   91           
   92           c1.setArrangement(new ColumnArrangement());
   93           assertFalse(c1.equals(c2));
   94           c2.setArrangement(new ColumnArrangement());
   95           assertTrue(c1.equals(c2));
   96           
   97           c1.add(new EmptyBlock(1.2, 3.4));
   98           assertFalse(c1.equals(c2));
   99           c2.add(new EmptyBlock(1.2, 3.4));
  100           assertTrue(c1.equals(c2));
  101       }
  102   
  103       /**
  104        * Confirm that cloning works.
  105        */
  106       public void testCloning() {
  107           BlockContainer c1 = new BlockContainer(new FlowArrangement());
  108           c1.add(new EmptyBlock(1.2, 3.4));
  109           
  110           BlockContainer c2 = null;
  111           
  112           try {
  113               c2 = (BlockContainer) c1.clone();
  114           }
  115           catch (CloneNotSupportedException e) {
  116               System.err.println("Failed to clone.");
  117           }
  118           assertTrue(c1 != c2);
  119           assertTrue(c1.getClass() == c2.getClass());
  120           assertTrue(c1.equals(c2));
  121       }
  122   
  123       /**
  124        * Serialize an instance, restore it, and check for equality.
  125        */
  126       public void testSerialization() {
  127           BlockContainer c1 = new BlockContainer();
  128           c1.add(new EmptyBlock(1.2, 3.4));
  129           BlockContainer c2 = null;
  130           try {
  131               ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  132               ObjectOutput out = new ObjectOutputStream(buffer);
  133               out.writeObject(c1);
  134               out.close();
  135   
  136               ObjectInput in = new ObjectInputStream(
  137                   new ByteArrayInputStream(buffer.toByteArray())
  138               );
  139               c2 = (BlockContainer) in.readObject();
  140               in.close();
  141           }
  142           catch (Exception e) {
  143               fail(e.toString());
  144           }
  145           assertEquals(c1, c2);
  146       }
  147      
  148   }

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