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: * BoxAndWhiskerXYToolTipGeneratorTests.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: BoxAndWhiskerXYToolTipGeneratorTests.java,v 1.1.2.1 2006/10/03 15:41:37 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 13-Aug-2003 : Version 1 (DG);
040: * 27-Feb-2004 : Renamed BoxAndWhiskerItemLabelGenerator
041: * --> XYBoxAndWhiskerItemLabelGenerator (DG);
042: *
043: */
044:
045: package org.jfree.chart.labels.junit;
046:
047: import java.io.ByteArrayInputStream;
048: import java.io.ByteArrayOutputStream;
049: import java.io.ObjectInput;
050: import java.io.ObjectInputStream;
051: import java.io.ObjectOutput;
052: import java.io.ObjectOutputStream;
053: import java.text.DecimalFormat;
054: import java.text.SimpleDateFormat;
055:
056: import junit.framework.Test;
057: import junit.framework.TestCase;
058: import junit.framework.TestSuite;
059:
060: import org.jfree.chart.labels.BoxAndWhiskerXYToolTipGenerator;
061:
062: /**
063: * Tests for the {@link BoxAndWhiskerXYToolTipGenerator} class.
064: */
065: public class BoxAndWhiskerXYToolTipGeneratorTests extends TestCase {
066:
067: /**
068: * Returns the tests as a test suite.
069: *
070: * @return The test suite.
071: */
072: public static Test suite() {
073: return new TestSuite(BoxAndWhiskerXYToolTipGeneratorTests.class);
074: }
075:
076: /**
077: * Constructs a new set of tests.
078: *
079: * @param name the name of the tests.
080: */
081: public BoxAndWhiskerXYToolTipGeneratorTests(String name) {
082: super (name);
083: }
084:
085: /**
086: * A series of tests for the equals() method.
087: */
088: public void testEquals() {
089:
090: // standard test
091: BoxAndWhiskerXYToolTipGenerator g1 = new BoxAndWhiskerXYToolTipGenerator();
092: BoxAndWhiskerXYToolTipGenerator g2 = new BoxAndWhiskerXYToolTipGenerator();
093: assertTrue(g1.equals(g2));
094: assertTrue(g2.equals(g1));
095:
096: // tooltip format
097: g1 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}",
098: new SimpleDateFormat("yyyy"), new DecimalFormat("0.0"));
099: g2 = new BoxAndWhiskerXYToolTipGenerator("{1} {2}",
100: new SimpleDateFormat("yyyy"), new DecimalFormat("0.0"));
101: assertFalse(g1.equals(g2));
102: g2 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}",
103: new SimpleDateFormat("yyyy"), new DecimalFormat("0.0"));
104: assertTrue(g1.equals(g2));
105:
106: // date format
107: g1 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}",
108: new SimpleDateFormat("yyyy"), new DecimalFormat("0.0"));
109: g2 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}",
110: new SimpleDateFormat("MMM-yyyy"), new DecimalFormat(
111: "0.0"));
112: assertFalse(g1.equals(g2));
113: g2 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}",
114: new SimpleDateFormat("yyyy"), new DecimalFormat("0.0"));
115: assertTrue(g1.equals(g2));
116:
117: // Y format
118: g1 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}",
119: new SimpleDateFormat("yyyy"), new DecimalFormat("0.0"));
120: g2 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}",
121: new SimpleDateFormat("yyyy"), new DecimalFormat("0.00"));
122: assertFalse(g1.equals(g2));
123: g2 = new BoxAndWhiskerXYToolTipGenerator("{0} --> {1} {2}",
124: new SimpleDateFormat("yyyy"), new DecimalFormat("0.0"));
125: assertTrue(g1.equals(g2));
126: }
127:
128: /**
129: * Confirm that cloning works.
130: */
131: public void testCloning() {
132: BoxAndWhiskerXYToolTipGenerator g1 = new BoxAndWhiskerXYToolTipGenerator();
133: BoxAndWhiskerXYToolTipGenerator g2 = null;
134: try {
135: g2 = (BoxAndWhiskerXYToolTipGenerator) g1.clone();
136: } catch (CloneNotSupportedException e) {
137: System.err.println("Failed to clone.");
138: }
139: assertTrue(g1 != g2);
140: assertTrue(g1.getClass() == g2.getClass());
141: assertTrue(g1.equals(g2));
142: }
143:
144: /**
145: * Serialize an instance, restore it, and check for equality.
146: */
147: public void testSerialization() {
148:
149: BoxAndWhiskerXYToolTipGenerator g1 = new BoxAndWhiskerXYToolTipGenerator();
150: BoxAndWhiskerXYToolTipGenerator g2 = null;
151:
152: try {
153: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
154: ObjectOutput out = new ObjectOutputStream(buffer);
155: out.writeObject(g1);
156: out.close();
157:
158: ObjectInput in = new ObjectInputStream(
159: new ByteArrayInputStream(buffer.toByteArray()));
160: g2 = (BoxAndWhiskerXYToolTipGenerator) in.readObject();
161: in.close();
162: } catch (Exception e) {
163: System.out.println(e.toString());
164: }
165: assertEquals(g1, g2);
166:
167: }
168:
169: }
|