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: * MultiplePiePlotTests.java
029: * -------------------------
030: * (C) Copyright 2005, 2006, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: MultiplePiePlotTests.java,v 1.1.2.1 2006/10/03 15:41:26 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 16-Jun-2005 : Version 1 (DG);
040: * 06-Apr-2006 : Added tests for new fields (DG);
041: *
042: */
043:
044: package org.jfree.chart.plot.junit;
045:
046: import java.awt.Color;
047: import java.awt.GradientPaint;
048: import java.io.ByteArrayInputStream;
049: import java.io.ByteArrayOutputStream;
050: import java.io.ObjectInput;
051: import java.io.ObjectInputStream;
052: import java.io.ObjectOutput;
053: import java.io.ObjectOutputStream;
054:
055: import junit.framework.Test;
056: import junit.framework.TestCase;
057: import junit.framework.TestSuite;
058:
059: import org.jfree.chart.ChartFactory;
060: import org.jfree.chart.plot.MultiplePiePlot;
061: import org.jfree.util.TableOrder;
062:
063: /**
064: * Some tests for the {@link MultiplePiePlot} class.
065: */
066: public class MultiplePiePlotTests 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(MultiplePiePlotTests.class);
075: }
076:
077: /**
078: * Constructs a new set of tests.
079: *
080: * @param name the name of the tests.
081: */
082: public MultiplePiePlotTests(String name) {
083: super (name);
084: }
085:
086: /**
087: * Check that the equals() method distinguishes the required fields.
088: */
089: public void testEquals() {
090: MultiplePiePlot p1 = new MultiplePiePlot();
091: MultiplePiePlot p2 = new MultiplePiePlot();
092: assertTrue(p1.equals(p2));
093: assertTrue(p2.equals(p1));
094:
095: p1.setDataExtractOrder(TableOrder.BY_ROW);
096: assertFalse(p1.equals(p2));
097: p2.setDataExtractOrder(TableOrder.BY_ROW);
098: assertTrue(p1.equals(p2));
099:
100: p1.setLimit(1.23);
101: assertFalse(p1.equals(p2));
102: p2.setLimit(1.23);
103: assertTrue(p1.equals(p2));
104:
105: p1.setAggregatedItemsKey("Aggregated Items");
106: assertFalse(p1.equals(p2));
107: p2.setAggregatedItemsKey("Aggregated Items");
108: assertTrue(p1.equals(p2));
109:
110: p1.setAggregatedItemsPaint(new GradientPaint(1.0f, 2.0f,
111: Color.red, 3.0f, 4.0f, Color.yellow));
112: assertFalse(p1.equals(p2));
113: p2.setAggregatedItemsPaint(new GradientPaint(1.0f, 2.0f,
114: Color.red, 3.0f, 4.0f, Color.yellow));
115: assertTrue(p1.equals(p2));
116:
117: p1.setPieChart(ChartFactory.createPieChart("Title", null, true,
118: true, true));
119: assertFalse(p1.equals(p2));
120: p2.setPieChart(ChartFactory.createPieChart("Title", null, true,
121: true, true));
122: assertTrue(p1.equals(p2));
123: }
124:
125: /**
126: * Some basic checks for the clone() method.
127: */
128: public void testCloning() {
129: MultiplePiePlot p1 = new MultiplePiePlot();
130: MultiplePiePlot p2 = null;
131: try {
132: p2 = (MultiplePiePlot) p1.clone();
133: } catch (CloneNotSupportedException e) {
134: e.printStackTrace();
135: System.err.println("Failed to clone.");
136: }
137: assertTrue(p1 != p2);
138: assertTrue(p1.getClass() == p2.getClass());
139: assertTrue(p1.equals(p2));
140: }
141:
142: /**
143: * Serialize an instance, restore it, and check for equality.
144: */
145: public void testSerialization() {
146: MultiplePiePlot p1 = new MultiplePiePlot(null);
147: p1.setAggregatedItemsPaint(new GradientPaint(1.0f, 2.0f,
148: Color.yellow, 3.0f, 4.0f, Color.red));
149: MultiplePiePlot p2 = null;
150: try {
151: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
152: ObjectOutput out = new ObjectOutputStream(buffer);
153: out.writeObject(p1);
154: out.close();
155:
156: ObjectInput in = new ObjectInputStream(
157: new ByteArrayInputStream(buffer.toByteArray()));
158: p2 = (MultiplePiePlot) in.readObject();
159: in.close();
160: } catch (Exception e) {
161: e.printStackTrace();
162: }
163: assertEquals(p1, p2);
164: }
165:
166: }
|