KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > renderer > xy > junit > XYErrorRendererTests


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  * XYErrorRendererTests.java
29  * -------------------------
30  * (C) Copyright 2006, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: XYErrorRendererTests.java,v 1.1.2.1 2006/10/25 09:51:49 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 25-Oct-2006 : Version 1 (DG);
40  *
41  */

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

63 public class XYErrorRendererTests extends TestCase {
64
65     /**
66      * Returns the tests as a test suite.
67      *
68      * @return The test suite.
69      */

70     public static Test suite() {
71         return new TestSuite(XYErrorRendererTests.class);
72     }
73
74     /**
75      * Constructs a new set of tests.
76      *
77      * @param name the name of the tests.
78      */

79     public XYErrorRendererTests(String JavaDoc name) {
80         super(name);
81     }
82
83     /**
84      * Check that the equals() method distinguishes all fields.
85      */

86     public void testEquals() {
87         XYErrorRenderer r1 = new XYErrorRenderer();
88         XYErrorRenderer r2 = new XYErrorRenderer();
89         assertEquals(r1, r2);
90         
91         // drawXError
92
r1.setDrawXError(false);
93         assertFalse(r1.equals(r2));
94         r2.setDrawXError(false);
95         assertTrue(r1.equals(r2));
96         
97         // drawYError
98
r1.setDrawYError(false);
99         assertFalse(r1.equals(r2));
100         r2.setDrawYError(false);
101         assertTrue(r1.equals(r2));
102         
103         // capLength
104
r1.setCapLength(9.0);
105         assertFalse(r1.equals(r2));
106         r2.setCapLength(9.0);
107         assertTrue(r1.equals(r2));
108         
109         // errorPaint
110
r1.setErrorPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
111                 Color.green));
112         assertFalse(r1.equals(r2));
113         r2.setErrorPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
114                 Color.green));
115         assertTrue(r1.equals(r2));
116     }
117
118     /**
119      * Two objects that are equal are required to return the same hashCode.
120      */

121     public void testHashcode() {
122         XYErrorRenderer r1 = new XYErrorRenderer();
123         XYErrorRenderer r2 = new XYErrorRenderer();
124         assertTrue(r1.equals(r2));
125         int h1 = r1.hashCode();
126         int h2 = r2.hashCode();
127         assertEquals(h1, h2);
128     }
129     
130     /**
131      * Confirm that cloning works.
132      */

133     public void testCloning() {
134         XYErrorRenderer r1 = new XYErrorRenderer();
135         r1.setErrorPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
136                 Color.white));
137         XYErrorRenderer r2 = null;
138         try {
139             r2 = (XYErrorRenderer) r1.clone();
140         }
141         catch (CloneNotSupportedException JavaDoc e) {
142             e.printStackTrace();
143         }
144         assertTrue(r1 != r2);
145         assertTrue(r1.getClass() == r2.getClass());
146         assertTrue(r1.equals(r2));
147     }
148
149     /**
150      * Serialize an instance, restore it, and check for equality.
151      */

152     public void testSerialization() {
153
154         XYErrorRenderer r1 = new XYErrorRenderer();
155         r1.setErrorPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
156                 Color.white));
157         XYErrorRenderer r2 = null;
158
159         try {
160             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
161             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
162             out.writeObject(r1);
163             out.close();
164
165             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
166                     new ByteArrayInputStream JavaDoc(buffer.toByteArray()));
167             r2 = (XYErrorRenderer) in.readObject();
168             in.close();
169         }
170         catch (Exception JavaDoc e) {
171             e.printStackTrace();
172         }
173         assertEquals(r1, r2);
174
175     }
176
177 }
178
Popular Tags