KickJava   Java API By Example, From Geeks To Geeks.

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


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  * SimpleDialScaleTests.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: StandardDialScaleTests.java,v 1.1.2.2 2006/11/06 16:31:01 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 import junit.framework.Test;
56 import junit.framework.TestCase;
57 import junit.framework.TestSuite;
58 import org.jfree.experimental.chart.plot.dial.StandardDialScale;
59
60 /**
61  * Tests for the {@link StandardDialScale} class.
62  */

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

79     public StandardDialScaleTests(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         StandardDialScale s1 = new StandardDialScale();
88         StandardDialScale s2 = new StandardDialScale();
89         assertTrue(s1.equals(s2));
90         
91         // lowerBound
92
s1 = new StandardDialScale(10.0, 100.0, 0.0, 270.0);
93         assertFalse(s1.equals(s2));
94         s2 = new StandardDialScale(10.0, 100.0, 0.0, 270.0);
95         assertTrue(s1.equals(s2));
96         
97         // upperBound
98
s1 = new StandardDialScale(10.0, 200.0, 0.0, 270.0);
99         assertFalse(s1.equals(s2));
100         s2 = new StandardDialScale(10.0, 200.0, 0.0, 270.0);
101         assertTrue(s1.equals(s2));
102         
103         // startAngle
104
s1 = new StandardDialScale(10.0, 200.0, 20.0, 270.0);
105         assertFalse(s1.equals(s2));
106         s2 = new StandardDialScale(10.0, 200.0, 20.0, 270.0);
107         assertTrue(s1.equals(s2));
108
109         // extent
110
s1 = new StandardDialScale(10.0, 200.0, 20.0, 99.0);
111         assertFalse(s1.equals(s2));
112         s2 = new StandardDialScale(10.0, 200.0, 20.0, 99.0);
113         assertTrue(s1.equals(s2));
114     
115         // tickRadius
116
s1.setTickRadius(0.99);
117         assertFalse(s1.equals(s2));
118         s2.setTickRadius(0.99);
119         assertTrue(s1.equals(s2));
120         
121         // majorTickIncrement
122
s1.setMajorTickIncrement(11.1);
123         assertFalse(s1.equals(s2));
124         s2.setMajorTickIncrement(11.1);
125         assertTrue(s1.equals(s2));
126         
127         // majorTickLength
128
s1.setMajorTickLength(0.09);
129         assertFalse(s1.equals(s2));
130         s2.setMajorTickLength(0.09);
131         assertTrue(s1.equals(s2));
132
133         // majorTickPaint
134
s1.setMajorTickPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red,
135                 3.0f, 4.0f, Color.yellow));
136         assertFalse(s1.equals(s2));
137         s2.setMajorTickPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red,
138                 3.0f, 4.0f, Color.yellow));
139         assertTrue(s1.equals(s2));
140         
141         // majorTickStroke
142
s1.setMajorTickStroke(new BasicStroke JavaDoc(1.1f));
143         assertFalse(s1.equals(s2));
144         s2.setMajorTickStroke(new BasicStroke JavaDoc(1.1f));
145         assertTrue(s1.equals(s2));
146         
147         // minorTickCount
148
s1.setMinorTickCount(7);
149         assertFalse(s1.equals(s2));
150         s2.setMinorTickCount(7);
151         assertTrue(s1.equals(s2));
152         
153         // minorTickLength
154
s1.setMinorTickLength(0.09);
155         assertFalse(s1.equals(s2));
156         s2.setMinorTickLength(0.09);
157         assertTrue(s1.equals(s2));
158         
159         // tickLabelOffset
160
s1.setTickLabelOffset(0.11);
161         assertFalse(s1.equals(s2));
162         s2.setTickLabelOffset(0.11);
163         assertTrue(s1.equals(s2));
164         
165         // tickLabelFont
166
s1.setTickLabelFont(new Font JavaDoc("Dialog", Font.PLAIN, 15));
167         assertFalse(s1.equals(s2));
168         s2.setTickLabelFont(new Font JavaDoc("Dialog", Font.PLAIN, 15));
169         assertTrue(s1.equals(s2));
170         
171         // tickLabelPaint
172
s1.setTickLabelPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.white,
173                 3.0f, 4.0f, Color.green));
174         assertFalse(s1.equals(s2));
175         s2.setTickLabelPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.white,
176                 3.0f, 4.0f, Color.green));
177         assertTrue(s1.equals(s2));
178         
179     }
180
181     /**
182      * Two objects that are equal are required to return the same hashCode.
183      */

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

196     public void testCloning() {
197         // try a default instance
198
StandardDialScale s1 = new StandardDialScale();
199         StandardDialScale s2 = null;
200         try {
201             s2 = (StandardDialScale) s1.clone();
202         }
203         catch (CloneNotSupportedException JavaDoc e) {
204             e.printStackTrace();
205         }
206         assertTrue(s1 != s2);
207         assertTrue(s1.getClass() == s2.getClass());
208         assertTrue(s1.equals(s2));
209         
210         // try a customised instance
211
s1 = new StandardDialScale();
212         s1.setExtent(123.4);
213         s1.setMajorTickPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red, 3.0f,
214                 4.0f, Color.white));
215         s1.setMajorTickStroke(new BasicStroke JavaDoc(2.0f));
216         s2 = null;
217         try {
218             s2 = (StandardDialScale) s1.clone();
219         }
220         catch (CloneNotSupportedException JavaDoc e) {
221             e.printStackTrace();
222         }
223         assertTrue(s1 != s2);
224         assertTrue(s1.getClass() == s2.getClass());
225         assertTrue(s1.equals(s2));
226     }
227
228
229     /**
230      * Serialize an instance, restore it, and check for equality.
231      */

232     public void testSerialization() {
233         // try a default instance
234
StandardDialScale s1 = new StandardDialScale();
235         StandardDialScale s2 = null;
236
237         try {
238             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
239             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
240             out.writeObject(s1);
241             out.close();
242
243             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
244                     new ByteArrayInputStream JavaDoc(buffer.toByteArray()));
245             s2 = (StandardDialScale) in.readObject();
246             in.close();
247         }
248         catch (Exception JavaDoc e) {
249             e.printStackTrace();
250         }
251         assertEquals(s1, s2);
252         
253         // try a customised instance
254
s1 = new StandardDialScale();
255         s1.setExtent(123.4);
256         s1.setMajorTickPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red, 3.0f,
257                 4.0f, Color.white));
258         s1.setMajorTickStroke(new BasicStroke JavaDoc(2.0f));
259         s2 = null;
260
261         try {
262             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
263             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
264             out.writeObject(s1);
265             out.close();
266
267             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
268                     new ByteArrayInputStream JavaDoc(buffer.toByteArray()));
269             s2 = (StandardDialScale) in.readObject();
270             in.close();
271         }
272         catch (Exception JavaDoc e) {
273             e.printStackTrace();
274         }
275         assertEquals(s1, s2);
276     }
277
278 }
279
Popular Tags