KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CustomXYToolTipGeneratorTests.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: CustomXYItemLabelGeneratorTests.java,v 1.1.2.1 2006/10/03 15:41:37 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 23-Mar-2003 : Version 1 (DG);
40  * 13-Aug-2003 : Added cloning tests (DG);
41  *
42  */

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

63 public class CustomXYItemLabelGeneratorTests 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(CustomXYItemLabelGeneratorTests.class);
72     }
73
74     /**
75      * Constructs a new set of tests.
76      *
77      * @param name the name of the tests.
78      */

79     public CustomXYItemLabelGeneratorTests(String JavaDoc name) {
80         super(name);
81     }
82
83     /**
84      * Confirm that cloning works.
85      */

86     public void testCloning() {
87         CustomXYToolTipGenerator g1 = new CustomXYToolTipGenerator();
88         CustomXYToolTipGenerator g2 = null;
89         try {
90             g2 = (CustomXYToolTipGenerator) g1.clone();
91         }
92         catch (CloneNotSupportedException JavaDoc e) {
93             System.err.println("Failed to clone.");
94         }
95         assertTrue(g1 != g2);
96         assertTrue(g1.getClass() == g2.getClass());
97         assertTrue(g1.equals(g2));
98     }
99
100     /**
101      * Serialize an instance, restore it, and check for equality.
102      */

103     public void testSerialization() {
104
105         List JavaDoc t1 = new java.util.ArrayList JavaDoc();
106         t1.add("Tooltip A1");
107         t1.add("Tooltip A2");
108         t1.add("Tooltip A3");
109
110         List JavaDoc t2 = new java.util.ArrayList JavaDoc();
111         t2.add("Tooltip B1");
112         t2.add("Tooltip B2");
113         t2.add("Tooltip B3");
114
115         CustomXYToolTipGenerator g1 = new CustomXYToolTipGenerator();
116         g1.addToolTipSeries(t1);
117         g1.addToolTipSeries(t2);
118         CustomXYToolTipGenerator g2 = null;
119
120         try {
121             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
122             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
123             out.writeObject(g1);
124             out.close();
125
126             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
127                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
128             );
129             g2 = (CustomXYToolTipGenerator) in.readObject();
130             in.close();
131         }
132         catch (Exception JavaDoc e) {
133             System.out.println(e.toString());
134         }
135         assertEquals(g1, g2);
136
137     }
138
139 }
140
Popular Tags