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: * StandardPieToolTipGeneratorTests.java
029: * -------------------------------------
030: * (C) Copyright 2003-2006, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: StandardPieToolTipGeneratorTests.java,v 1.1.2.2 2006/10/06 12:29:37 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 18-Mar-2003 : Version 1 (DG);
040: * 13-Aug-2003 : Added clone tests (DG);
041: * 04-Mar-2004 : Added test for equals() method (DG);
042: * ------------- JFREECHART 1.0.0 ---------------------------------------------
043: * 03-May-2006 : Extended test for clone() method (DG);
044: * 03-May-2006 : Renamed StandardPieItemLabelGeneratorTests
045: * --> StandardPieToolTipGeneratorTests (DG);
046: *
047: */
048:
049: package org.jfree.chart.labels.junit;
050:
051: import java.io.ByteArrayInputStream;
052: import java.io.ByteArrayOutputStream;
053: import java.io.ObjectInput;
054: import java.io.ObjectInputStream;
055: import java.io.ObjectOutput;
056: import java.io.ObjectOutputStream;
057: import java.text.DecimalFormat;
058: import java.text.NumberFormat;
059:
060: import junit.framework.Test;
061: import junit.framework.TestCase;
062: import junit.framework.TestSuite;
063:
064: import org.jfree.chart.labels.StandardPieToolTipGenerator;
065:
066: /**
067: * Tests for the {@link StandardPieToolTipGenerator} class.
068: */
069: public class StandardPieToolTipGeneratorTests extends TestCase {
070:
071: /**
072: * Returns the tests as a test suite.
073: *
074: * @return The test suite.
075: */
076: public static Test suite() {
077: return new TestSuite(StandardPieToolTipGeneratorTests.class);
078: }
079:
080: /**
081: * Constructs a new set of tests.
082: *
083: * @param name the name of the tests.
084: */
085: public StandardPieToolTipGeneratorTests(String name) {
086: super (name);
087: }
088:
089: /**
090: * Test that the equals() method distinguishes all fields.
091: */
092: public void testEquals() {
093: StandardPieToolTipGenerator g1 = new StandardPieToolTipGenerator();
094: StandardPieToolTipGenerator g2 = new StandardPieToolTipGenerator();
095: assertTrue(g1.equals(g2));
096: assertTrue(g2.equals(g1));
097:
098: g1 = new StandardPieToolTipGenerator("{0}", new DecimalFormat(
099: "#,##0.00"), NumberFormat.getPercentInstance());
100: assertFalse(g1.equals(g2));
101: g2 = new StandardPieToolTipGenerator("{0}", new DecimalFormat(
102: "#,##0.00"), NumberFormat.getPercentInstance());
103: assertTrue(g1.equals(g2));
104:
105: g1 = new StandardPieToolTipGenerator("{0} {1}",
106: new DecimalFormat("#,##0.00"), NumberFormat
107: .getPercentInstance());
108: assertFalse(g1.equals(g2));
109: g2 = new StandardPieToolTipGenerator("{0} {1}",
110: new DecimalFormat("#,##0.00"), NumberFormat
111: .getPercentInstance());
112: assertTrue(g1.equals(g2));
113:
114: g1 = new StandardPieToolTipGenerator("{0} {1}",
115: new DecimalFormat("#,##0"), NumberFormat
116: .getPercentInstance());
117: assertFalse(g1.equals(g2));
118: g2 = new StandardPieToolTipGenerator("{0} {1}",
119: new DecimalFormat("#,##0"), NumberFormat
120: .getPercentInstance());
121: assertTrue(g1.equals(g2));
122:
123: g1 = new StandardPieToolTipGenerator("{0} {1}",
124: new DecimalFormat("#,##0"), new DecimalFormat("0.000%"));
125: assertFalse(g1.equals(g2));
126: g2 = new StandardPieToolTipGenerator("{0} {1}",
127: new DecimalFormat("#,##0"), new DecimalFormat("0.000%"));
128: assertTrue(g1.equals(g2));
129: }
130:
131: /**
132: * Some checks for cloning.
133: */
134: public void testCloning() {
135: StandardPieToolTipGenerator g1 = new StandardPieToolTipGenerator();
136: StandardPieToolTipGenerator g2 = null;
137: try {
138: g2 = (StandardPieToolTipGenerator) g1.clone();
139: } catch (CloneNotSupportedException e) {
140: System.err.println("Failed to clone.");
141: }
142: assertTrue(g1 != g2);
143: assertTrue(g1.getClass() == g2.getClass());
144: assertTrue(g1.equals(g2));
145: assertTrue(g1.getNumberFormat() != g2.getNumberFormat());
146: assertTrue(g1.getPercentFormat() != g2.getPercentFormat());
147: }
148:
149: /**
150: * Serialize an instance, restore it, and check for equality.
151: */
152: public void testSerialization() {
153:
154: StandardPieToolTipGenerator g1 = new StandardPieToolTipGenerator();
155: StandardPieToolTipGenerator g2 = null;
156:
157: try {
158: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
159: ObjectOutput out = new ObjectOutputStream(buffer);
160: out.writeObject(g1);
161: out.close();
162:
163: ObjectInput in = new ObjectInputStream(
164: new ByteArrayInputStream(buffer.toByteArray()));
165: g2 = (StandardPieToolTipGenerator) in.readObject();
166: in.close();
167: } catch (Exception e) {
168: e.printStackTrace();
169: }
170: assertEquals(g1, g2);
171:
172: }
173:
174: }
|