KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > block > junit > FlowArrangementTests


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
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * -------------------------
28  * FlowArrangementTests.java
29  * -------------------------
30  * (C) Copyright 2005, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: FlowArrangementTests.java,v 1.1.2.1 2006/10/03 15:41:44 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 04-Feb-2005 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.chart.block.junit;
44
45 import java.io.ByteArrayInputStream JavaDoc;
46 import java.io.ByteArrayOutputStream JavaDoc;
47 import java.io.ObjectInput JavaDoc;
48 import java.io.ObjectInputStream JavaDoc;
49 import java.io.ObjectOutput JavaDoc;
50 import java.io.ObjectOutputStream JavaDoc;
51
52 import junit.framework.Test;
53 import junit.framework.TestCase;
54 import junit.framework.TestSuite;
55
56 import org.jfree.chart.block.FlowArrangement;
57 import org.jfree.ui.HorizontalAlignment;
58 import org.jfree.ui.VerticalAlignment;
59
60 /**
61  * Tests for the {@link FlowArrangement} class.
62  */

63 public class FlowArrangementTests 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(FlowArrangementTests.class);
72     }
73
74     /**
75      * Constructs a new set of tests.
76      *
77      * @param name the name of the tests.
78      */

79     public FlowArrangementTests(String JavaDoc 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         FlowArrangement f1 = new FlowArrangement(
88             HorizontalAlignment.LEFT, VerticalAlignment.TOP, 1.0, 2.0
89         );
90         FlowArrangement f2 = new FlowArrangement(
91             HorizontalAlignment.LEFT, VerticalAlignment.TOP, 1.0, 2.0
92         );
93         assertTrue(f1.equals(f2));
94         assertTrue(f2.equals(f1));
95
96         f1 = new FlowArrangement(
97             HorizontalAlignment.RIGHT, VerticalAlignment.TOP, 1.0, 2.0
98         );
99         assertFalse(f1.equals(f2));
100         f2 = new FlowArrangement(
101             HorizontalAlignment.RIGHT, VerticalAlignment.TOP, 1.0, 2.0
102         );
103         assertTrue(f1.equals(f2));
104
105         f1 = new FlowArrangement(
106             HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.0, 2.0
107         );
108         assertFalse(f1.equals(f2));
109         f2 = new FlowArrangement(
110             HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.0, 2.0
111         );
112         assertTrue(f1.equals(f2));
113     
114         f1 = new FlowArrangement(
115             HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.0
116         );
117         assertFalse(f1.equals(f2));
118         f2 = new FlowArrangement(
119             HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.0
120         );
121         assertTrue(f1.equals(f2));
122         
123         f1 = new FlowArrangement(
124             HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.2
125         );
126         assertFalse(f1.equals(f2));
127         f2 = new FlowArrangement(
128             HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.2
129         );
130         assertTrue(f1.equals(f2));
131         
132     }
133
134     /**
135      * Immutable - cloning is not necessary.
136      */

137     public void testCloning() {
138         FlowArrangement f1 = new FlowArrangement();
139         assertFalse(f1 instanceof Cloneable JavaDoc);
140     }
141
142     /**
143      * Serialize an instance, restore it, and check for equality.
144      */

145     public void testSerialization() {
146         FlowArrangement f1 = new FlowArrangement(
147             HorizontalAlignment.LEFT, VerticalAlignment.TOP, 1.0, 2.0
148         );
149         FlowArrangement f2 = null;
150         try {
151             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
152             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
153             out.writeObject(f1);
154             out.close();
155
156             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
157                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
158             );
159             f2 = (FlowArrangement) in.readObject();
160             in.close();
161         }
162         catch (Exception JavaDoc e) {
163             System.out.println(e.toString());
164         }
165         assertEquals(f1, f2);
166     }
167    
168 }
169
Popular Tags