KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > experimental > chart > plot > dial > junit > SimpleDialFrameTests


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  * SimpleDialFrameTests.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: SimpleDialFrameTests.java,v 1.1.2.2 2006/11/06 16:31:01 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 03-Nov-2006 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.experimental.chart.plot.dial.junit;
44
45 import java.awt.BasicStroke JavaDoc;
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.experimental.chart.plot.dial.SimpleDialFrame;
60
61 /**
62  * Tests for the {@link SimpleDialFrame} class.
63  */

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

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

80     public SimpleDialFrameTests(String JavaDoc name) {
81         super(name);
82     }
83
84     /**
85      * Confirm that the equals method can distinguish all the required fields.
86      */

87     public void testEquals() {
88         SimpleDialFrame f1 = new SimpleDialFrame();
89         SimpleDialFrame f2 = new SimpleDialFrame();
90         assertTrue(f1.equals(f2));
91
92         // radius
93
f1.setRadius(0.2);
94         assertFalse(f1.equals(f2));
95         f2.setRadius(0.2);
96         assertTrue(f1.equals(f2));
97         
98         // backgroundPaint
99
f1.setBackgroundPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.white, 3.0f,
100                 4.0f, Color.yellow));
101         assertFalse(f1.equals(f2));
102         f2.setBackgroundPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.white, 3.0f,
103                 4.0f, Color.yellow));
104         assertTrue(f1.equals(f2));
105         
106         // foregroundPaint
107
f1.setForegroundPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.blue, 3.0f,
108                 4.0f, Color.green));
109         assertFalse(f1.equals(f2));
110         f2.setForegroundPaint(new GradientPaint JavaDoc(1.0f, 2.0f, Color.blue, 3.0f,
111                 4.0f, Color.green));
112         assertTrue(f1.equals(f2));
113         
114         // stroke
115
f1.setStroke(new BasicStroke JavaDoc(2.4f));
116         assertFalse(f1.equals(f2));
117         f2.setStroke(new BasicStroke JavaDoc(2.4f));
118         assertTrue(f1.equals(f2));
119     }
120
121     /**
122      * Two objects that are equal are required to return the same hashCode.
123      */

124     public void testHashCode() {
125         SimpleDialFrame f1 = new SimpleDialFrame();
126         SimpleDialFrame f2 = new SimpleDialFrame();
127         assertTrue(f1.equals(f2));
128         int h1 = f1.hashCode();
129         int h2 = f2.hashCode();
130         assertEquals(h1, h2);
131     }
132
133     /**
134      * Confirm that cloning works.
135      */

136     public void testCloning() {
137         SimpleDialFrame f1 = new SimpleDialFrame();
138         SimpleDialFrame f2 = null;
139         try {
140             f2 = (SimpleDialFrame) f1.clone();
141         }
142         catch (CloneNotSupportedException JavaDoc e) {
143             e.printStackTrace();
144         }
145         assertTrue(f1 != f2);
146         assertTrue(f1.getClass() == f2.getClass());
147         assertTrue(f1.equals(f2));
148     }
149
150
151     /**
152      * Serialize an instance, restore it, and check for equality.
153      */

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