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: * CompassPlotTests.java
029: * ---------------------
030: * (C) Copyright 2003-2007, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: CompassPlotTests.java,v 1.1.2.2 2007/03/20 21:52:16 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 27-Mar-2003 : Version 1 (DG);
040: * 20-Mar-2007 : Extended serialization tests (DG);
041: *
042: */
043:
044: package org.jfree.chart.plot.junit;
045:
046: import java.awt.Color;
047: import java.awt.Font;
048: import java.awt.GradientPaint;
049: import java.io.ByteArrayInputStream;
050: import java.io.ByteArrayOutputStream;
051: import java.io.ObjectInput;
052: import java.io.ObjectInputStream;
053: import java.io.ObjectOutput;
054: import java.io.ObjectOutputStream;
055:
056: import junit.framework.Test;
057: import junit.framework.TestCase;
058: import junit.framework.TestSuite;
059:
060: import org.jfree.chart.plot.CompassPlot;
061: import org.jfree.data.general.DefaultValueDataset;
062:
063: /**
064: * Tests for the {@link CompassPlot} class.
065: */
066: public class CompassPlotTests extends TestCase {
067:
068: /**
069: * Returns the tests as a test suite.
070: *
071: * @return The test suite.
072: */
073: public static Test suite() {
074: return new TestSuite(CompassPlotTests.class);
075: }
076:
077: /**
078: * Constructs a new set of tests.
079: *
080: * @param name the name of the tests.
081: */
082: public CompassPlotTests(String name) {
083: super (name);
084: }
085:
086: /**
087: * Test the equals() method.
088: */
089: public void testEquals() {
090: CompassPlot plot1 = new CompassPlot();
091: CompassPlot plot2 = new CompassPlot();
092: assertTrue(plot1.equals(plot2));
093:
094: // labelType...
095: plot1.setLabelType(CompassPlot.VALUE_LABELS);
096: assertFalse(plot1.equals(plot2));
097: plot2.setLabelType(CompassPlot.VALUE_LABELS);
098: assertTrue(plot1.equals(plot2));
099:
100: // labelFont
101: plot1.setLabelFont(new Font("Serif", Font.PLAIN, 10));
102: assertFalse(plot1.equals(plot2));
103: plot2.setLabelFont(new Font("Serif", Font.PLAIN, 10));
104: assertTrue(plot1.equals(plot2));
105:
106: // drawBorder
107: plot1.setDrawBorder(true);
108: assertFalse(plot1.equals(plot2));
109: plot2.setDrawBorder(true);
110: assertTrue(plot1.equals(plot2));
111:
112: // rosePaint
113: plot1.setRosePaint(new GradientPaint(1.0f, 2.0f, Color.blue,
114: 3.0f, 4.0f, Color.yellow));
115: assertFalse(plot1.equals(plot2));
116: plot2.setRosePaint(new GradientPaint(1.0f, 2.0f, Color.blue,
117: 3.0f, 4.0f, Color.yellow));
118: assertTrue(plot1.equals(plot2));
119:
120: // roseCenterPaint
121: plot1.setRoseCenterPaint(new GradientPaint(1.0f, 2.0f,
122: Color.red, 3.0f, 4.0f, Color.yellow));
123: assertFalse(plot1.equals(plot2));
124: plot2.setRoseCenterPaint(new GradientPaint(1.0f, 2.0f,
125: Color.red, 3.0f, 4.0f, Color.yellow));
126: assertTrue(plot1.equals(plot2));
127:
128: // roseHighlightPaint
129: plot1.setRoseHighlightPaint(new GradientPaint(1.0f, 2.0f,
130: Color.green, 3.0f, 4.0f, Color.yellow));
131: assertFalse(plot1.equals(plot2));
132: plot2.setRoseHighlightPaint(new GradientPaint(1.0f, 2.0f,
133: Color.green, 3.0f, 4.0f, Color.yellow));
134: assertTrue(plot1.equals(plot2));
135: }
136:
137: /**
138: * Serialize an instance, restore it, and check for equality.
139: */
140: public void testSerialization() {
141:
142: CompassPlot p1 = new CompassPlot(null);
143: p1.setRosePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f,
144: 4.0f, Color.blue));
145: p1.setRoseCenterPaint(new GradientPaint(4.0f, 3.0f, Color.red,
146: 2.0f, 1.0f, Color.green));
147: p1.setRoseHighlightPaint(new GradientPaint(4.0f, 3.0f,
148: Color.red, 2.0f, 1.0f, Color.green));
149: CompassPlot p2 = null;
150:
151: try {
152: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
153: ObjectOutput out = new ObjectOutputStream(buffer);
154: out.writeObject(p1);
155: out.close();
156:
157: ObjectInput in = new ObjectInputStream(
158: new ByteArrayInputStream(buffer.toByteArray()));
159: p2 = (CompassPlot) in.readObject();
160: in.close();
161: } catch (Exception e) {
162: e.printStackTrace();
163: }
164: assertEquals(p1, p2);
165:
166: }
167:
168: /**
169: * Confirm that cloning works.
170: */
171: public void testCloning() {
172: CompassPlot p1 = new CompassPlot(new DefaultValueDataset(15.0));
173: CompassPlot p2 = null;
174: try {
175: p2 = (CompassPlot) p1.clone();
176: } catch (CloneNotSupportedException e) {
177: e.printStackTrace();
178: }
179: assertTrue(p1 != p2);
180: assertTrue(p1.getClass() == p2.getClass());
181: assertTrue(p1.equals(p2));
182: }
183:
184: }
|