KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > axis > junit > CyclicNumberAxisTests


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 License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * --------------------
27  * CyclicAxisTests.java
28  * --------------------
29  * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
30  *
31  * Original Author: Nicolas Brodu
32  * Contributor(s): -;
33  *
34  * $Id: CyclicNumberAxisTests.java,v 1.4 2005/03/16 12:10:45 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 19-Nov-2003 : First version (NB);
39  * 05-Oct-2004 : Removed extension of NumberAxisTests (DG);
40  * 07-Jan-2004 : Added test for hashCode() (DG);
41  *
42  */

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

67 public class CyclicNumberAxisTests extends TestCase {
68
69     /**
70      * Returns the tests as a test suite.
71      *
72      * @return The test suite.
73      */

74     public static Test suite() {
75         return new TestSuite(CyclicNumberAxisTests.class);
76     }
77
78     /**
79      * Constructs a new set of tests.
80      *
81      * @param name the name of the tests.
82      */

83     public CyclicNumberAxisTests(String JavaDoc name) {
84         super(name);
85     }
86
87     /**
88      * Confirm that cloning works.
89      */

90     public void testCloning() {
91         CyclicNumberAxis a1 = new CyclicNumberAxis(10, 0, "Test");
92         CyclicNumberAxis a2 = null;
93         try {
94             a2 = (CyclicNumberAxis) a1.clone();
95         }
96         catch (CloneNotSupportedException JavaDoc e) {
97             System.err.println("Failed to clone.");
98         }
99         assertTrue(a1 != a2);
100         assertTrue(a1.getClass() == a2.getClass());
101         assertTrue(a1.equals(a2));
102     }
103
104     /**
105      * Confirm that the equals method can distinguish all the required fields.
106      */

107     public void testEquals() {
108        
109         CyclicNumberAxis a1 = new CyclicNumberAxis(10, 0, "Test");
110         CyclicNumberAxis a2 = new CyclicNumberAxis(10, 0, "Test");
111         assertTrue(a1.equals(a2));
112         
113         // period
114
a1.setPeriod(5);
115         assertFalse(a1.equals(a2));
116         a2.setPeriod(5);
117         assertTrue(a1.equals(a2));
118
119         // offset
120
a1.setOffset(2.0);
121         assertFalse(a1.equals(a2));
122         a2.setOffset(2.0);
123         assertTrue(a1.equals(a2));
124
125         // advance line Paint
126
a1.setAdvanceLinePaint(Color.cyan);
127         assertFalse(a1.equals(a2));
128         a2.setAdvanceLinePaint(Color.cyan);
129         assertTrue(a1.equals(a2));
130         
131         // advance line Stroke
132
Stroke JavaDoc stroke = new BasicStroke JavaDoc(0.2f);
133         a1.setAdvanceLineStroke(stroke);
134         assertFalse(a1.equals(a2));
135         a2.setAdvanceLineStroke(stroke);
136         assertTrue(a1.equals(a2));
137
138         // advance line Visible
139
a1.setAdvanceLineVisible(!a1.isAdvanceLineVisible());
140         assertFalse(a1.equals(a2));
141         a2.setAdvanceLineVisible(a1.isAdvanceLineVisible());
142         assertTrue(a1.equals(a2));
143
144         // cycle bound mapping
145
a1.setBoundMappedToLastCycle(!a1.isBoundMappedToLastCycle());
146         assertFalse(a1.equals(a2));
147         a2.setBoundMappedToLastCycle(a1.isBoundMappedToLastCycle());
148         assertTrue(a1.equals(a2));
149         
150     }
151
152     /**
153      * Two objects that are equal are required to return the same hashCode.
154      */

155     public void testHashCode() {
156         CyclicNumberAxis a1 = new CyclicNumberAxis(10, 0, "Test");
157         CyclicNumberAxis a2 = new CyclicNumberAxis(10, 0, "Test");
158         assertTrue(a1.equals(a2));
159         int h1 = a1.hashCode();
160         int h2 = a2.hashCode();
161         assertEquals(h1, h2);
162     }
163
164     /**
165      * Serialize an instance, restore it, and check for equality.
166      */

167     public void testSerialization() {
168
169         CyclicNumberAxis a1 = new CyclicNumberAxis(10, 0, "Test Axis");
170         CyclicNumberAxis a2 = null;
171
172         try {
173             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
174             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
175             out.writeObject(a1);
176             out.close();
177
178             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
179                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
180             );
181             a2 = (CyclicNumberAxis) in.readObject();
182             in.close();
183         }
184         catch (Exception JavaDoc e) {
185             System.out.println(e.toString());
186         }
187         assertEquals(a1, a2);
188
189     }
190     
191 }
192
193
Popular Tags