KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, 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 License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * ------------------------------------
27  * StandardXYToolTipGeneratorTests.java
28  * ------------------------------------
29  * (C) Copyright 2004, by Object Refinery Limited and Contributors.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: StandardXYToolTipGeneratorTests.java,v 1.2 2005/02/09 14:23:48 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 11-May-2004 : Version 1 (DG);
39  *
40  */

41
42 package org.jfree.chart.labels.junit;
43
44 import java.io.ByteArrayInputStream JavaDoc;
45 import java.io.ByteArrayOutputStream JavaDoc;
46 import java.io.ObjectInput JavaDoc;
47 import java.io.ObjectInputStream JavaDoc;
48 import java.io.ObjectOutput JavaDoc;
49 import java.io.ObjectOutputStream JavaDoc;
50 import java.text.DateFormat JavaDoc;
51 import java.text.DecimalFormat JavaDoc;
52 import java.text.NumberFormat JavaDoc;
53 import java.text.SimpleDateFormat JavaDoc;
54
55 import junit.framework.Test;
56 import junit.framework.TestCase;
57 import junit.framework.TestSuite;
58
59 import org.jfree.chart.labels.StandardXYToolTipGenerator;
60
61 /**
62  * Tests for the {@link StandardXYToolTipGenerator} class.
63  */

64 public class StandardXYToolTipGeneratorTests extends TestCase {
65
66     /**
67      * Returns the tests as a test suite.
68      *
69      * @return The test suite.
70      */

71     public static Test suite() {
72         return new TestSuite(StandardXYToolTipGeneratorTests.class);
73     }
74
75     /**
76      * Constructs a new set of tests.
77      *
78      * @param name the name of the tests.
79      */

80     public StandardXYToolTipGeneratorTests(String JavaDoc name) {
81         super(name);
82     }
83     
84     /**
85      * Tests the equals() method.
86      */

87     public void testEquals() {
88         
89         // some setup...
90
String JavaDoc f1 = "{1}";
91         String JavaDoc f2 = "{2}";
92         NumberFormat JavaDoc xnf1 = new DecimalFormat JavaDoc("0.00");
93         NumberFormat JavaDoc xnf2 = new DecimalFormat JavaDoc("0.000");
94         NumberFormat JavaDoc ynf1 = new DecimalFormat JavaDoc("0.00");
95         NumberFormat JavaDoc ynf2 = new DecimalFormat JavaDoc("0.000");
96
97         StandardXYToolTipGenerator g1 = null;
98         StandardXYToolTipGenerator g2 = null;
99         
100         g1 = new StandardXYToolTipGenerator(f1, xnf1, ynf1);
101         g2 = new StandardXYToolTipGenerator(f1, xnf1, ynf1);
102         assertTrue(g1.equals(g2));
103         assertTrue(g2.equals(g1));
104         
105         g1 = new StandardXYToolTipGenerator(f2, xnf1, ynf1);
106         assertFalse(g1.equals(g2));
107         g2 = new StandardXYToolTipGenerator(f2, xnf1, ynf1);
108         assertTrue(g1.equals(g2));
109                 
110         g1 = new StandardXYToolTipGenerator(f2, xnf2, ynf1);
111         assertFalse(g1.equals(g2));
112         g2 = new StandardXYToolTipGenerator(f2, xnf2, ynf1);
113         assertTrue(g1.equals(g2));
114
115         g1 = new StandardXYToolTipGenerator(f2, xnf2, ynf2);
116         assertFalse(g1.equals(g2));
117         g2 = new StandardXYToolTipGenerator(f2, xnf2, ynf2);
118         assertTrue(g1.equals(g2));
119                 
120         DateFormat JavaDoc xdf1 = new SimpleDateFormat JavaDoc("d-MMM");
121         DateFormat JavaDoc xdf2 = new SimpleDateFormat JavaDoc("d-MMM-yyyy");
122         DateFormat JavaDoc ydf1 = new SimpleDateFormat JavaDoc("d-MMM");
123         DateFormat JavaDoc ydf2 = new SimpleDateFormat JavaDoc("d-MMM-yyyy");
124
125         g1 = new StandardXYToolTipGenerator(f1, xdf1, ydf1);
126         g2 = new StandardXYToolTipGenerator(f1, xdf1, ydf1);
127         assertTrue(g1.equals(g2));
128         assertTrue(g2.equals(g1));
129         
130         g1 = new StandardXYToolTipGenerator(f1, xdf2, ydf1);
131         assertFalse(g1.equals(g2));
132         g2 = new StandardXYToolTipGenerator(f1, xdf2, ydf1);
133         assertTrue(g1.equals(g2));
134                 
135         g1 = new StandardXYToolTipGenerator(f1, xdf2, ydf2);
136         assertFalse(g1.equals(g2));
137         g2 = new StandardXYToolTipGenerator(f1, xdf2, ydf2);
138         assertTrue(g1.equals(g2));
139
140     }
141
142     /**
143      * Confirm that cloning works.
144      */

145     public void testCloning() {
146         StandardXYToolTipGenerator g1 = new StandardXYToolTipGenerator();
147         StandardXYToolTipGenerator g2 = null;
148         try {
149             g2 = (StandardXYToolTipGenerator) g1.clone();
150         }
151         catch (CloneNotSupportedException JavaDoc e) {
152             System.err.println("Failed to clone.");
153         }
154         assertTrue(g1 != g2);
155         assertTrue(g1.getClass() == g2.getClass());
156         assertTrue(g1.equals(g2));
157     }
158
159     /**
160      * Serialize an instance, restore it, and check for equality.
161      */

162     public void testSerialization() {
163
164         StandardXYToolTipGenerator g1 = new StandardXYToolTipGenerator();
165         StandardXYToolTipGenerator g2 = null;
166
167         try {
168             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
169             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
170             out.writeObject(g1);
171             out.close();
172
173             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
174                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
175             );
176             g2 = (StandardXYToolTipGenerator) in.readObject();
177             in.close();
178         }
179         catch (Exception JavaDoc e) {
180             System.out.println(e.toString());
181         }
182         assertEquals(g1, g2);
183
184     }
185
186 }
187
Popular Tags