001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2006, 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: * RingPlotTests.java
029: * ------------------
030: * (C) Copyright 2004-2006, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: RingPlotTests.java,v 1.1.2.2 2006/10/12 11:12:56 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 09-Nov-2004 : Version 1 (DG);
040: * 12-Oct-2006 : Updated testEquals() (DG);
041: *
042: */
043:
044: package org.jfree.chart.plot.junit;
045:
046: import java.awt.BasicStroke;
047: import java.awt.Color;
048: import java.awt.GradientPaint;
049: import java.awt.Stroke;
050: import java.io.ByteArrayInputStream;
051: import java.io.ByteArrayOutputStream;
052: import java.io.ObjectInput;
053: import java.io.ObjectInputStream;
054: import java.io.ObjectOutput;
055: import java.io.ObjectOutputStream;
056:
057: import junit.framework.Test;
058: import junit.framework.TestCase;
059: import junit.framework.TestSuite;
060:
061: import org.jfree.chart.plot.RingPlot;
062:
063: /**
064: * Tests for the {@link RingPlot} class.
065: */
066: public class RingPlotTests 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(RingPlotTests.class);
075: }
076:
077: /**
078: * Constructs a new set of tests.
079: *
080: * @param name the name of the tests.
081: */
082: public RingPlotTests(String name) {
083: super (name);
084: }
085:
086: /**
087: * Some checks for the equals() method.
088: */
089: public void testEquals() {
090:
091: RingPlot plot1 = new RingPlot(null);
092: RingPlot plot2 = new RingPlot(null);
093: assertTrue(plot1.equals(plot2));
094: assertTrue(plot2.equals(plot1));
095:
096: // separatorsVisible
097: plot1.setSeparatorsVisible(false);
098: assertFalse(plot1.equals(plot2));
099: plot2.setSeparatorsVisible(false);
100: assertTrue(plot1.equals(plot2));
101:
102: // separatorStroke
103: Stroke s = new BasicStroke(1.1f);
104: plot1.setSeparatorStroke(s);
105: assertFalse(plot1.equals(plot2));
106: plot2.setSeparatorStroke(s);
107: assertTrue(plot1.equals(plot2));
108:
109: // separatorPaint
110: plot1.setSeparatorPaint(new GradientPaint(1.0f, 2.0f,
111: Color.red, 2.0f, 1.0f, Color.blue));
112: assertFalse(plot1.equals(plot2));
113: plot2.setSeparatorPaint(new GradientPaint(1.0f, 2.0f,
114: Color.red, 2.0f, 1.0f, Color.blue));
115: assertTrue(plot1.equals(plot2));
116:
117: // innerSeparatorExtension
118: plot1.setInnerSeparatorExtension(0.01);
119: assertFalse(plot1.equals(plot2));
120: plot2.setInnerSeparatorExtension(0.01);
121: assertTrue(plot1.equals(plot2));
122:
123: // outerSeparatorExtension
124: plot1.setOuterSeparatorExtension(0.02);
125: assertFalse(plot1.equals(plot2));
126: plot2.setOuterSeparatorExtension(0.02);
127: assertTrue(plot1.equals(plot2));
128:
129: // sectionDepth
130: plot1.setSectionDepth(0.12);
131: assertFalse(plot1.equals(plot2));
132: plot2.setSectionDepth(0.12);
133: assertTrue(plot1.equals(plot2));
134:
135: }
136:
137: /**
138: * Confirm that cloning works.
139: */
140: public void testCloning() {
141: RingPlot p1 = new RingPlot(null);
142: GradientPaint gp = new GradientPaint(1.0f, 2.0f, Color.yellow,
143: 3.0f, 4.0f, Color.red);
144: p1.setSeparatorPaint(gp);
145: RingPlot p2 = null;
146: try {
147: p2 = (RingPlot) p1.clone();
148: } catch (CloneNotSupportedException e) {
149: e.printStackTrace();
150: }
151: assertTrue(p1 != p2);
152: assertTrue(p1.getClass() == p2.getClass());
153: assertTrue(p1.equals(p2));
154: }
155:
156: /**
157: * Serialize an instance, restore it, and check for equality.
158: */
159: public void testSerialization() {
160:
161: RingPlot p1 = new RingPlot(null);
162: GradientPaint gp = new GradientPaint(1.0f, 2.0f, Color.yellow,
163: 3.0f, 4.0f, Color.red);
164: p1.setSeparatorPaint(gp);
165: RingPlot p2 = null;
166: try {
167: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
168: ObjectOutput out = new ObjectOutputStream(buffer);
169: out.writeObject(p1);
170: out.close();
171:
172: ObjectInput in = new ObjectInputStream(
173: new ByteArrayInputStream(buffer.toByteArray()));
174: p2 = (RingPlot) in.readObject();
175: in.close();
176: } catch (Exception e) {
177: e.printStackTrace();
178: }
179: assertEquals(p1, p2);
180: }
181:
182: }
|