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: * IntervalXYDelegateTests.java
029: * ----------------------------
030: * (C) Copyright 2005, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: IntervalXYDelegateTests.java,v 1.1.2.1 2006/10/03 15:41:38 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 21-Feb-2005 : Version 1 (DG);
040: * 06-Oct-2005 : Updated for testEquals() for method name change (DG);
041: *
042: */
043:
044: package org.jfree.data.xy.junit;
045:
046: import java.io.ByteArrayInputStream;
047: import java.io.ByteArrayOutputStream;
048: import java.io.ObjectInput;
049: import java.io.ObjectInputStream;
050: import java.io.ObjectOutput;
051: import java.io.ObjectOutputStream;
052:
053: import junit.framework.Test;
054: import junit.framework.TestCase;
055: import junit.framework.TestSuite;
056:
057: import org.jfree.data.xy.IntervalXYDelegate;
058: import org.jfree.data.xy.XYSeries;
059: import org.jfree.data.xy.XYSeriesCollection;
060:
061: /**
062: * Some checks for the {@link IntervalXYDelegate} class.
063: */
064: public class IntervalXYDelegateTests 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(IntervalXYDelegateTests.class);
073: }
074:
075: /**
076: * Constructs a new set of tests.
077: *
078: * @param name the name of the tests.
079: */
080: public IntervalXYDelegateTests(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: XYSeries s1 = new XYSeries("Series");
089: s1.add(1.2, 3.4);
090: XYSeriesCollection c1 = new XYSeriesCollection();
091: c1.addSeries(s1);
092: IntervalXYDelegate d1 = new IntervalXYDelegate(c1);
093:
094: XYSeries s2 = new XYSeries("Series");
095: XYSeriesCollection c2 = new XYSeriesCollection();
096: s2.add(1.2, 3.4);
097: c2.addSeries(s2);
098: IntervalXYDelegate d2 = new IntervalXYDelegate(c2);
099:
100: assertTrue(d1.equals(d2));
101: assertTrue(d2.equals(d1));
102:
103: d1.setAutoWidth(false);
104: assertFalse(d1.equals(d2));
105: d2.setAutoWidth(false);
106: assertTrue(d1.equals(d2));
107:
108: d1.setIntervalPositionFactor(0.123);
109: assertFalse(d1.equals(d2));
110: d2.setIntervalPositionFactor(0.123);
111: assertTrue(d1.equals(d2));
112:
113: d1.setFixedIntervalWidth(1.23);
114: assertFalse(d1.equals(d2));
115: d2.setFixedIntervalWidth(1.23);
116: assertTrue(d1.equals(d2));
117: }
118:
119: /**
120: * Confirm that cloning works.
121: */
122: public void testCloning() {
123: XYSeries s1 = new XYSeries("Series");
124: s1.add(1.2, 3.4);
125: XYSeriesCollection c1 = new XYSeriesCollection();
126: c1.addSeries(s1);
127: IntervalXYDelegate d1 = new IntervalXYDelegate(c1);
128:
129: IntervalXYDelegate d2 = null;
130: try {
131: d2 = (IntervalXYDelegate) d1.clone();
132: } catch (CloneNotSupportedException e) {
133: System.err.println("Failed to clone.");
134: }
135: assertTrue(d1 != d2);
136: assertTrue(d1.getClass() == d2.getClass());
137: assertTrue(d1.equals(d2));
138: }
139:
140: /**
141: * Serialize an instance, restore it, and check for equality.
142: */
143: public void testSerialization() {
144: XYSeries s1 = new XYSeries("Series");
145: s1.add(1.2, 3.4);
146: XYSeriesCollection c1 = new XYSeriesCollection();
147: c1.addSeries(s1);
148: IntervalXYDelegate d1 = new IntervalXYDelegate(c1);
149: IntervalXYDelegate d2 = null;
150: try {
151: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
152: ObjectOutput out = new ObjectOutputStream(buffer);
153: out.writeObject(d1);
154: out.close();
155:
156: ObjectInput in = new ObjectInputStream(
157: new ByteArrayInputStream(buffer.toByteArray()));
158: d2 = (IntervalXYDelegate) in.readObject();
159: in.close();
160: } catch (Exception e) {
161: System.out.println(e.toString());
162: }
163: assertEquals(d1, d2);
164:
165: }
166:
167: }
|