KickJava   Java API By Example, From Geeks To Geeks.

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


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  * RingPlotTests.java
29  * ------------------
30  * (C) Copyright 2004-2006, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: RingPlotTests.java,v 1.1.2.2 2006/10/12 11:12:56 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 09-Nov-2004 : Version 1 (DG);
40  * 12-Oct-2006 : Updated testEquals() (DG);
41  *
42  */

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

66 public class RingPlotTests 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(RingPlotTests.class);
75     }
76
77     /**
78      * Constructs a new set of tests.
79      *
80      * @param name the name of the tests.
81      */

82     public RingPlotTests(String JavaDoc name) {
83         super(name);
84     }
85
86     /**
87      * Some checks for the equals() method.
88      */

89     public void testEquals() {
90         
91         RingPlot plot1 = new RingPlot(null);
92         RingPlot plot2 = new RingPlot(null);
93         assertTrue(plot1.equals(plot2));
94         assertTrue(plot2.equals(plot1));
95                 
96         // separatorsVisible
97
plot1.setSeparatorsVisible(false);
98         assertFalse(plot1.equals(plot2));
99         plot2.setSeparatorsVisible(false);
100         assertTrue(plot1.equals(plot2));
101         
102         // separatorStroke
103
Stroke JavaDoc s = new BasicStroke JavaDoc(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 JavaDoc(1.0f, 2.0f, Color.red,
111                 2.0f, 1.0f, Color.blue));
112         assertFalse(plot1.equals(plot2));
113         plot2.setSeparatorPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red,
114                 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 JavaDoc gp = new GradientPaint JavaDoc(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         }
149         catch (CloneNotSupportedException JavaDoc e) {
150             e.printStackTrace();
151         }
152         assertTrue(p1 != p2);
153         assertTrue(p1.getClass() == p2.getClass());
154         assertTrue(p1.equals(p2));
155     }
156
157     /**
158      * Serialize an instance, restore it, and check for equality.
159      */

160     public void testSerialization() {
161
162         RingPlot p1 = new RingPlot(null);
163         GradientPaint JavaDoc gp = new GradientPaint JavaDoc(1.0f, 2.0f, Color.yellow,
164                 3.0f, 4.0f, Color.red);
165         p1.setSeparatorPaint(gp);
166         RingPlot p2 = null;
167         try {
168             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
169             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
170             out.writeObject(p1);
171             out.close();
172
173             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
174                     new ByteArrayInputStream JavaDoc(buffer.toByteArray()));
175             p2 = (RingPlot) in.readObject();
176             in.close();
177         }
178         catch (Exception JavaDoc e) {
179             e.printStackTrace();
180         }
181         assertEquals(p1, p2);
182     }
183
184 }
185
Popular Tags