KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > labels > junit > StandardPieToolTipGeneratorTests


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * -------------------------------------
28  * StandardPieToolTipGeneratorTests.java
29  * -------------------------------------
30  * (C) Copyright 2003-2006, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: StandardPieToolTipGeneratorTests.java,v 1.1.2.2 2006/10/06 12:29:37 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 18-Mar-2003 : Version 1 (DG);
40  * 13-Aug-2003 : Added clone tests (DG);
41  * 04-Mar-2004 : Added test for equals() method (DG);
42  * ------------- JFREECHART 1.0.0 ---------------------------------------------
43  * 03-May-2006 : Extended test for clone() method (DG);
44  * 03-May-2006 : Renamed StandardPieItemLabelGeneratorTests
45  * --> StandardPieToolTipGeneratorTests (DG);
46  *
47  */

48
49 package org.jfree.chart.labels.junit;
50
51 import java.io.ByteArrayInputStream JavaDoc;
52 import java.io.ByteArrayOutputStream JavaDoc;
53 import java.io.ObjectInput JavaDoc;
54 import java.io.ObjectInputStream JavaDoc;
55 import java.io.ObjectOutput JavaDoc;
56 import java.io.ObjectOutputStream JavaDoc;
57 import java.text.DecimalFormat JavaDoc;
58 import java.text.NumberFormat JavaDoc;
59
60 import junit.framework.Test;
61 import junit.framework.TestCase;
62 import junit.framework.TestSuite;
63
64 import org.jfree.chart.labels.StandardPieToolTipGenerator;
65
66 /**
67  * Tests for the {@link StandardPieToolTipGenerator} class.
68  */

69 public class StandardPieToolTipGeneratorTests extends TestCase {
70
71     /**
72      * Returns the tests as a test suite.
73      *
74      * @return The test suite.
75      */

76     public static Test suite() {
77         return new TestSuite(StandardPieToolTipGeneratorTests.class);
78     }
79
80     /**
81      * Constructs a new set of tests.
82      *
83      * @param name the name of the tests.
84      */

85     public StandardPieToolTipGeneratorTests(String JavaDoc name) {
86         super(name);
87     }
88
89     /**
90      * Test that the equals() method distinguishes all fields.
91      */

92     public void testEquals() {
93         StandardPieToolTipGenerator g1 = new StandardPieToolTipGenerator();
94         StandardPieToolTipGenerator g2 = new StandardPieToolTipGenerator();
95         assertTrue(g1.equals(g2));
96         assertTrue(g2.equals(g1));
97         
98         g1 = new StandardPieToolTipGenerator("{0}",
99                 new DecimalFormat JavaDoc("#,##0.00"),
100                 NumberFormat.getPercentInstance());
101         assertFalse(g1.equals(g2));
102         g2 = new StandardPieToolTipGenerator("{0}",
103                 new DecimalFormat JavaDoc("#,##0.00"),
104                 NumberFormat.getPercentInstance());
105         assertTrue(g1.equals(g2));
106
107         g1 = new StandardPieToolTipGenerator("{0} {1}",
108                 new DecimalFormat JavaDoc("#,##0.00"),
109                 NumberFormat.getPercentInstance());
110         assertFalse(g1.equals(g2));
111         g2 = new StandardPieToolTipGenerator("{0} {1}",
112                 new DecimalFormat JavaDoc("#,##0.00"),
113                 NumberFormat.getPercentInstance());
114         assertTrue(g1.equals(g2));
115     
116         g1 = new StandardPieToolTipGenerator("{0} {1}",
117                 new DecimalFormat JavaDoc("#,##0"), NumberFormat.getPercentInstance());
118         assertFalse(g1.equals(g2));
119         g2 = new StandardPieToolTipGenerator("{0} {1}",
120                 new DecimalFormat JavaDoc("#,##0"), NumberFormat.getPercentInstance());
121         assertTrue(g1.equals(g2));
122
123         g1 = new StandardPieToolTipGenerator("{0} {1}",
124                 new DecimalFormat JavaDoc("#,##0"), new DecimalFormat JavaDoc("0.000%"));
125         assertFalse(g1.equals(g2));
126         g2 = new StandardPieToolTipGenerator("{0} {1}",
127                 new DecimalFormat JavaDoc("#,##0"), new DecimalFormat JavaDoc("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         }
140         catch (CloneNotSupportedException JavaDoc e) {
141             System.err.println("Failed to clone.");
142         }
143         assertTrue(g1 != g2);
144         assertTrue(g1.getClass() == g2.getClass());
145         assertTrue(g1.equals(g2));
146         assertTrue(g1.getNumberFormat() != g2.getNumberFormat());
147         assertTrue(g1.getPercentFormat() != g2.getPercentFormat());
148     }
149
150     /**
151      * Serialize an instance, restore it, and check for equality.
152      */

153     public void testSerialization() {
154
155         StandardPieToolTipGenerator g1 = new StandardPieToolTipGenerator();
156         StandardPieToolTipGenerator g2 = null;
157
158         try {
159             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
160             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
161             out.writeObject(g1);
162             out.close();
163
164             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
165                     new ByteArrayInputStream JavaDoc(buffer.toByteArray()));
166             g2 = (StandardPieToolTipGenerator) in.readObject();
167             in.close();
168         }
169         catch (Exception JavaDoc e) {
170             e.printStackTrace();
171         }
172         assertEquals(g1, g2);
173
174     }
175
176 }
177
Popular Tags