001: package org.jfree.experimental.chart.plot.dial.junit;
002:
003: import java.awt.BasicStroke;
004: import java.awt.Color;
005: import java.awt.GradientPaint;
006: import java.io.ByteArrayInputStream;
007: import java.io.ByteArrayOutputStream;
008: import java.io.ObjectInput;
009: import java.io.ObjectInputStream;
010: import java.io.ObjectOutput;
011: import java.io.ObjectOutputStream;
012:
013: import junit.framework.Test;
014: import junit.framework.TestCase;
015: import junit.framework.TestSuite;
016:
017: import org.jfree.experimental.chart.plot.dial.StandardDialFrame;
018:
019: /**
020: * Tests for the {@link StandardDialFrame} class.
021: */
022: public class StandardDialFrameTests extends TestCase {
023:
024: /**
025: * Returns the tests as a test suite.
026: *
027: * @return The test suite.
028: */
029: public static Test suite() {
030: return new TestSuite(StandardDialFrameTests.class);
031: }
032:
033: /**
034: * Constructs a new set of tests.
035: *
036: * @param name the name of the tests.
037: */
038: public StandardDialFrameTests(String name) {
039: super (name);
040: }
041:
042: /**
043: * Confirm that the equals method can distinguish all the required fields.
044: */
045: public void testEquals() {
046: StandardDialFrame f1 = new StandardDialFrame();
047: StandardDialFrame f2 = new StandardDialFrame();
048: assertTrue(f1.equals(f2));
049:
050: // background paint
051: f1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red,
052: 3.0f, 4.0f, Color.yellow));
053: assertFalse(f1.equals(f2));
054: f2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red,
055: 3.0f, 4.0f, Color.yellow));
056: assertTrue(f1.equals(f2));
057:
058: // foreground paint
059: f1.setForegroundPaint(new GradientPaint(1.0f, 2.0f, Color.red,
060: 3.0f, 4.0f, Color.yellow));
061: assertFalse(f1.equals(f2));
062: f2.setForegroundPaint(new GradientPaint(1.0f, 2.0f, Color.red,
063: 3.0f, 4.0f, Color.yellow));
064: assertTrue(f1.equals(f2));
065:
066: // stroke
067: f1.setStroke(new BasicStroke(1.1f));
068: assertFalse(f1.equals(f2));
069: f2.setStroke(new BasicStroke(1.1f));
070: assertTrue(f1.equals(f2));
071:
072: // inner radius
073: f1.setInnerRadius(0.11);
074: assertFalse(f1.equals(f2));
075: f2.setInnerRadius(0.11);
076: assertTrue(f1.equals(f2));
077:
078: // outer radius
079: f1.setOuterRadius(0.88);
080: assertFalse(f1.equals(f2));
081: f2.setOuterRadius(0.88);
082: assertTrue(f1.equals(f2));
083:
084: // startAngle
085: f1.setStartAngle(99);
086: assertFalse(f1.equals(f2));
087: f2.setStartAngle(99);
088: assertTrue(f1.equals(f2));
089:
090: // extent
091: f1.setExtent(33);
092: assertFalse(f1.equals(f2));
093: f2.setExtent(33);
094: assertTrue(f1.equals(f2));
095:
096: }
097:
098: /**
099: * Two objects that are equal are required to return the same hashCode.
100: */
101: public void testHashCode() {
102: StandardDialFrame f1 = new StandardDialFrame();
103: StandardDialFrame f2 = new StandardDialFrame();
104: assertTrue(f1.equals(f2));
105: int h1 = f1.hashCode();
106: int h2 = f2.hashCode();
107: assertEquals(h1, h2);
108: }
109:
110: /**
111: * Confirm that cloning works.
112: */
113: public void testCloning() {
114: StandardDialFrame f1 = new StandardDialFrame();
115: StandardDialFrame f2 = null;
116: try {
117: f2 = (StandardDialFrame) f1.clone();
118: } catch (CloneNotSupportedException e) {
119: e.printStackTrace();
120: }
121: assertTrue(f1 != f2);
122: assertTrue(f1.getClass() == f2.getClass());
123: assertTrue(f1.equals(f2));
124: }
125:
126: /**
127: * Serialize an instance, restore it, and check for equality.
128: */
129: public void testSerialization() {
130: StandardDialFrame f1 = new StandardDialFrame();
131: StandardDialFrame f2 = null;
132:
133: try {
134: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
135: ObjectOutput out = new ObjectOutputStream(buffer);
136: out.writeObject(f1);
137: out.close();
138:
139: ObjectInput in = new ObjectInputStream(
140: new ByteArrayInputStream(buffer.toByteArray()));
141: f2 = (StandardDialFrame) in.readObject();
142: in.close();
143: } catch (Exception e) {
144: e.printStackTrace();
145: }
146: assertEquals(f1, f2);
147: }
148:
149: }
|