001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * ------------------------
028: * TextAnnotationTests.java
029: * ------------------------
030: * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: TextAnnotationTests.java,v 1.1.2.1 2006/10/03 15:41:40 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 19-Aug-2003 : Version 1 (DG);
040: * 07-Jan-2005 : Added testHashCode() method (DG);
041: *
042: */
043:
044: package org.jfree.chart.annotations.junit;
045:
046: import java.awt.Color;
047: import java.awt.Font;
048: import java.awt.GradientPaint;
049:
050: import junit.framework.Test;
051: import junit.framework.TestCase;
052: import junit.framework.TestSuite;
053:
054: import org.jfree.chart.annotations.CategoryTextAnnotation;
055: import org.jfree.chart.annotations.TextAnnotation;
056: import org.jfree.ui.TextAnchor;
057:
058: /**
059: * Tests for the {@link TextAnnotation} class.
060: */
061: public class TextAnnotationTests extends TestCase {
062:
063: /**
064: * Returns the tests as a test suite.
065: *
066: * @return The test suite.
067: */
068: public static Test suite() {
069: return new TestSuite(TextAnnotationTests.class);
070: }
071:
072: /**
073: * Constructs a new set of tests.
074: *
075: * @param name the name of the tests.
076: */
077: public TextAnnotationTests(String name) {
078: super (name);
079: }
080:
081: /**
082: * Confirm that the equals method can distinguish all the required fields.
083: */
084: public void testEquals() {
085:
086: TextAnnotation a1 = new CategoryTextAnnotation("Test",
087: "Category", 1.0);
088: TextAnnotation a2 = new CategoryTextAnnotation("Test",
089: "Category", 1.0);
090: assertTrue(a1.equals(a2));
091:
092: // text
093: a1.setText("Text");
094: assertFalse(a1.equals(a2));
095: a2.setText("Text");
096: assertTrue(a1.equals(a2));
097:
098: // font
099: a1.setFont(new Font("Serif", Font.BOLD, 18));
100: assertFalse(a1.equals(a2));
101: a2.setFont(new Font("Serif", Font.BOLD, 18));
102: assertTrue(a1.equals(a2));
103:
104: // paint
105: a1.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f,
106: 4.0f, Color.pink));
107: assertFalse(a1.equals(a2));
108: a2.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f,
109: 4.0f, Color.pink));
110: assertTrue(a1.equals(a2));
111:
112: // textAnchor
113: a1.setTextAnchor(TextAnchor.BOTTOM_LEFT);
114: assertFalse(a1.equals(a2));
115: a2.setTextAnchor(TextAnchor.BOTTOM_LEFT);
116: assertTrue(a1.equals(a2));
117:
118: // rotationAnchor
119: a1.setRotationAnchor(TextAnchor.BOTTOM_LEFT);
120: assertFalse(a1.equals(a2));
121: a2.setRotationAnchor(TextAnchor.BOTTOM_LEFT);
122: assertTrue(a1.equals(a2));
123:
124: // rotationAngle
125: a1.setRotationAngle(Math.PI);
126: assertFalse(a1.equals(a2));
127: a2.setRotationAngle(Math.PI);
128: assertTrue(a1.equals(a2));
129:
130: }
131:
132: /**
133: * Two objects that are equal are required to return the same hashCode.
134: */
135: public void testHashCode() {
136: TextAnnotation a1 = new CategoryTextAnnotation("Test",
137: "Category", 1.0);
138: TextAnnotation a2 = new CategoryTextAnnotation("Test",
139: "Category", 1.0);
140: assertTrue(a1.equals(a2));
141: int h1 = a1.hashCode();
142: int h2 = a2.hashCode();
143: assertEquals(h1, h2);
144: }
145:
146: }
|