KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > experimental > chart > plot > dial > junit > DialValueIndicatorTests


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2006, 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  * DialValueIndicatorTests.java
29  * ----------------------------
30  * (C) Copyright 2006, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: DialValueIndicatorTests.java,v 1.1.2.4 2006/11/07 16:11:12 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 03-Nov-2006 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.experimental.chart.plot.dial.junit;
44
45 import java.awt.BasicStroke JavaDoc;
46 import java.awt.Color JavaDoc;
47 import java.awt.Font JavaDoc;
48 import java.awt.GradientPaint JavaDoc;
49 import java.io.ByteArrayInputStream JavaDoc;
50 import java.io.ByteArrayOutputStream JavaDoc;
51 import java.io.ObjectInput JavaDoc;
52 import java.io.ObjectInputStream JavaDoc;
53 import java.io.ObjectOutput JavaDoc;
54 import java.io.ObjectOutputStream JavaDoc;
55
56 import junit.framework.Test;
57 import junit.framework.TestCase;
58 import junit.framework.TestSuite;
59
60 import org.jfree.experimental.chart.plot.dial.DialValueIndicator;
61 import org.jfree.ui.RectangleAnchor;
62 import org.jfree.ui.RectangleInsets;
63 import org.jfree.ui.TextAnchor;
64
65 /**
66  * Tests for the {@link DialValueIndicator} class.
67  */

68 public class DialValueIndicatorTests extends TestCase {
69
70     /**
71      * Returns the tests as a test suite.
72      *
73      * @return The test suite.
74      */

75     public static Test suite() {
76         return new TestSuite(DialValueIndicatorTests.class);
77     }
78
79     /**
80      * Constructs a new set of tests.
81      *
82      * @param name the name of the tests.
83      */

84     public DialValueIndicatorTests(String JavaDoc name) {
85         super(name);
86     }
87
88     /**
89      * Confirm that the equals method can distinguish all the required fields.
90      */

91     public void testEquals() {
92         DialValueIndicator i1 = new DialValueIndicator(0, "Label");
93         DialValueIndicator i2 = new DialValueIndicator(0, "Label");
94         assertTrue(i1.equals(i2));
95         
96         // dataset index
97
i1.setDatasetIndex(99);
98         assertFalse(i1.equals(i2));
99         i2.setDatasetIndex(99);
100         assertTrue(i1.equals(i2));
101         
102         // angle
103
i1.setAngle(43);
104         assertFalse(i1.equals(i2));
105         i2.setAngle(43);
106         assertTrue(i1.equals(i2));
107         
108         // radius
109
i1.setRadius(0.77);
110         assertFalse(i1.equals(i2));
111         i2.setRadius(0.77);
112         assertTrue(i1.equals(i2));
113         
114         // frameAnchor
115
i1.setFrameAnchor(RectangleAnchor.TOP_LEFT);
116         assertFalse(i1.equals(i2));
117         i2.setFrameAnchor(RectangleAnchor.TOP_LEFT);
118         assertTrue(i1.equals(i2));
119         
120         // templateValue
121
i1.setTemplateValue(new Double JavaDoc(1.23));
122         assertFalse(i1.equals(i2));
123         i2.setTemplateValue(new Double JavaDoc(1.23));
124         assertTrue(i1.equals(i2));
125         
126         // font
127
i1.setFont(new Font JavaDoc("Dialog", Font.PLAIN, 7));
128         assertFalse(i1.equals(i2));
129         i2.setFont(new Font JavaDoc("Dialog", Font.PLAIN, 7));
130         assertTrue(i1.equals(i2));
131         
132         // paint
133
i1.setPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
134                 Color.green));
135         assertFalse(i1.equals(i2));
136         i2.setPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
137                 Color.green));
138         assertTrue(i1.equals(i2));
139
140         // backgroundPaint
141
i1.setBackgroundPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red, 3.0f,
142                 4.0f, Color.green));
143         assertFalse(i1.equals(i2));
144         i2.setBackgroundPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red, 3.0f,
145                 4.0f, Color.green));
146         assertTrue(i1.equals(i2));
147         
148         // outlineStroke
149
i1.setOutlineStroke(new BasicStroke JavaDoc(1.1f));
150         assertFalse(i1.equals(i2));
151         i2.setOutlineStroke(new BasicStroke JavaDoc(1.1f));
152         assertTrue(i1.equals(i2));
153         
154         // outlinePaint
155
i1.setOutlinePaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
156                 Color.green));
157         assertFalse(i1.equals(i2));
158         i2.setOutlinePaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
159                 Color.green));
160         assertTrue(i1.equals(i2));
161
162         // insets
163
i1.setInsets(new RectangleInsets(1, 2, 3, 4));
164         assertFalse(i1.equals(i2));
165         i2.setInsets(new RectangleInsets(1, 2, 3, 4));
166         assertTrue(i1.equals(i2));
167         
168         // valueAnchor
169
i1.setValueAnchor(RectangleAnchor.BOTTOM_LEFT);
170         assertFalse(i1.equals(i2));
171         i2.setValueAnchor(RectangleAnchor.BOTTOM_LEFT);
172         assertTrue(i1.equals(i2));
173         
174         // textAnchor
175
i1.setTextAnchor(TextAnchor.TOP_LEFT);
176         assertFalse(i1.equals(i2));
177         i2.setTextAnchor(TextAnchor.TOP_LEFT);
178         assertTrue(i1.equals(i2));
179     }
180
181     /**
182      * Two objects that are equal are required to return the same hashCode.
183      */

184     public void testHashCode() {
185         DialValueIndicator i1 = new DialValueIndicator(0, "Label");
186         DialValueIndicator i2 = new DialValueIndicator(0, "Label");
187         assertTrue(i1.equals(i2));
188         int h1 = i1.hashCode();
189         int h2 = i2.hashCode();
190         assertEquals(h1, h2);
191     }
192
193     /**
194      * Confirm that cloning works.
195      */

196     public void testCloning() {
197         // test a default instance
198
DialValueIndicator i1 = new DialValueIndicator(0, "Label");
199         DialValueIndicator i2 = null;
200         try {
201             i2 = (DialValueIndicator) i1.clone();
202         }
203         catch (CloneNotSupportedException JavaDoc e) {
204             e.printStackTrace();
205         }
206         assertTrue(i1 != i2);
207         assertTrue(i1.getClass() == i2.getClass());
208         assertTrue(i1.equals(i2));
209         
210         // test a customised instance
211
}
212
213
214     /**
215      * Serialize an instance, restore it, and check for equality.
216      */

217     public void testSerialization() {
218         // test a default instance
219
DialValueIndicator i1 = new DialValueIndicator(0, "Label");
220         DialValueIndicator i2 = null;
221
222         try {
223             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
224             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
225             out.writeObject(i1);
226             out.close();
227
228             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
229                     new ByteArrayInputStream JavaDoc(buffer.toByteArray()));
230             i2 = (DialValueIndicator) in.readObject();
231             in.close();
232         }
233         catch (Exception JavaDoc e) {
234             e.printStackTrace();
235         }
236         assertEquals(i1, i2);
237         
238         // test a custom instance
239
}
240
241 }
242
Popular Tags