KickJava   Java API By Example, From Geeks To Geeks.

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


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  * StandardCategoryToolTipGeneratorTests.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: StandardCategoryToolTipGeneratorTests.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.SimpleDateFormat JavaDoc;
53
54 import junit.framework.Test;
55 import junit.framework.TestCase;
56 import junit.framework.TestSuite;
57
58 import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
59
60 /**
61  * Tests for the {@link StandardCategoryToolTipGenerator} class.
62  */

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

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

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

86     public void testEquals() {
87         
88         StandardCategoryToolTipGenerator g1
89             = new StandardCategoryToolTipGenerator();
90         StandardCategoryToolTipGenerator g2
91             = new StandardCategoryToolTipGenerator();
92         assertTrue(g1.equals(g2));
93         assertTrue(g2.equals(g1));
94         
95         g1 = new StandardCategoryToolTipGenerator(
96             "{0}", new DecimalFormat JavaDoc("0.000")
97         );
98         assertFalse(g1.equals(g2));
99         g2 = new StandardCategoryToolTipGenerator(
100             "{0}", new DecimalFormat JavaDoc("0.000")
101         );
102         assertTrue(g1.equals(g2));
103
104         g1 = new StandardCategoryToolTipGenerator(
105             "{1}", new DecimalFormat JavaDoc("0.000")
106         );
107         assertFalse(g1.equals(g2));
108         g2 = new StandardCategoryToolTipGenerator(
109             "{1}", new DecimalFormat JavaDoc("0.000")
110         );
111         assertTrue(g1.equals(g2));
112
113         g1 = new StandardCategoryToolTipGenerator(
114             "{2}", new SimpleDateFormat JavaDoc("d-MMM")
115         );
116         assertFalse(g1.equals(g2));
117         g2 = new StandardCategoryToolTipGenerator(
118             "{2}", new SimpleDateFormat JavaDoc("d-MMM")
119         );
120         assertTrue(g1.equals(g2));
121         
122     }
123
124     /**
125      * Confirm that cloning works.
126      */

127     public void testCloning() {
128         StandardCategoryToolTipGenerator g1
129             = new StandardCategoryToolTipGenerator();
130         StandardCategoryToolTipGenerator g2 = null;
131         try {
132             g2 = (StandardCategoryToolTipGenerator) g1.clone();
133         }
134         catch (CloneNotSupportedException JavaDoc e) {
135             System.err.println("Failed to clone.");
136         }
137         assertTrue(g1 != g2);
138         assertTrue(g1.getClass() == g2.getClass());
139         assertTrue(g1.equals(g2));
140     }
141
142     /**
143      * Serialize an instance, restore it, and check for equality.
144      */

145     public void testSerialization() {
146
147         StandardCategoryToolTipGenerator g1
148             = new StandardCategoryToolTipGenerator(
149                 "{2}", DateFormat.getInstance()
150             );
151         StandardCategoryToolTipGenerator g2 = null;
152
153         try {
154             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
155             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
156             out.writeObject(g1);
157             out.close();
158
159             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
160                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
161             );
162             g2 = (StandardCategoryToolTipGenerator) in.readObject();
163             in.close();
164         }
165         catch (Exception JavaDoc e) {
166             System.out.println(e.toString());
167         }
168         assertEquals(g1, g2);
169
170     }
171
172 }
173
Popular Tags