KickJava   Java API By Example, From Geeks To Geeks.

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


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  * AxisSpaceTests.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: AxisSpaceTests.java,v 1.3 2005/03/16 12:10:45 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 14-Aug-2003 : Version 1 (DG);
39  * 07-Jan-2005 : Added hashCode test (DG);
40  *
41  */

42
43 package org.jfree.chart.axis.junit;
44
45 import junit.framework.Test;
46 import junit.framework.TestCase;
47 import junit.framework.TestSuite;
48
49 import org.jfree.chart.axis.AxisSpace;
50
51 /**
52  * Tests for the {@link AxisSpace} class.
53  */

54 public class AxisSpaceTests extends TestCase {
55
56     /**
57      * Returns the tests as a test suite.
58      *
59      * @return The test suite.
60      */

61     public static Test suite() {
62         return new TestSuite(AxisSpaceTests.class);
63     }
64
65     /**
66      * Constructs a new set of tests.
67      *
68      * @param name the name of the tests.
69      */

70     public AxisSpaceTests(String JavaDoc name) {
71         super(name);
72     }
73     
74     /**
75      * Check that the equals() method can distinguish all fields.
76      */

77     public void testEquals() {
78         AxisSpace a1 = new AxisSpace();
79         AxisSpace a2 = new AxisSpace();
80         assertEquals(a1, a2);
81         
82         a1.setTop(1.11);
83         assertFalse(a1.equals(a2));
84         a2.setTop(1.11);
85         assertTrue(a1.equals(a2));
86         
87         a1.setBottom(2.22);
88         assertFalse(a1.equals(a2));
89         a2.setBottom(2.22);
90         assertTrue(a1.equals(a2));
91
92         a1.setLeft(3.33);
93         assertFalse(a1.equals(a2));
94         a2.setLeft(3.33);
95         assertTrue(a1.equals(a2));
96
97         a1.setRight(4.44);
98         assertFalse(a1.equals(a2));
99         a2.setRight(4.44);
100         assertTrue(a1.equals(a2));
101     }
102     
103     /**
104      * Two objects that are equal are required to return the same hashCode.
105      */

106     public void testHashCode() {
107         AxisSpace s1 = new AxisSpace();
108         AxisSpace s2 = new AxisSpace();
109         assertTrue(s1.equals(s2));
110         int h1 = s1.hashCode();
111         int h2 = s2.hashCode();
112         assertEquals(h1, h2);
113     }
114     
115     /**
116      * Confirm that cloning works.
117      */

118     public void testCloning() {
119         AxisSpace s1 = new AxisSpace();
120         AxisSpace s2 = null;
121         try {
122             s2 = (AxisSpace) s1.clone();
123         }
124         catch (CloneNotSupportedException JavaDoc e) {
125             System.err.println("Failed to clone.");
126         }
127         assertTrue(s1 != s2);
128         assertTrue(s1.getClass() == s2.getClass());
129         assertTrue(s1.equals(s2));
130     }
131     
132 }
133
134
Popular Tags