KickJava   Java API By Example, From Geeks To Geeks.

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


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  * SimpleDialRangeTests.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: StandardDialRangeTests.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.Color JavaDoc;
46 import java.awt.GradientPaint JavaDoc;
47 import java.io.ByteArrayInputStream JavaDoc;
48 import java.io.ByteArrayOutputStream JavaDoc;
49 import java.io.ObjectInput JavaDoc;
50 import java.io.ObjectInputStream JavaDoc;
51 import java.io.ObjectOutput JavaDoc;
52 import java.io.ObjectOutputStream JavaDoc;
53
54 import junit.framework.Test;
55 import junit.framework.TestCase;
56 import junit.framework.TestSuite;
57
58 import org.jfree.experimental.chart.plot.dial.StandardDialRange;
59
60 /**
61  * Tests for the {@link StandardDialRange} class.
62  */

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

79     public StandardDialRangeTests(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         StandardDialRange r1 = new StandardDialRange();
88         StandardDialRange r2 = new StandardDialRange();
89         assertTrue(r1.equals(r2));
90         
91         // lowerBound
92
r1.setLowerBound(1.1);
93         assertFalse(r1.equals(r2));
94         r2.setLowerBound(1.1);
95         assertTrue(r1.equals(r2));
96         
97         // upperBound
98
r1.setUpperBound(11.1);
99         assertFalse(r1.equals(r2));
100         r2.setUpperBound(11.1);
101         assertTrue(r1.equals(r2));
102         
103         // increment
104
r1.setIncrement(1.5);
105         assertFalse(r1.equals(r2));
106         r2.setIncrement(1.5);
107         assertTrue(r1.equals(r2));
108         
109         // paint
110
r1.setPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
111                 Color.blue));
112         assertFalse(r1.equals(r2));
113         r2.setPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
114                 Color.blue));
115         assertTrue(r1.equals(r2));
116         
117     }
118     
119     /**
120      * Two objects that are equal are required to return the same hashCode.
121      */

122     public void testHashCode() {
123         StandardDialRange r1 = new StandardDialRange();
124         StandardDialRange r2 = new StandardDialRange();
125         assertTrue(r1.equals(r2));
126         int h1 = r1.hashCode();
127         int h2 = r2.hashCode();
128         assertEquals(h1, h2);
129     }
130
131     /**
132      * Confirm that cloning works.
133      */

134     public void testCloning() {
135         StandardDialRange r1 = new StandardDialRange();
136         StandardDialRange r2 = null;
137         try {
138             r2 = (StandardDialRange) r1.clone();
139         }
140         catch (CloneNotSupportedException JavaDoc e) {
141             e.printStackTrace();
142         }
143         assertTrue(r1 != r2);
144         assertTrue(r1.getClass() == r2.getClass());
145         assertTrue(r1.equals(r2));
146     }
147
148
149     /**
150      * Serialize an instance, restore it, and check for equality.
151      */

152     public void testSerialization() {
153         StandardDialRange r1 = new StandardDialRange();
154         StandardDialRange r2 = null;
155
156         try {
157             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
158             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
159             out.writeObject(r1);
160             out.close();
161
162             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
163                     new ByteArrayInputStream JavaDoc(buffer.toByteArray()));
164             r2 = (StandardDialRange) in.readObject();
165             in.close();
166         }
167         catch (Exception JavaDoc e) {
168             e.printStackTrace();
169         }
170         assertEquals(r1, r2);
171     }
172
173 }
174
Popular Tags