KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > renderer > category > junit > WaterfallBarRendererTests


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

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

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

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

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

85     public void testEquals() {
86         WaterfallBarRenderer r1 = new WaterfallBarRenderer();
87         WaterfallBarRenderer r2 = new WaterfallBarRenderer();
88         assertEquals(r1, r2);
89                 
90         // firstBarPaint;
91
r1.setFirstBarPaint(Color.cyan);
92         assertFalse(r1.equals(r2));
93         r2.setFirstBarPaint(Color.cyan);
94         assertTrue(r1.equals(r2));
95         
96         // lastBarPaint;
97
r1.setLastBarPaint(Color.cyan);
98         assertFalse(r1.equals(r2));
99         r2.setLastBarPaint(Color.cyan);
100         assertTrue(r1.equals(r2));
101
102         // positiveBarPaint;
103
r1.setPositiveBarPaint(Color.cyan);
104         assertFalse(r1.equals(r2));
105         r2.setPositiveBarPaint(Color.cyan);
106         assertTrue(r1.equals(r2));
107
108         //private Paint negativeBarPaint;
109
r1.setNegativeBarPaint(Color.cyan);
110         assertFalse(r1.equals(r2));
111         r2.setNegativeBarPaint(Color.cyan);
112         assertTrue(r1.equals(r2));
113
114     }
115
116     /**
117      * Two objects that are equal are required to return the same hashCode.
118      */

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

131     public void testCloning() {
132         WaterfallBarRenderer r1 = new WaterfallBarRenderer();
133         WaterfallBarRenderer r2 = null;
134         try {
135             r2 = (WaterfallBarRenderer) r1.clone();
136         }
137         catch (CloneNotSupportedException JavaDoc e) {
138             System.err.println("Failed to clone.");
139         }
140         assertTrue(r1 != r2);
141         assertTrue(r1.getClass() == r2.getClass());
142         assertTrue(r1.equals(r2));
143         
144         // quick check for independence
145
r1.setFirstBarPaint(Color.yellow);
146         assertFalse(r1.equals(r2));
147         r2.setFirstBarPaint(Color.yellow);
148         assertTrue(r1.equals(r2));
149         
150     }
151
152     /**
153      * Serialize an instance, restore it, and check for equality.
154      */

155     public void testSerialization() {
156
157         WaterfallBarRenderer r1 = new WaterfallBarRenderer();
158         WaterfallBarRenderer r2 = null;
159
160         try {
161             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
162             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
163             out.writeObject(r1);
164             out.close();
165
166             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
167                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
168             );
169             r2 = (WaterfallBarRenderer) in.readObject();
170             in.close();
171         }
172         catch (Exception JavaDoc e) {
173             System.out.println(e.toString());
174         }
175         assertEquals(r1, r2);
176
177     }
178
179 }
180
Popular Tags