KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * ----------------------------------
23  * CustomXYToolTipGeneratorTests.java
24  * ----------------------------------
25  * (C) Copyright 2003 by Object Refinery Limited and Contributors.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): -;
29  *
30  * $Id: CustomXYToolTipGeneratorTests.java,v 1.2 2003/08/15 11:54:09 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 23-Mar-2003 : Version 1 (DG);
35  * 13-Aug-2003 : Added cloning tests (DG);
36  *
37  */

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

60 public class CustomXYToolTipGeneratorTests extends TestCase {
61
62     /**
63      * Returns the tests as a test suite.
64      *
65      * @return the test suite.
66      */

67     public static Test suite() {
68         return new TestSuite(CustomXYToolTipGeneratorTests.class);
69     }
70
71     /**
72      * Constructs a new set of tests.
73      *
74      * @param name the name of the tests.
75      */

76     public CustomXYToolTipGeneratorTests(String JavaDoc name) {
77         super(name);
78     }
79
80     /**
81      * Confirm that cloning works.
82      */

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

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