KickJava   Java API By Example, From Geeks To Geeks.

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


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
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  * BoxAndWhiskerXYToolTipGeneratorTests.java
29  * -----------------------------------------
30  * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: BoxAndWhiskerXYToolTipGeneratorTests.java,v 1.1.2.1 2006/10/03 15:41:37 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 13-Aug-2003 : Version 1 (DG);
40  * 27-Feb-2004 : Renamed BoxAndWhiskerItemLabelGenerator
41  * --> XYBoxAndWhiskerItemLabelGenerator (DG);
42  *
43  */

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

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

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

81     public BoxAndWhiskerXYToolTipGeneratorTests(String JavaDoc name) {
82         super(name);
83     }
84
85     /**
86      * A series of tests for the equals() method.
87      */

88     public void testEquals() {
89         
90         // standard test
91
BoxAndWhiskerXYToolTipGenerator g1
92             = new BoxAndWhiskerXYToolTipGenerator();
93         BoxAndWhiskerXYToolTipGenerator g2
94             = new BoxAndWhiskerXYToolTipGenerator();
95         assertTrue(g1.equals(g2));
96         assertTrue(g2.equals(g1));
97         
98         // tooltip format
99
g1 = new BoxAndWhiskerXYToolTipGenerator(
100             "{0} --> {1} {2}",
101             new SimpleDateFormat JavaDoc("yyyy"), new DecimalFormat JavaDoc("0.0")
102         );
103         g2 = new BoxAndWhiskerXYToolTipGenerator(
104             "{1} {2}", new SimpleDateFormat JavaDoc("yyyy"), new DecimalFormat JavaDoc("0.0")
105         );
106         assertFalse(g1.equals(g2));
107         g2 = new BoxAndWhiskerXYToolTipGenerator(
108             "{0} --> {1} {2}",
109             new SimpleDateFormat JavaDoc("yyyy"), new DecimalFormat JavaDoc("0.0")
110         );
111         assertTrue(g1.equals(g2));
112
113         // date format
114
g1 = new BoxAndWhiskerXYToolTipGenerator(
115             "{0} --> {1} {2}",
116             new SimpleDateFormat JavaDoc("yyyy"), new DecimalFormat JavaDoc("0.0")
117         );
118         g2 = new BoxAndWhiskerXYToolTipGenerator(
119             "{0} --> {1} {2}",
120             new SimpleDateFormat JavaDoc("MMM-yyyy"), new DecimalFormat JavaDoc("0.0")
121         );
122         assertFalse(g1.equals(g2));
123         g2 = new BoxAndWhiskerXYToolTipGenerator(
124             "{0} --> {1} {2}",
125             new SimpleDateFormat JavaDoc("yyyy"), new DecimalFormat JavaDoc("0.0")
126         );
127         assertTrue(g1.equals(g2));
128
129         // Y format
130
g1 = new BoxAndWhiskerXYToolTipGenerator(
131             "{0} --> {1} {2}",
132             new SimpleDateFormat JavaDoc("yyyy"), new DecimalFormat JavaDoc("0.0")
133         );
134         g2 = new BoxAndWhiskerXYToolTipGenerator(
135             "{0} --> {1} {2}",
136             new SimpleDateFormat JavaDoc("yyyy"), new DecimalFormat JavaDoc("0.00")
137         );
138         assertFalse(g1.equals(g2));
139         g2 = new BoxAndWhiskerXYToolTipGenerator(
140             "{0} --> {1} {2}",
141             new SimpleDateFormat JavaDoc("yyyy"), new DecimalFormat JavaDoc("0.0")
142         );
143         assertTrue(g1.equals(g2));
144     }
145
146     /**
147      * Confirm that cloning works.
148      */

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

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