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: * SimpleDialFrameTests.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: SimpleDialFrameTests.java,v 1.1.2.2 2006/11/06 16:31:01 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.GradientPaint;
048: import java.io.ByteArrayInputStream;
049: import java.io.ByteArrayOutputStream;
050: import java.io.ObjectInput;
051: import java.io.ObjectInputStream;
052: import java.io.ObjectOutput;
053: import java.io.ObjectOutputStream;
054:
055: import junit.framework.Test;
056: import junit.framework.TestCase;
057: import junit.framework.TestSuite;
058:
059: import org.jfree.experimental.chart.plot.dial.SimpleDialFrame;
060:
061: /**
062: * Tests for the {@link SimpleDialFrame} class.
063: */
064: public class SimpleDialFrameTests extends TestCase {
065:
066: /**
067: * Returns the tests as a test suite.
068: *
069: * @return The test suite.
070: */
071: public static Test suite() {
072: return new TestSuite(SimpleDialFrameTests.class);
073: }
074:
075: /**
076: * Constructs a new set of tests.
077: *
078: * @param name the name of the tests.
079: */
080: public SimpleDialFrameTests(String name) {
081: super (name);
082: }
083:
084: /**
085: * Confirm that the equals method can distinguish all the required fields.
086: */
087: public void testEquals() {
088: SimpleDialFrame f1 = new SimpleDialFrame();
089: SimpleDialFrame f2 = new SimpleDialFrame();
090: assertTrue(f1.equals(f2));
091:
092: // radius
093: f1.setRadius(0.2);
094: assertFalse(f1.equals(f2));
095: f2.setRadius(0.2);
096: assertTrue(f1.equals(f2));
097:
098: // backgroundPaint
099: f1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f,
100: Color.white, 3.0f, 4.0f, Color.yellow));
101: assertFalse(f1.equals(f2));
102: f2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f,
103: Color.white, 3.0f, 4.0f, Color.yellow));
104: assertTrue(f1.equals(f2));
105:
106: // foregroundPaint
107: f1.setForegroundPaint(new GradientPaint(1.0f, 2.0f, Color.blue,
108: 3.0f, 4.0f, Color.green));
109: assertFalse(f1.equals(f2));
110: f2.setForegroundPaint(new GradientPaint(1.0f, 2.0f, Color.blue,
111: 3.0f, 4.0f, Color.green));
112: assertTrue(f1.equals(f2));
113:
114: // stroke
115: f1.setStroke(new BasicStroke(2.4f));
116: assertFalse(f1.equals(f2));
117: f2.setStroke(new BasicStroke(2.4f));
118: assertTrue(f1.equals(f2));
119: }
120:
121: /**
122: * Two objects that are equal are required to return the same hashCode.
123: */
124: public void testHashCode() {
125: SimpleDialFrame f1 = new SimpleDialFrame();
126: SimpleDialFrame f2 = new SimpleDialFrame();
127: assertTrue(f1.equals(f2));
128: int h1 = f1.hashCode();
129: int h2 = f2.hashCode();
130: assertEquals(h1, h2);
131: }
132:
133: /**
134: * Confirm that cloning works.
135: */
136: public void testCloning() {
137: SimpleDialFrame f1 = new SimpleDialFrame();
138: SimpleDialFrame f2 = null;
139: try {
140: f2 = (SimpleDialFrame) f1.clone();
141: } catch (CloneNotSupportedException e) {
142: e.printStackTrace();
143: }
144: assertTrue(f1 != f2);
145: assertTrue(f1.getClass() == f2.getClass());
146: assertTrue(f1.equals(f2));
147: }
148:
149: /**
150: * Serialize an instance, restore it, and check for equality.
151: */
152: public void testSerialization() {
153: SimpleDialFrame f1 = new SimpleDialFrame();
154: SimpleDialFrame f2 = null;
155:
156: try {
157: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
158: ObjectOutput out = new ObjectOutputStream(buffer);
159: out.writeObject(f1);
160: out.close();
161:
162: ObjectInput in = new ObjectInputStream(
163: new ByteArrayInputStream(buffer.toByteArray()));
164: f2 = (SimpleDialFrame) in.readObject();
165: in.close();
166: } catch (Exception e) {
167: e.printStackTrace();
168: }
169: assertEquals(f1, f2);
170: }
171:
172: }
|