KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * ------------------------------
23  * WaterfallBarRendererTests.java
24  * ------------------------------
25  * (C) Copyright 2003 by Object Refinery Limited and Contributors.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): -;
29  *
30  * $Id: WaterfallBarRendererTests.java,v 1.3 2003/11/13 09:25:20 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 21-Oct-2003 : Version 1 (DG);
35  *
36  */

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

59 public class WaterfallBarRendererTests extends TestCase {
60
61     /**
62      * Returns the tests as a test suite.
63      *
64      * @return the test suite.
65      */

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

75     public WaterfallBarRendererTests(String JavaDoc name) {
76         super(name);
77     }
78
79     /**
80      * Test that the equals(...) method distinguishes all fields.
81      */

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

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

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

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