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: * AxisTests.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: AxisTests.java,v 1.1.2.1 2006/10/03 15:41:23 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 13-Aug-2003 : Version 1 (DG);
040: * 06-Jan-2004 : Added tests for axis line attributes (DG);
041: * 07-Jan-2005 : Added hashCode() test (DG);
042: */
043:
044: package org.jfree.chart.axis.junit;
045:
046: import java.awt.BasicStroke;
047: import java.awt.Color;
048: import java.awt.Font;
049: import java.awt.GradientPaint;
050:
051: import junit.framework.Test;
052: import junit.framework.TestCase;
053: import junit.framework.TestSuite;
054:
055: import org.jfree.chart.axis.Axis;
056: import org.jfree.chart.axis.CategoryAxis;
057: import org.jfree.ui.RectangleInsets;
058:
059: /**
060: * Tests for the {@link Axis} class.
061: */
062: public class AxisTests extends TestCase {
063:
064: /**
065: * Returns the tests as a test suite.
066: *
067: * @return The test suite.
068: */
069: public static Test suite() {
070: return new TestSuite(AxisTests.class);
071: }
072:
073: /**
074: * Constructs a new set of tests.
075: *
076: * @param name the name of the tests.
077: */
078: public AxisTests(String name) {
079: super (name);
080: }
081:
082: /**
083: * Confirm that cloning works.
084: */
085: public void testCloning() {
086: CategoryAxis a1 = new CategoryAxis("Test");
087: a1.setAxisLinePaint(Color.red);
088: CategoryAxis a2 = null;
089: try {
090: a2 = (CategoryAxis) a1.clone();
091: } catch (CloneNotSupportedException e) {
092: System.err.println("Failed to clone.");
093: }
094: assertTrue(a1 != a2);
095: assertTrue(a1.getClass() == a2.getClass());
096: assertTrue(a1.equals(a2));
097: }
098:
099: /**
100: * Confirm that the equals method can distinguish all the required fields.
101: */
102: public void testEquals() {
103:
104: Axis a1 = new CategoryAxis("Test");
105: Axis a2 = new CategoryAxis("Test");
106: assertTrue(a1.equals(a2));
107:
108: // visible flag...
109: a1.setVisible(false);
110: assertFalse(a1.equals(a2));
111: a2.setVisible(false);
112: assertTrue(a1.equals(a2));
113:
114: // label...
115: a1.setLabel("New Label");
116: assertFalse(a1.equals(a2));
117: a2.setLabel("New Label");
118: assertTrue(a1.equals(a2));
119:
120: // label font...
121: a1.setLabelFont(new Font("Dialog", Font.PLAIN, 8));
122: assertFalse(a1.equals(a2));
123: a2.setLabelFont(new Font("Dialog", Font.PLAIN, 8));
124: assertTrue(a1.equals(a2));
125:
126: // label paint...
127: a1.setLabelPaint(new GradientPaint(1.0f, 2.0f, Color.white,
128: 3.0f, 4.0f, Color.black));
129: assertFalse(a1.equals(a2));
130: a2.setLabelPaint(new GradientPaint(1.0f, 2.0f, Color.white,
131: 3.0f, 4.0f, Color.black));
132: assertTrue(a1.equals(a2));
133:
134: // label insets...
135: a1.setLabelInsets(new RectangleInsets(10.0, 10.0, 10.0, 10.0));
136: assertFalse(a1.equals(a2));
137: a2.setLabelInsets(new RectangleInsets(10.0, 10.0, 10.0, 10.0));
138: assertTrue(a1.equals(a2));
139:
140: // label angle...
141: a1.setLabelAngle(1.23);
142: assertFalse(a1.equals(a2));
143: a2.setLabelAngle(1.23);
144: assertTrue(a1.equals(a2));
145:
146: // axis line visible...
147: a1.setAxisLineVisible(false);
148: assertFalse(a1.equals(a2));
149: a2.setAxisLineVisible(false);
150: assertTrue(a1.equals(a2));
151:
152: // axis line stroke...
153: BasicStroke s = new BasicStroke(1.1f);
154: a1.setAxisLineStroke(s);
155: assertFalse(a1.equals(a2));
156: a2.setAxisLineStroke(s);
157: assertTrue(a1.equals(a2));
158:
159: // axis line paint...
160: a1.setAxisLinePaint(new GradientPaint(1.0f, 2.0f, Color.red,
161: 3.0f, 4.0f, Color.black));
162: assertFalse(a1.equals(a2));
163: a2.setAxisLinePaint(new GradientPaint(1.0f, 2.0f, Color.red,
164: 3.0f, 4.0f, Color.black));
165: assertTrue(a1.equals(a2));
166:
167: // tick labels visible flag...
168: a1.setTickLabelsVisible(false);
169: assertFalse(a1.equals(a2));
170: a2.setTickLabelsVisible(false);
171: assertTrue(a1.equals(a2));
172:
173: // tick label font...
174: a1.setTickLabelFont(new Font("Dialog", Font.PLAIN, 12));
175: assertFalse(a1.equals(a2));
176: a2.setTickLabelFont(new Font("Dialog", Font.PLAIN, 12));
177: assertTrue(a1.equals(a2));
178:
179: // tick label paint...
180: a1.setTickLabelPaint(new GradientPaint(1.0f, 2.0f,
181: Color.yellow, 3.0f, 4.0f, Color.black));
182: assertFalse(a1.equals(a2));
183: a2.setTickLabelPaint(new GradientPaint(1.0f, 2.0f,
184: Color.yellow, 3.0f, 4.0f, Color.black));
185: assertTrue(a1.equals(a2));
186:
187: // tick label insets...
188: a1.setTickLabelInsets(new RectangleInsets(10.0, 10.0, 10.0,
189: 10.0));
190: assertFalse(a1.equals(a2));
191: a2.setTickLabelInsets(new RectangleInsets(10.0, 10.0, 10.0,
192: 10.0));
193: assertTrue(a1.equals(a2));
194:
195: // tick marks visible flag...
196: a1.setTickMarksVisible(true);
197: assertFalse(a1.equals(a2));
198: a2.setTickMarksVisible(true);
199: assertTrue(a1.equals(a2));
200:
201: // tick mark inside length...
202: a1.setTickMarkInsideLength(1.23f);
203: assertFalse(a1.equals(a2));
204: a2.setTickMarkInsideLength(1.23f);
205: assertTrue(a1.equals(a2));
206:
207: // tick mark outside length...
208: a1.setTickMarkOutsideLength(1.23f);
209: assertFalse(a1.equals(a2));
210: a2.setTickMarkOutsideLength(1.23f);
211: assertTrue(a1.equals(a2));
212:
213: // tick mark stroke...
214: a1.setTickMarkStroke(new BasicStroke(2.0f));
215: assertFalse(a1.equals(a2));
216: a2.setTickMarkStroke(new BasicStroke(2.0f));
217: assertTrue(a1.equals(a2));
218:
219: // tick mark paint...
220: a1.setTickMarkPaint(new GradientPaint(1.0f, 2.0f, Color.cyan,
221: 3.0f, 4.0f, Color.black));
222: assertFalse(a1.equals(a2));
223: a2.setTickMarkPaint(new GradientPaint(1.0f, 2.0f, Color.cyan,
224: 3.0f, 4.0f, Color.black));
225: assertTrue(a1.equals(a2));
226:
227: // tick mark outside length...
228: a1.setFixedDimension(3.21f);
229: assertFalse(a1.equals(a2));
230: a2.setFixedDimension(3.21f);
231: assertTrue(a1.equals(a2));
232:
233: }
234:
235: /**
236: * Two objects that are equal are required to return the same hashCode.
237: */
238: public void testHashCode() {
239: Axis a1 = new CategoryAxis("Test");
240: Axis a2 = new CategoryAxis("Test");
241: assertTrue(a1.equals(a2));
242: int h1 = a1.hashCode();
243: int h2 = a2.hashCode();
244: assertEquals(h1, h2);
245: }
246:
247: }
|