KickJava   Java API By Example, From Geeks To Geeks.

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


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
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  * PolarPlotTests.java
29  * -------------------
30  * (C) Copyright 2005, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: PolarPlotTests.java,v 1.1.2.1 2006/10/03 15:41:28 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 23-Feb-2005 : Version 1 (DG);
40  * 08-Jun-2005 : Extended testEquals() (DG);
41  *
42  */

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

68 public class PolarPlotTests 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(PolarPlotTests.class);
77     }
78
79     /**
80      * Constructs a new set of tests.
81      *
82      * @param name the name of the tests.
83      */

84     public PolarPlotTests(String JavaDoc name) {
85         super(name);
86     }
87
88     /**
89      * Some checks for the equals() method.
90      */

91     public void testEquals() {
92         PolarPlot plot1 = new PolarPlot();
93         PolarPlot plot2 = new PolarPlot();
94         assertTrue(plot1.equals(plot2));
95         assertTrue(plot2.equals(plot1));
96         
97         plot1.setAngleGridlinePaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red,
98                 3.0f, 4.0f, Color.blue));
99         assertFalse(plot1.equals(plot2));
100         plot2.setAngleGridlinePaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red,
101                 3.0f, 4.0f, Color.blue));
102         assertTrue(plot1.equals(plot2));
103         
104         Stroke JavaDoc s = new BasicStroke JavaDoc(1.23f);
105         plot1.setAngleGridlineStroke(s);
106         assertFalse(plot1.equals(plot2));
107         plot2.setAngleGridlineStroke(s);
108         assertTrue(plot1.equals(plot2));
109         
110         plot1.setAngleGridlinesVisible(false);
111         assertFalse(plot1.equals(plot2));
112         plot2.setAngleGridlinesVisible(false);
113         assertTrue(plot1.equals(plot2));
114         
115         plot1.setAngleLabelFont(new Font JavaDoc("Serif", Font.PLAIN, 9));
116         assertFalse(plot1.equals(plot2));
117         plot2.setAngleLabelFont(new Font JavaDoc("Serif", Font.PLAIN, 9));
118         assertTrue(plot1.equals(plot2));
119         
120         plot1.setAngleLabelPaint(new GradientPaint JavaDoc(9.0f, 8.0f, Color.blue,
121                 7.0f, 6.0f, Color.red));
122         assertFalse(plot1.equals(plot2));
123         plot2.setAngleLabelPaint(new GradientPaint JavaDoc(9.0f, 8.0f, Color.blue,
124                 7.0f, 6.0f, Color.red));
125         assertTrue(plot1.equals(plot2));
126         
127         plot1.setAngleLabelsVisible(false);
128         assertFalse(plot1.equals(plot2));
129         plot2.setAngleLabelsVisible(false);
130         assertTrue(plot1.equals(plot2));
131         
132         plot1.setAxis(new NumberAxis("Test"));
133         assertFalse(plot1.equals(plot2));
134         plot2.setAxis(new NumberAxis("Test"));
135         assertTrue(plot1.equals(plot2));
136         
137         plot1.setRadiusGridlinePaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.white,
138                 3.0f, 4.0f, Color.black));
139         assertFalse(plot1.equals(plot2));
140         plot2.setRadiusGridlinePaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.white,
141                 3.0f, 4.0f, Color.black));
142         assertTrue(plot1.equals(plot2));
143         
144         plot1.setRadiusGridlineStroke(s);
145         assertFalse(plot1.equals(plot2));
146         plot2.setRadiusGridlineStroke(s);
147         assertTrue(plot1.equals(plot2));
148         
149         plot1.setRadiusGridlinesVisible(false);
150         assertFalse(plot1.equals(plot2));
151         plot2.setRadiusGridlinesVisible(false);
152         assertTrue(plot1.equals(plot2));
153     }
154
155     /**
156      * Some basic checks for the clone() method.
157      */

158     public void testCloning() {
159         PolarPlot p1 = new PolarPlot();
160         PolarPlot p2 = null;
161         try {
162             p2 = (PolarPlot) p1.clone();
163         }
164         catch (CloneNotSupportedException JavaDoc e) {
165             e.printStackTrace();
166             System.err.println("Failed to clone.");
167         }
168         assertTrue(p1 != p2);
169         assertTrue(p1.getClass() == p2.getClass());
170         assertTrue(p1.equals(p2));
171     }
172
173     /**
174      * Serialize an instance, restore it, and check for equality.
175      */

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