001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * -------------------
028: * PolarPlotTests.java
029: * -------------------
030: * (C) Copyright 2005, 2007, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: PolarPlotTests.java,v 1.1.2.3 2007/03/21 10:37:20 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 23-Feb-2005 : Version 1 (DG);
040: * 08-Jun-2005 : Extended testEquals() (DG);
041: * 07-Feb-2007 : Extended testEquals() and testCloning() (DG);
042: *
043: */
044:
045: package org.jfree.chart.plot.junit;
046:
047: import java.awt.BasicStroke;
048: import java.awt.Color;
049: import java.awt.Font;
050: import java.awt.GradientPaint;
051: import java.awt.Stroke;
052: import java.io.ByteArrayInputStream;
053: import java.io.ByteArrayOutputStream;
054: import java.io.ObjectInput;
055: import java.io.ObjectInputStream;
056: import java.io.ObjectOutput;
057: import java.io.ObjectOutputStream;
058:
059: import junit.framework.Test;
060: import junit.framework.TestCase;
061: import junit.framework.TestSuite;
062:
063: import org.jfree.chart.axis.NumberAxis;
064: import org.jfree.chart.plot.PolarPlot;
065: import org.jfree.chart.renderer.DefaultPolarItemRenderer;
066: import org.jfree.data.xy.DefaultXYDataset;
067:
068: /**
069: * Some tests for the {@link PolarPlot} class.
070: */
071: public class PolarPlotTests extends TestCase {
072:
073: /**
074: * Returns the tests as a test suite.
075: *
076: * @return The test suite.
077: */
078: public static Test suite() {
079: return new TestSuite(PolarPlotTests.class);
080: }
081:
082: /**
083: * Constructs a new set of tests.
084: *
085: * @param name the name of the tests.
086: */
087: public PolarPlotTests(String name) {
088: super (name);
089: }
090:
091: /**
092: * Some checks for the equals() method.
093: */
094: public void testEquals() {
095: PolarPlot plot1 = new PolarPlot();
096: PolarPlot plot2 = new PolarPlot();
097: assertTrue(plot1.equals(plot2));
098: assertTrue(plot2.equals(plot1));
099:
100: plot1.setAngleGridlinePaint(new GradientPaint(1.0f, 2.0f,
101: Color.red, 3.0f, 4.0f, Color.blue));
102: assertFalse(plot1.equals(plot2));
103: plot2.setAngleGridlinePaint(new GradientPaint(1.0f, 2.0f,
104: Color.red, 3.0f, 4.0f, Color.blue));
105: assertTrue(plot1.equals(plot2));
106:
107: Stroke s = new BasicStroke(1.23f);
108: plot1.setAngleGridlineStroke(s);
109: assertFalse(plot1.equals(plot2));
110: plot2.setAngleGridlineStroke(s);
111: assertTrue(plot1.equals(plot2));
112:
113: plot1.setAngleGridlinesVisible(false);
114: assertFalse(plot1.equals(plot2));
115: plot2.setAngleGridlinesVisible(false);
116: assertTrue(plot1.equals(plot2));
117:
118: plot1.setAngleLabelFont(new Font("Serif", Font.PLAIN, 9));
119: assertFalse(plot1.equals(plot2));
120: plot2.setAngleLabelFont(new Font("Serif", Font.PLAIN, 9));
121: assertTrue(plot1.equals(plot2));
122:
123: plot1.setAngleLabelPaint(new GradientPaint(9.0f, 8.0f,
124: Color.blue, 7.0f, 6.0f, Color.red));
125: assertFalse(plot1.equals(plot2));
126: plot2.setAngleLabelPaint(new GradientPaint(9.0f, 8.0f,
127: Color.blue, 7.0f, 6.0f, Color.red));
128: assertTrue(plot1.equals(plot2));
129:
130: plot1.setAngleLabelsVisible(false);
131: assertFalse(plot1.equals(plot2));
132: plot2.setAngleLabelsVisible(false);
133: assertTrue(plot1.equals(plot2));
134:
135: plot1.setAxis(new NumberAxis("Test"));
136: assertFalse(plot1.equals(plot2));
137: plot2.setAxis(new NumberAxis("Test"));
138: assertTrue(plot1.equals(plot2));
139:
140: plot1.setRadiusGridlinePaint(new GradientPaint(1.0f, 2.0f,
141: Color.white, 3.0f, 4.0f, Color.black));
142: assertFalse(plot1.equals(plot2));
143: plot2.setRadiusGridlinePaint(new GradientPaint(1.0f, 2.0f,
144: Color.white, 3.0f, 4.0f, Color.black));
145: assertTrue(plot1.equals(plot2));
146:
147: plot1.setRadiusGridlineStroke(s);
148: assertFalse(plot1.equals(plot2));
149: plot2.setRadiusGridlineStroke(s);
150: assertTrue(plot1.equals(plot2));
151:
152: plot1.setRadiusGridlinesVisible(false);
153: assertFalse(plot1.equals(plot2));
154: plot2.setRadiusGridlinesVisible(false);
155: assertTrue(plot1.equals(plot2));
156:
157: plot1.addCornerTextItem("XYZ");
158: assertFalse(plot1.equals(plot2));
159: plot2.addCornerTextItem("XYZ");
160: assertTrue(plot1.equals(plot2));
161: }
162:
163: /**
164: * Some basic checks for the clone() method.
165: */
166: public void testCloning() {
167: PolarPlot p1 = new PolarPlot();
168: PolarPlot p2 = null;
169: try {
170: p2 = (PolarPlot) p1.clone();
171: } catch (CloneNotSupportedException e) {
172: e.printStackTrace();
173: }
174: assertTrue(p1 != p2);
175: assertTrue(p1.getClass() == p2.getClass());
176: assertTrue(p1.equals(p2));
177:
178: // check independence
179: p1.addCornerTextItem("XYZ");
180: assertFalse(p1.equals(p2));
181: p2.addCornerTextItem("XYZ");
182: assertTrue(p1.equals(p2));
183:
184: p1 = new PolarPlot(new DefaultXYDataset(),
185: new NumberAxis("A1"), new DefaultPolarItemRenderer());
186: p2 = null;
187: try {
188: p2 = (PolarPlot) p1.clone();
189: } catch (CloneNotSupportedException e) {
190: e.printStackTrace();
191: System.err.println("Failed to clone.");
192: }
193: assertTrue(p1 != p2);
194: assertTrue(p1.getClass() == p2.getClass());
195: assertTrue(p1.equals(p2));
196:
197: // check independence
198: p1.getAxis().setLabel("ABC");
199: assertFalse(p1.equals(p2));
200: p2.getAxis().setLabel("ABC");
201: assertTrue(p1.equals(p2));
202:
203: }
204:
205: /**
206: * Serialize an instance, restore it, and check for equality.
207: */
208: public void testSerialization() {
209:
210: PolarPlot p1 = new PolarPlot();
211: p1.setAngleGridlinePaint(new GradientPaint(1.0f, 2.0f,
212: Color.red, 3.0f, 4.0f, Color.blue));
213: p1.setAngleLabelPaint(new GradientPaint(1.0f, 2.0f, Color.red,
214: 3.0f, 4.0f, Color.blue));
215: p1.setRadiusGridlinePaint(new GradientPaint(1.0f, 2.0f,
216: Color.red, 3.0f, 4.0f, Color.blue));
217: PolarPlot p2 = null;
218:
219: try {
220: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
221: ObjectOutput out = new ObjectOutputStream(buffer);
222: out.writeObject(p1);
223: out.close();
224:
225: ObjectInput in = new ObjectInputStream(
226: new ByteArrayInputStream(buffer.toByteArray()));
227: p2 = (PolarPlot) in.readObject();
228: in.close();
229: } catch (Exception e) {
230: e.printStackTrace();
231: }
232: assertEquals(p1, p2);
233:
234: }
235:
236: }
|