KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2006, 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  * MultiplePiePlotTests.java
29  * -------------------------
30  * (C) Copyright 2005, 2006, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: MultiplePiePlotTests.java,v 1.1.2.1 2006/10/03 15:41:26 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 16-Jun-2005 : Version 1 (DG);
40  * 06-Apr-2006 : Added tests for new fields (DG);
41  *
42  */

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

66 public class MultiplePiePlotTests extends TestCase {
67
68     /**
69      * Returns the tests as a test suite.
70      *
71      * @return The test suite.
72      */

73     public static Test suite() {
74         return new TestSuite(MultiplePiePlotTests.class);
75     }
76
77     /**
78      * Constructs a new set of tests.
79      *
80      * @param name the name of the tests.
81      */

82     public MultiplePiePlotTests(String JavaDoc name) {
83         super(name);
84     }
85
86     /**
87      * Check that the equals() method distinguishes the required fields.
88      */

89     public void testEquals() {
90         MultiplePiePlot p1 = new MultiplePiePlot();
91         MultiplePiePlot p2 = new MultiplePiePlot();
92         assertTrue(p1.equals(p2));
93         assertTrue(p2.equals(p1));
94         
95         p1.setDataExtractOrder(TableOrder.BY_ROW);
96         assertFalse(p1.equals(p2));
97         p2.setDataExtractOrder(TableOrder.BY_ROW);
98         assertTrue(p1.equals(p2));
99         
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 JavaDoc(1.0f, 2.0f, Color.red,
111                 3.0f, 4.0f, Color.yellow));
112         assertFalse(p1.equals(p2));
113         p2.setAggregatedItemsPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red,
114                 3.0f, 4.0f, Color.yellow));
115         assertTrue(p1.equals(p2));
116         
117         p1.setPieChart(ChartFactory.createPieChart("Title", null, true, true,
118                 true));
119         assertFalse(p1.equals(p2));
120         p2.setPieChart(ChartFactory.createPieChart("Title", null, true, true,
121                 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         }
134         catch (CloneNotSupportedException JavaDoc e) {
135             e.printStackTrace();
136             System.err.println("Failed to clone.");
137         }
138         assertTrue(p1 != p2);
139         assertTrue(p1.getClass() == p2.getClass());
140         assertTrue(p1.equals(p2));
141     }
142
143     /**
144      * Serialize an instance, restore it, and check for equality.
145      */

146     public void testSerialization() {
147         MultiplePiePlot p1 = new MultiplePiePlot(null);
148         p1.setAggregatedItemsPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.yellow,
149                 3.0f, 4.0f, Color.red));
150         MultiplePiePlot p2 = null;
151         try {
152             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
153             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
154             out.writeObject(p1);
155             out.close();
156
157             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
158                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
159             );
160             p2 = (MultiplePiePlot) in.readObject();
161             in.close();
162         }
163         catch (Exception JavaDoc e) {
164             e.printStackTrace();
165         }
166         assertEquals(p1, p2);
167     }
168     
169 }
170
Popular Tags