KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > plot > junit > PiePlotTests


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  * PiePlotTests.java
28  * -----------------
29  * (C) Copyright 2003, 2004, by Object Refinery Limited and Contributors.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: PiePlotTests.java,v 1.7 2005/05/10 19:26:17 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 18-Mar-2003 : Version 1 (DG);
39  * 10-May-2005 : Strengthened equals() test (DG);
40  *
41  */

42
43 package org.jfree.chart.plot.junit;
44
45 import java.awt.BasicStroke JavaDoc;
46 import java.awt.Color JavaDoc;
47 import java.awt.Font JavaDoc;
48 import java.awt.Stroke JavaDoc;
49 import java.awt.geom.Rectangle2D JavaDoc;
50 import java.io.ByteArrayInputStream JavaDoc;
51 import java.io.ByteArrayOutputStream JavaDoc;
52 import java.io.ObjectInput JavaDoc;
53 import java.io.ObjectInputStream JavaDoc;
54 import java.io.ObjectOutput JavaDoc;
55 import java.io.ObjectOutputStream JavaDoc;
56
57 import junit.framework.Test;
58 import junit.framework.TestCase;
59 import junit.framework.TestSuite;
60
61 import org.jfree.chart.labels.StandardPieItemLabelGenerator;
62 import org.jfree.chart.plot.PiePlot;
63 import org.jfree.chart.urls.StandardPieURLGenerator;
64 import org.jfree.util.Rotation;
65
66 /**
67  * Tests for the {@link PiePlot} class.
68  */

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

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

85     public PiePlotTests(String JavaDoc name) {
86         super(name);
87     }
88
89     /**
90      * Test the equals() method.
91      */

