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 * FlowArrangementTests.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: FlowArrangementTests.java,v 1.1 2005/02/04 16:55:15 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.FlowArrangement;
56 import org.jfree.ui.HorizontalAlignment;
57 import org.jfree.ui.VerticalAlignment;
58
59 /**
60 * Tests for the {@link FlowArrangement} class.
61 */
62 public class FlowArrangementTests 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(FlowArrangementTests.class);
71 }
72
73 /**
74 * Constructs a new set of tests.
75 *
76 * @param name the name of the tests.
77 */
78 public FlowArrangementTests(String name) {
79 super(name);
80 }
81
82 /**
83 * Confirm that the equals() method can distinguish all the required fields.
84 */
85 public void testEquals() {
86 FlowArrangement f1 = new FlowArrangement(
87 HorizontalAlignment.LEFT, VerticalAlignment.TOP, 1.0, 2.0
88 );
89 FlowArrangement f2 = new FlowArrangement(
90 HorizontalAlignment.LEFT, VerticalAlignment.TOP, 1.0, 2.0
91 );
92 assertTrue(f1.equals(f2));
93 assertTrue(f2.equals(f1));
94
95 f1 = new FlowArrangement(
96 HorizontalAlignment.RIGHT, VerticalAlignment.TOP, 1.0, 2.0
97 );
98 assertFalse(f1.equals(f2));
99 f2 = new FlowArrangement(
100 HorizontalAlignment.RIGHT, VerticalAlignment.TOP, 1.0, 2.0
101 );
102 assertTrue(f1.equals(f2));
103
104 f1 = new FlowArrangement(
105 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.0, 2.0
106 );
107 assertFalse(f1.equals(f2));
108 f2 = new FlowArrangement(
109 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.0, 2.0
110 );
111 assertTrue(f1.equals(f2));
112
113 f1 = new FlowArrangement(
114 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.0
115 );
116 assertFalse(f1.equals(f2));
117 f2 = new FlowArrangement(
118 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.0
119 );
120 assertTrue(f1.equals(f2));
121
122 f1 = new FlowArrangement(
123 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.2
124 );
125 assertFalse(f1.equals(f2));
126 f2 = new FlowArrangement(
127 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.2
128 );
129 assertTrue(f1.equals(f2));
130
131 }
132
133 /**
134 * Immutable - cloning is not necessary.
135 */
136 public void testCloning() {
137 FlowArrangement f1 = new FlowArrangement();
138 assertFalse(f1 instanceof Cloneable);
139 }
140
141 /**
142 * Serialize an instance, restore it, and check for equality.
143 */
144 public void testSerialization() {
145 FlowArrangement f1 = new FlowArrangement(
146 HorizontalAlignment.LEFT, VerticalAlignment.TOP, 1.0, 2.0
147 );
148 FlowArrangement f2 = null;
149 try {
150 ByteArrayOutputStream buffer = new ByteArrayOutputStream();
151 ObjectOutput out = new ObjectOutputStream(buffer);
152 out.writeObject(f1);
153 out.close();
154
155 ObjectInput in = new ObjectInputStream(
156 new ByteArrayInputStream(buffer.toByteArray())
157 );
158 f2 = (FlowArrangement) in.readObject();
159 in.close();
160 }
161 catch (Exception e) {
162 System.out.println(e.toString());
163 }
164 assertEquals(f1, f2);
165 }
166
167 }