KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > annotations > junit > TextAnnotationTests


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  * TextAnnotationTests.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: TextAnnotationTests.java,v 1.3 2005/02/28 16:10:46 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 19-Aug-2003 : Version 1 (DG);
39  * 07-Jan-2005 : Added testHashCode() method (DG);
40  *
41  */

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

59 public class TextAnnotationTests 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(TextAnnotationTests.class);
68     }
69
70     /**
71      * Constructs a new set of tests.
72      *
73      * @param name the name of the tests.
74      */

75     public TextAnnotationTests(String JavaDoc name) {
76         super(name);
77     }
78
79     /**
80      * Confirm that the equals method can distinguish all the required fields.
81      */

82     public void testEquals() {
83         
84         TextAnnotation a1 = new CategoryTextAnnotation("Test", "Category", 1.0);
85         TextAnnotation a2 = new CategoryTextAnnotation("Test", "Category", 1.0);
86         assertTrue(a1.equals(a2));
87         
88         // text
89
a1.setText("Text");
90         assertFalse(a1.equals(a2));
91         a2.setText("Text");
92         assertTrue(a1.equals(a2));
93
94         // font
95
a1.setFont(new Font JavaDoc("Serif", Font.BOLD, 18));
96         assertFalse(a1.equals(a2));
97         a2.setFont(new Font JavaDoc("Serif", Font.BOLD, 18));
98         assertTrue(a1.equals(a2));
99
100         // paint
101
a1.setPaint(Color.red);
102         assertFalse(a1.equals(a2));
103         a2.setPaint(Color.red);
104         assertTrue(a1.equals(a2));
105
106         // textAnchor
107
a1.setTextAnchor(TextAnchor.BOTTOM_LEFT);
108         assertFalse(a1.equals(a2));
109         a2.setTextAnchor(TextAnchor.BOTTOM_LEFT);
110         assertTrue(a1.equals(a2));
111
112         // rotationAnchor
113
a1.setRotationAnchor(TextAnchor.BOTTOM_LEFT);
114         assertFalse(a1.equals(a2));
115         a2.setRotationAnchor(TextAnchor.BOTTOM_LEFT);
116         assertTrue(a1.equals(a2));
117
118         // rotationAngle
119
a1.setRotationAngle(Math.PI);
120         assertFalse(a1.equals(a2));
121         a2.setRotationAngle(Math.PI);
122         assertTrue(a1.equals(a2));
123
124     }
125     
126     /**
127      * Two objects that are equal are required to return the same hashCode.
128      */

129     public void testHashCode() {
130         TextAnnotation a1 = new CategoryTextAnnotation("Test", "Category", 1.0);
131         TextAnnotation a2 = new CategoryTextAnnotation("Test", "Category", 1.0);
132         assertTrue(a1.equals(a2));
133         int h1 = a1.hashCode();
134         int h2 = a2.hashCode();
135         assertEquals(h1, h2);
136     }
137
138 }
139
Popular Tags