KickJava   Java API By Example, From Geeks To Geeks.

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


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  * AxisTests.java
28  * --------------
29  * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: AxisTests.java,v 1.4 2005/04/21 09:43:33 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 13-Aug-2003 : Version 1 (DG);
39  * 06-Jan-2004 : Added tests for axis line attributes (DG);
40  * 07-Jan-2005 : Added hashCode() test (DG);
41  */

42
43 package org.jfree.chart.axis.junit;
44
45 import java.awt.BasicStroke JavaDoc;
46 import java.awt.Color JavaDoc;
47 import java.awt.Font JavaDoc;
48
49 import junit.framework.Test;
50 import junit.framework.TestCase;
51 import junit.framework.TestSuite;
52
53 import org.jfree.chart.axis.Axis;
54 import org.jfree.chart.axis.CategoryAxis;
55 import org.jfree.ui.RectangleInsets;
56
57 /**
58  * Tests for the {@link Axis} class.
59  */

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

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

76     public AxisTests(String JavaDoc name) {
77         super(name);
78     }
79
80     /**
81      * Confirm that cloning works.
82      */

83     public void testCloning() {
84         CategoryAxis a1 = new CategoryAxis("Test");
85         a1.setAxisLinePaint(Color.red);
86         CategoryAxis a2 = null;
87         try {
88             a2 = (CategoryAxis) a1.clone();
89         }
90         catch (CloneNotSupportedException JavaDoc e) {
91             System.err.println("Failed to clone.");
92         }
93         assertTrue(a1 != a2);
94         assertTrue(a1.getClass() == a2.getClass());
95         assertTrue(a1.equals(a2));
96     }
97
98     /**
99      * Confirm that the equals method can distinguish all the required fields.
100      */

101     public void testEquals() {
102         
103         Axis a1 = new CategoryAxis("Test");
104         Axis a2 = new CategoryAxis("Test");
105         assertTrue(a1.equals(a2));
106         
107         // visible flag...
108
a1.setVisible(false);
109         assertFalse(a1.equals(a2));
110         a2.setVisible(false);
111         assertTrue(a1.equals(a2));
112                 
113         // label...
114
a1.setLabel("New Label");
115         assertFalse(a1.equals(a2));
116         a2.setLabel("New Label");
117         assertTrue(a1.equals(a2));
118
119         // label font...
120
a1.setLabelFont(new Font JavaDoc("Dialog", Font.PLAIN, 8));
121         assertFalse(a1.equals(a2));
122         a2.setLabelFont(new Font JavaDoc("Dialog", Font.PLAIN, 8));
123         assertTrue(a1.equals(a2));
124
125         // label paint...
126
a1.setLabelPaint(Color.blue);
127         assertFalse(a1.equals(a2));
128         a2.setLabelPaint(Color.blue);
129         assertTrue(a1.equals(a2));
130        
131         // label insets...
132
a1.setLabelInsets(new RectangleInsets(10.0, 10.0, 10.0, 10.0));
133         assertFalse(a1.equals(a2));
134         a2.setLabelInsets(new RectangleInsets(10.0, 10.0, 10.0, 10.0));
135         assertTrue(a1.equals(a2));
136
137         // label angle...
138
a1.setLabelAngle(1.23);
139         assertFalse(a1.equals(a2));
140         a2.setLabelAngle(1.23);
141         assertTrue(a1.equals(a2));
142
143         // axis line visible...
144
a1.setAxisLineVisible(false);
145         assertFalse(a1.equals(a2));
146         a2.setAxisLineVisible(false);
147         assertTrue(a1.equals(a2));
148         
149         // axis line stroke...
150
BasicStroke JavaDoc s = new BasicStroke JavaDoc(1.1f);
151         a1.setAxisLineStroke(s);
152         assertFalse(a1.equals(a2));
153         a2.setAxisLineStroke(s);
154         assertTrue(a1.equals(a2));
155         
156         // axis line paint...
157
a1.setAxisLinePaint(Color.blue);
158         assertFalse(a1.equals(a2));
159         a2.setAxisLinePaint(Color.blue);
160         assertTrue(a1.equals(a2));
161         
162         // tick labels visible flag...
163
a1.setTickLabelsVisible(false);
164         assertFalse(a1.equals(a2));
165         a2.setTickLabelsVisible(false);
166         assertTrue(a1.equals(a2));
167                 
168         // tick label font...
169
a1.setTickLabelFont(new Font JavaDoc("Dialog", Font.PLAIN, 12));
170         assertFalse(a1.equals(a2));
171         a2.setTickLabelFont(new Font JavaDoc("Dialog", Font.PLAIN, 12));
172         assertTrue(a1.equals(a2));
173
174         // tick label paint...
175
a1.setTickLabelPaint(Color.red);
176         assertFalse(a1.equals(a2));
177         a2.setTickLabelPaint(Color.red);
178         assertTrue(a1.equals(a2));
179
180         // tick label insets...
181
a1.setTickLabelInsets(new RectangleInsets(10.0, 10.0, 10.0, 10.0));
182         assertFalse(a1.equals(a2));
183         a2.setTickLabelInsets(new RectangleInsets(10.0, 10.0, 10.0, 10.0));
184         assertTrue(a1.equals(a2));
185
186         // tick marks visible flag...
187
a1.setTickMarksVisible(true);
188         assertFalse(a1.equals(a2));
189         a2.setTickMarksVisible(true);
190         assertTrue(a1.equals(a2));
191                 
192         // tick mark inside length...
193
a1.setTickMarkInsideLength(1.23f);
194         assertFalse(a1.equals(a2));
195         a2.setTickMarkInsideLength(1.23f);
196         assertTrue(a1.equals(a2));
197
198         // tick mark outside length...
199
a1.setTickMarkOutsideLength(1.23f);
200         assertFalse(a1.equals(a2));
201         a2.setTickMarkOutsideLength(1.23f);
202         assertTrue(a1.equals(a2));
203
204         // tick mark stroke...
205
a1.setTickMarkStroke(new BasicStroke JavaDoc(2.0f));
206         assertFalse(a1.equals(a2));
207         a2.setTickMarkStroke(new BasicStroke JavaDoc(2.0f));
208         assertTrue(a1.equals(a2));
209
210         // tick mark paint...
211
a1.setTickMarkPaint(Color.green);
212         assertFalse(a1.equals(a2));
213         a2.setTickMarkPaint(Color.green);
214         assertTrue(a1.equals(a2));
215
216         // tick mark outside length...
217
a1.setFixedDimension(3.21f);
218         assertFalse(a1.equals(a2));
219         a2.setFixedDimension(3.21f);
220         assertTrue(a1.equals(a2));
221
222     }
223     
224     /**
225      * Two objects that are equal are required to return the same hashCode.
226      */

227     public void testHashCode() {
228         Axis a1 = new CategoryAxis("Test");
229         Axis a2 = new CategoryAxis("Test");
230         assertTrue(a1.equals(a2));
231         int h1 = a1.hashCode();
232         int h2 = a2.hashCode();
233         assertEquals(h1, h2);
234     }
235
236 }
237
Popular Tags