001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2006, 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: * DialValueIndicatorTests.java
029: * ----------------------------
030: * (C) Copyright 2006, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: DialValueIndicatorTests.java,v 1.1.2.4 2006/11/07 16:11:12 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 03-Nov-2006 : Version 1 (DG);
040: *
041: */
042:
043: package org.jfree.experimental.chart.plot.dial.junit;
044:
045: import java.awt.BasicStroke;
046: import java.awt.Color;
047: import java.awt.Font;
048: import java.awt.GradientPaint;
049: import java.io.ByteArrayInputStream;
050: import java.io.ByteArrayOutputStream;
051: import java.io.ObjectInput;
052: import java.io.ObjectInputStream;
053: import java.io.ObjectOutput;
054: import java.io.ObjectOutputStream;
055:
056: import junit.framework.Test;
057: import junit.framework.TestCase;
058: import junit.framework.TestSuite;
059:
060: import org.jfree.experimental.chart.plot.dial.DialValueIndicator;
061: import org.jfree.ui.RectangleAnchor;
062: import org.jfree.ui.RectangleInsets;
063: import org.jfree.ui.TextAnchor;
064:
065: /**
066: * Tests for the {@link DialValueIndicator} class.
067: */
068: public class DialValueIndicatorTests extends TestCase {
069:
070: /**
071: * Returns the tests as a test suite.
072: *
073: * @return The test suite.
074: */
075: public static Test suite() {
076: return new TestSuite(DialValueIndicatorTests.class);
077: }
078:
079: /**
080: * Constructs a new set of tests.
081: *
082: * @param name the name of the tests.
083: */
084: public DialValueIndicatorTests(String name) {
085: super (name);
086: }
087:
088: /**
089: * Confirm that the equals method can distinguish all the required fields.
090: */
091: public void testEquals() {
092: DialValueIndicator i1 = new DialValueIndicator(0, "Label");
093: DialValueIndicator i2 = new DialValueIndicator(0, "Label");
094: assertTrue(i1.equals(i2));
095:
096: // dataset index
097: i1.setDatasetIndex(99);
098: assertFalse(i1.equals(i2));
099: i2.setDatasetIndex(99);
100: assertTrue(i1.equals(i2));
101:
102: // angle
103: i1.setAngle(43);
104: assertFalse(i1.equals(i2));
105: i2.setAngle(43);
106: assertTrue(i1.equals(i2));
107:
108: // radius
109: i1.setRadius(0.77);
110: assertFalse(i1.equals(i2));
111: i2.setRadius(0.77);
112: assertTrue(i1.equals(i2));
113:
114: // frameAnchor
115: i1.setFrameAnchor(RectangleAnchor.TOP_LEFT);
116: assertFalse(i1.equals(i2));
117: i2.setFrameAnchor(RectangleAnchor.TOP_LEFT);
118: assertTrue(i1.equals(i2));
119:
120: // templateValue
121: i1.setTemplateValue(new Double(1.23));
122: assertFalse(i1.equals(i2));
123: i2.setTemplateValue(new Double(1.23));
124: assertTrue(i1.equals(i2));
125:
126: // font
127: i1.setFont(new Font("Dialog", Font.PLAIN, 7));
128: assertFalse(i1.equals(i2));
129: i2.setFont(new Font("Dialog", Font.PLAIN, 7));
130: assertTrue(i1.equals(i2));
131:
132: // paint
133: i1.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f,
134: 4.0f, Color.green));
135: assertFalse(i1.equals(i2));
136: i2.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f,
137: 4.0f, Color.green));
138: assertTrue(i1.equals(i2));
139:
140: // backgroundPaint
141: i1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red,
142: 3.0f, 4.0f, Color.green));
143: assertFalse(i1.equals(i2));
144: i2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red,
145: 3.0f, 4.0f, Color.green));
146: assertTrue(i1.equals(i2));
147:
148: // outlineStroke
149: i1.setOutlineStroke(new BasicStroke(1.1f));
150: assertFalse(i1.equals(i2));
151: i2.setOutlineStroke(new BasicStroke(1.1f));
152: assertTrue(i1.equals(i2));
153:
154: // outlinePaint
155: i1.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.red,
156: 3.0f, 4.0f, Color.green));
157: assertFalse(i1.equals(i2));
158: i2.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.red,
159: 3.0f, 4.0f, Color.green));
160: assertTrue(i1.equals(i2));
161:
162: // insets
163: i1.setInsets(new RectangleInsets(1, 2, 3, 4));
164: assertFalse(i1.equals(i2));
165: i2.setInsets(new RectangleInsets(1, 2, 3, 4));
166: assertTrue(i1.equals(i2));
167:
168: // valueAnchor
169: i1.setValueAnchor(RectangleAnchor.BOTTOM_LEFT);
170: assertFalse(i1.equals(i2));
171: i2.setValueAnchor(RectangleAnchor.BOTTOM_LEFT);
172: assertTrue(i1.equals(i2));
173:
174: // textAnchor
175: i1.setTextAnchor(TextAnchor.TOP_LEFT);
176: assertFalse(i1.equals(i2));
177: i2.setTextAnchor(TextAnchor.TOP_LEFT);
178: assertTrue(i1.equals(i2));
179: }
180:
181: /**
182: * Two objects that are equal are required to return the same hashCode.
183: */
184: public void testHashCode() {
185: DialValueIndicator i1 = new DialValueIndicator(0, "Label");
186: DialValueIndicator i2 = new DialValueIndicator(0, "Label");
187: assertTrue(i1.equals(i2));
188: int h1 = i1.hashCode();
189: int h2 = i2.hashCode();
190: assertEquals(h1, h2);
191: }
192:
193: /**
194: * Confirm that cloning works.
195: */
196: public void testCloning() {
197: // test a default instance
198: DialValueIndicator i1 = new DialValueIndicator(0, "Label");
199: DialValueIndicator i2 = null;
200: try {
201: i2 = (DialValueIndicator) i1.clone();
202: } catch (CloneNotSupportedException e) {
203: e.printStackTrace();
204: }
205: assertTrue(i1 != i2);
206: assertTrue(i1.getClass() == i2.getClass());
207: assertTrue(i1.equals(i2));
208:
209: // test a customised instance
210: }
211:
212: /**
213: * Serialize an instance, restore it, and check for equality.
214: */
215: public void testSerialization() {
216: // test a default instance
217: DialValueIndicator i1 = new DialValueIndicator(0, "Label");
218: DialValueIndicator i2 = null;
219:
220: try {
221: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
222: ObjectOutput out = new ObjectOutputStream(buffer);
223: out.writeObject(i1);
224: out.close();
225:
226: ObjectInput in = new ObjectInputStream(
227: new ByteArrayInputStream(buffer.toByteArray()));
228: i2 = (DialValueIndicator) in.readObject();
229: in.close();
230: } catch (Exception e) {
231: e.printStackTrace();
232: }
233: assertEquals(i1, i2);
234:
235: // test a custom instance
236: }
237:
238: }
|