92     public void testEquals() {
93         
94         PiePlot plot1 = new PiePlot();
95         PiePlot plot2 = new PiePlot();
96         assertTrue(plot1.equals(plot2));
97         assertTrue(plot2.equals(plot1));
98                 
99         // pieIndex...
100
plot1.setPieIndex(99);
101         assertFalse(plot1.equals(plot2));
102         plot2.setPieIndex(99);
103         assertTrue(plot1.equals(plot2));
104         
105         // interiorGap...
106
plot1.setInteriorGap(0.15);
107         assertFalse(plot1.equals(plot2));
108         plot2.setInteriorGap(0.15);
109         assertTrue(plot1.equals(plot2));
110
111         // circular
112
plot1.setCircular(!plot1.isCircular());
113         assertFalse(plot1.equals(plot2));
114         plot2.setCircular(false);
115         assertTrue(plot1.equals(plot2));
116         
117         // startAngle
118
plot1.setStartAngle(Math.PI);
119         assertFalse(plot1.equals(plot2));
120         plot2.setStartAngle(Math.PI);
121         assertTrue(plot1.equals(plot2));
122         
123         // direction
124
plot1.setDirection(Rotation.ANTICLOCKWISE);
125         assertFalse(plot1.equals(plot2));
126         plot2.setDirection(Rotation.ANTICLOCKWISE);
127         assertTrue(plot1.equals(plot2));
128         
129         // ignoreZeroValues
130
plot1.setIgnoreZeroValues(true);
131         assertFalse(plot1.equals(plot2));
132         plot2.setIgnoreZeroValues(true);
133         assertTrue(plot1.equals(plot2));
134         
135         // ignoreNullValues
136
plot1.setIgnoreNullValues(true);
137         assertFalse(plot1.equals(plot2));
138         plot2.setIgnoreNullValues(true);
139         assertTrue(plot1.equals(plot2));
140         
141         // sectionPaint
142
plot1.setSectionPaint(Color.red);
143         assertFalse(plot1.equals(plot2));
144         plot2.setSectionPaint(Color.red);
145         assertTrue(plot1.equals(plot2));
146         
147         // sectionPaintList
148
plot1.setSectionPaint(2, Color.red);
149         assertFalse(plot1.equals(plot2));
150         plot2.setSectionPaint(2, Color.red);
151         assertTrue(plot1.equals(plot2));
152         
153         // baseSectionPaint
154
plot1.setBaseSectionPaint(Color.red);
155         assertFalse(plot1.equals(plot2));
156         plot2.setBaseSectionPaint(Color.red);
157         assertTrue(plot1.equals(plot2));
158         
159         // sectionOutlinePaint
160
plot1.setSectionOutlinePaint(Color.red);
161         assertFalse(plot1.equals(plot2));
162         plot2.setSectionOutlinePaint(Color.red);
163         assertTrue(plot1.equals(plot2));
164         
165         // sectionOutlinePaintList
166
plot1.setSectionOutlinePaint(2, Color.red);
167         assertFalse(plot1.equals(plot2));
168         plot2.setSectionOutlinePaint(2, Color.red);
169         assertTrue(plot1.equals(plot2));
170         
171         // baseSectionOutlinePaint
172
plot1.setBaseSectionOutlinePaint(Color.red);
173         assertFalse(plot1.equals(plot2));
174         plot2.setBaseSectionOutlinePaint(Color.red);
175         assertTrue(plot1.equals(plot2));
176         
177         // sectionOutlineStroke
178
plot1.setSectionOutlineStroke(new BasicStroke JavaDoc(1.0f));
179         assertFalse(plot1.equals(plot2));
180         plot2.setSectionOutlineStroke(new BasicStroke JavaDoc(1.0f));
181         assertTrue(plot1.equals(plot2));
182         
183         // sectionOutlineStrokeList
184
plot1.setSectionOutlineStroke(2, new BasicStroke JavaDoc(1.0f));
185         assertFalse(plot1.equals(plot2));
186         plot2.setSectionOutlineStroke(2, new BasicStroke JavaDoc(1.0f));
187         assertTrue(plot1.equals(plot2));
188         
189         // baseSectionOutlineStroke
190
plot1.setBaseSectionOutlineStroke(new BasicStroke JavaDoc(1.0f));
191         assertFalse(plot1.equals(plot2));
192         plot2.setBaseSectionOutlineStroke(new BasicStroke JavaDoc(1.0f));
193         assertTrue(plot1.equals(plot2));
194         
195         // shadowPaint
196
plot1.setShadowPaint(Color.red);
197         assertFalse(plot1.equals(plot2));
198         plot2.setShadowPaint(Color.red);
199         assertTrue(plot1.equals(plot2));
200
201         // shadowXOffset
202
plot1.setShadowXOffset(4.4);
203         assertFalse(plot1.equals(plot2));
204         plot2.setShadowXOffset(4.4);
205         assertTrue(plot1.equals(plot2));
206
207         // shadowYOffset
208
plot1.setShadowYOffset(4.4);
209         assertFalse(plot1.equals(plot2));
210         plot2.setShadowYOffset(4.4);
211         assertTrue(plot1.equals(plot2));
212
213         // labelFont
214
plot1.setLabelFont(new Font JavaDoc("Serif", Font.PLAIN, 18));
215         assertFalse(plot1.equals(plot2));
216         plot2.setLabelFont(new Font JavaDoc("Serif", Font.PLAIN, 18));
217         assertTrue(plot1.equals(plot2));
218        
219         // labelPaint
220
plot1.setLabelPaint(Color.red);
221         assertFalse(plot1.equals(plot2));
222         plot2.setLabelPaint(Color.red);
223         assertTrue(plot1.equals(plot2));
224        
225         // labelBackgroundPaint
226
plot1.setLabelBackgroundPaint(Color.red);
227         assertFalse(plot1.equals(plot2));
228         plot2.setLabelBackgroundPaint(Color.red);
229         assertTrue(plot1.equals(plot2));
230         
231         // labelOutlinePaint
232
plot1.setLabelOutlinePaint(Color.red);
233         assertFalse(plot1.equals(plot2));
234         plot2.setLabelOutlinePaint(Color.red);
235         assertTrue(plot1.equals(plot2));
236         
237         // labelOutlineStroke
238
Stroke JavaDoc s = new BasicStroke JavaDoc(1.1f);
239         plot1.setLabelOutlineStroke(s);
240         assertFalse(plot1.equals(plot2));
241         plot2.setLabelOutlineStroke(s);
242         assertTrue(plot1.equals(plot2));
243         
244         // labelShadowPaint
245
plot1.setLabelShadowPaint(Color.red);
246         assertFalse(plot1.equals(plot2));
247         plot2.setLabelShadowPaint(Color.red);
248         assertTrue(plot1.equals(plot2));
249         
250         // explodePercentages
251
plot1.setExplodePercent(3, 0.33);
252         assertFalse(plot1.equals(plot2));
253         plot2.setExplodePercent(3, 0.33);
254         assertTrue(plot1.equals(plot2));
255         
256         // labelGenerator
257
plot1.setLabelGenerator(new StandardPieItemLabelGenerator("{2}{1}{0}"));
258         assertFalse(plot1.equals(plot2));
259         plot2.setLabelGenerator(new StandardPieItemLabelGenerator("{2}{1}{0}"));
260         assertTrue(plot1.equals(plot2));
261        
262         // labelFont
263
Font JavaDoc f = new Font JavaDoc("SansSerif", Font.PLAIN, 20);
264         plot1.setLabelFont(f);
265         assertFalse(plot1.equals(plot2));
266         plot2.setLabelFont(f);
267         assertTrue(plot1.equals(plot2));
268         
269         // labelPaint
270
plot1.setLabelPaint(Color.blue);
271         assertFalse(plot1.equals(plot2));
272         plot2.setLabelPaint(Color.blue);
273         assertTrue(plot1.equals(plot2));
274         
275         // maximumLabelWidth
276
plot1.setMaximumLabelWidth(0.33);
277         assertFalse(plot1.equals(plot2));
278         plot2.setMaximumLabelWidth(0.33);
279         assertTrue(plot1.equals(plot2));
280         
281         // labelGap
282
plot1.setLabelGap(0.11);
283         assertFalse(plot1.equals(plot2));
284         plot2.setLabelGap(0.11);
285         assertTrue(plot1.equals(plot2));
286         
287         // links visible
288
plot1.setLabelLinksVisible(false);
289         assertFalse(plot1.equals(plot2));
290         plot2.setLabelLinksVisible(false);
291         assertTrue(plot1.equals(plot2));
292         
293         // linkMargin
294
plot1.setLabelLinkMargin(0.11);
295         assertFalse(plot1.equals(plot2));
296         plot2.setLabelLinkMargin(0.11);
297         assertTrue(plot1.equals(plot2));
298
299         // labelLinkPaint
300
plot1.setLabelLinkPaint(Color.red);
301         assertFalse(plot1.equals(plot2));
302         plot2.setLabelLinkPaint(Color.red);
303         assertTrue(plot1.equals(plot2));
304        
305         // labelLinkStroke
306
plot1.setLabelLinkStroke(new BasicStroke JavaDoc(1.0f));
307         assertFalse(plot1.equals(plot2));
308         plot2.setLabelLinkStroke(new BasicStroke JavaDoc(1.0f));
309         assertTrue(plot1.equals(plot2));
310        
311         // toolTipGenerator
312
plot1.setToolTipGenerator(
313             new StandardPieItemLabelGenerator("{2}{1}{0}")
314         );
315         assertFalse(plot1.equals(plot2));
316         plot2.setToolTipGenerator(
317             new StandardPieItemLabelGenerator("{2}{1}{0}")
318         );
319         assertTrue(plot1.equals(plot2));
320         
321         // urlGenerator
322
plot1.setURLGenerator(new StandardPieURLGenerator("xx"));
323         assertFalse(plot1.equals(plot2));
324         plot2.setURLGenerator(new StandardPieURLGenerator("xx"));
325         assertTrue(plot1.equals(plot2));
326         
327         // minimumArcAngleToDraw
328
plot1.setMinimumArcAngleToDraw(1.0);
329         assertFalse(plot1.equals(plot2));
330         plot2.setMinimumArcAngleToDraw(1.0);
331         assertTrue(plot1.equals(plot2));
332         
333         // legendItemShape
334
plot1.setLegendItemShape(new Rectangle2D.Double JavaDoc(1.0, 2.0, 3.0, 4.0));
335         assertFalse(plot1.equals(plot2));
336         plot2.setLegendItemShape(new Rectangle2D.Double JavaDoc(1.0, 2.0, 3.0, 4.0));
337         assertTrue(plot1.equals(plot2));
338         
339     }
340
341     /**
342      * Some basic checks for the clone() method.
343      */

344     public void testCloning() {
345         PiePlot p1 = new PiePlot();
346         PiePlot p2 = null;
347         try {
348             p2 = (PiePlot) p1.clone();
349         }
350         catch (CloneNotSupportedException JavaDoc e) {
351             e.printStackTrace();
352             System.err.println("Failed to clone.");
353         }
354         assertTrue(p1 != p2);
355         assertTrue(p1.getClass() == p2.getClass());
356         assertTrue(p1.equals(p2));
357     }
358
359     /**
360      * Serialize an instance, restore it, and check for equality.
361      */

362     public void testSerialization() {
363
364         PiePlot p1 = new PiePlot(null);
365         PiePlot p2 = null;
366
367         try {
368             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
369             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
370             out.writeObject(p1);
371             out.close();
372
373             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
374                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
375             );
376             p2 = (PiePlot) in.readObject();
377             in.close();
378         }
379         catch (Exception JavaDoc e) {
380             e.printStackTrace();
381         }
382         assertEquals(p1, p2);
383
384     }
385
386 }
387
Popular Tags