KickJava   Java API By Example, From Geeks To Geeks.

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


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  * DialPlotTests.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: DialPlotTests.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.DialBackground;
59 import org.jfree.experimental.chart.plot.dial.DialCap;
60 import org.jfree.experimental.chart.plot.dial.DialPlot;
61 import org.jfree.experimental.chart.plot.dial.SimpleDialFrame;
62 import org.jfree.experimental.chart.plot.dial.StandardDialScale;
63
64 /**
65  * Tests for the {@link DialPlot} class.
66  */

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

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

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

90     public void testEquals() {
91         DialPlot p1 = new DialPlot();
92         DialPlot p2 = new DialPlot();
93         assertTrue(p1.equals(p2));
94         
95         // background
96
p1.setBackground(new DialBackground(Color.green));
97         assertFalse(p1.equals(p2));
98         p2.setBackground(new DialBackground(Color.green));
99         assertTrue(p1.equals(p2));
100         
101         p1.setBackground(null);
102         assertFalse(p1.equals(p2));
103         p2.setBackground(null);
104         assertTrue(p1.equals(p2));
105         
106         // dial cap
107
DialCap cap1 = new DialCap();
108         cap1.setFillPaint(Color.red);
109         p1.setCap(cap1);
110         assertFalse(p1.equals(p2));
111         DialCap cap2 = new DialCap();
112         cap2.setFillPaint(Color.red);
113         p2.setCap(cap2);
114         assertTrue(p1.equals(p2));
115         
116         p1.setCap(null);
117         assertFalse(p1.equals(p2));
118         p2.setCap(null);
119         assertTrue(p1.equals(p2));
120         
121         // frame
122
SimpleDialFrame f1 = new SimpleDialFrame();
123         f1.setBackgroundPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red, 3.0f,
124                 4.0f, Color.white));
125         p1.setDialFrame(f1);
126         assertFalse(p1.equals(p2));
127         SimpleDialFrame f2 = new SimpleDialFrame();
128         f2.setBackgroundPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red, 3.0f,
129                 4.0f, Color.white));
130         p2.setDialFrame(f2);
131         assertTrue(p1.equals(p2));
132         
133         // view
134
p1.setView(0.2, 0.0, 0.8, 1.0);
135         assertFalse(p1.equals(p2));
136         p2.setView(0.2, 0.0, 0.8, 1.0);
137         assertTrue(p1.equals(p2));
138         
139         // layer
140
p1.addLayer(new StandardDialScale());
141         assertFalse(p1.equals(p2));
142         p2.addLayer(new StandardDialScale());
143         assertTrue(p1.equals(p2));
144     }
145
146     /**
147      * Two objects that are equal are required to return the same hashCode.
148      */

149     public void testHashCode() {
150         DialPlot p1 = new DialPlot();
151         DialPlot p2 = new DialPlot();
152         assertTrue(p1.equals(p2));
153         int h1 = p1.hashCode();
154         int h2 = p2.hashCode();
155         assertEquals(h1, h2);
156     }
157
158     /**
159      * Confirm that cloning works.
160      */

161     public void testCloning() {
162         DialPlot p1 = new DialPlot();
163         DialPlot p2 = null;
164         try {
165             p2 = (DialPlot) p1.clone();
166         }
167         catch (CloneNotSupportedException JavaDoc e) {
168             e.printStackTrace();
169         }
170         assertTrue(p1 != p2);
171         assertTrue(p1.getClass() == p2.getClass());
172         assertTrue(p1.equals(p2));
173     }
174
175
176     /**
177      * Serialize an instance, restore it, and check for equality.
178      */

179     public void testSerialization() {
180         DialPlot p1 = new DialPlot();
181         DialPlot p2 = null;
182
183         try {
184             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
185             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
186             out.writeObject(p1);
187             out.close();
188
189             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
190                     new ByteArrayInputStream JavaDoc(buffer.toByteArray()));
191             p2 = (DialPlot) in.readObject();
192             in.close();
193         }
194         catch (Exception JavaDoc e) {
195             e.printStackTrace();
196         }
197         assertEquals(p1, p2);
198     }
199
200 }
201
Popular Tags