KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ColumnArrangementTests.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: ColumnArrangementTests.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.ColumnArrangement;
57 import org.jfree.chart.block.FlowArrangement;
58 import org.jfree.ui.HorizontalAlignment;
59 import org.jfree.ui.VerticalAlignment;
60
61 /**
62  * Tests for the {@link ColumnArrangement} class.
63  */

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

80     public ColumnArrangementTests(String JavaDoc name) {
81         super(name);
82     }
83     
84     /**
85      * Confirm that the equals() method can distinguish all the required fields.
86      */

87     public void testEquals() {
88         ColumnArrangement c1 = new ColumnArrangement(
89             HorizontalAlignment.LEFT, VerticalAlignment.TOP, 1.0, 2.0
90         );
91         ColumnArrangement c2 = new ColumnArrangement(
92             HorizontalAlignment.LEFT, VerticalAlignment.TOP, 1.0, 2.0
93         );
94         assertTrue(c1.equals(c2));
95         assertTrue(c2.equals(c1));
96
97         c1 = new ColumnArrangement(
98             HorizontalAlignment.RIGHT, VerticalAlignment.TOP, 1.0, 2.0
99         );
100         assertFalse(c1.equals(c2));
101         c2 = new ColumnArrangement(
102             HorizontalAlignment.RIGHT, VerticalAlignment.TOP, 1.0, 2.0
103         );
104         assertTrue(c1.equals(c2));
105
106         c1 = new ColumnArrangement(
107             HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.0, 2.0
108         );
109         assertFalse(c1.equals(c2));
110         c2 = new ColumnArrangement(
111             HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.0, 2.0
112         );
113         assertTrue(c1.equals(c2));
114     
115         c1 = new ColumnArrangement(
116             HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.0
117         );
118         assertFalse(c1.equals(c2));
119         c2 = new ColumnArrangement(
120             HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.0
121         );
122         assertTrue(c1.equals(c2));
123         
124         c1 = new ColumnArrangement(
125             HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.2
126         );
127         assertFalse(c1.equals(c2));
128         c2 = new ColumnArrangement(
129             HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.2
130         );
131         assertTrue(c1.equals(c2));
132         
133     }
134
135     /**
136      * Immutable - cloning is not necessary.
137      */

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

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