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 * ColumnArrangementTests.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: ColumnArrangementTests.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.ColumnArrangement;
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 ColumnArrangement} class.
62 */
63 public class ColumnArrangementTests 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(ColumnArrangementTests.class);
72 }
73
74 /**
75 * Constructs a new set of tests.
76 *
77 * @param name the name of the tests.
78 */
79 public ColumnArrangementTests(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 ColumnArrangement c1 = new ColumnArrangement(
88 HorizontalAlignment.LEFT, VerticalAlignment.TOP, 1.0, 2.0
89 );
90 ColumnArrangement c2 = new ColumnArrangement(
91 HorizontalAlignment.LEFT, VerticalAlignment.TOP, 1.0, 2.0
92 );
93 assertTrue(c1.equals(c2));
94 assertTrue(c2.equals(c1));
95
96 c1 = new ColumnArrangement(
97 HorizontalAlignment.RIGHT, VerticalAlignment.TOP, 1.0, 2.0
98 );
99 assertFalse(c1.equals(c2));
100 c2 = new ColumnArrangement(
101 HorizontalAlignment.RIGHT, VerticalAlignment.TOP, 1.0, 2.0
102 );
103 assertTrue(c1.equals(c2));
104
105 c1 = new ColumnArrangement(
106 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.0, 2.0
107 );
108 assertFalse(c1.equals(c2));
109 c2 = new ColumnArrangement(
110 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.0, 2.0
111 );
112 assertTrue(c1.equals(c2));
113
114 c1 = new ColumnArrangement(
115 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.0
116 );
117 assertFalse(c1.equals(c2));
118 c2 = new ColumnArrangement(
119 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.0
120 );
121 assertTrue(c1.equals(c2));
122
123 c1 = new ColumnArrangement(
124 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.2
125 );
126 assertFalse(c1.equals(c2));
127 c2 = new ColumnArrangement(
128 HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, 1.1, 2.2
129 );
130 assertTrue(c1.equals(c2));
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);
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 buffer = new ByteArrayOutputStream();
152 ObjectOutput out = new ObjectOutputStream(buffer);
153 out.writeObject(f1);
154 out.close();
155
156 ObjectInput in = new ObjectInputStream(
157 new ByteArrayInputStream(buffer.toByteArray())
158 );
159 f2 = (FlowArrangement) in.readObject();
160 in.close();
161 }
162 catch (Exception e) {
163 System.out.println(e.toString());
164 }
165 assertEquals(f1, f2);
166 }
167
168 }