KickJava   Java API By Example, From Geeks To Geeks.

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


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  * TimeSeriesToolTipGeneratorTests.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: TimeSeriesToolTipGeneratorTests.java,v 1.2 2003/08/15 11:54:09 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 23-Mar-2003 : Version 1 (DG);
35  *
36  */

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

60 public class TimeSeriesToolTipGeneratorTests 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(TimeSeriesToolTipGeneratorTests.class);
69     }
70
71     /**
72      * Constructs a new set of tests.
73      *
74      * @param name the name of the tests.
75      */

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

83     public void testCloning() {
84         TimeSeriesToolTipGenerator g1 = new TimeSeriesToolTipGenerator();
85         TimeSeriesToolTipGenerator g2 = null;
86         try {
87             g2 = (TimeSeriesToolTipGenerator) g1.clone();
88         }
89         catch (CloneNotSupportedException JavaDoc e) {
90             System.err.println("TimeSeriesToolTipGeneratorTests.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         TimeSeriesToolTipGenerator g1 = new TimeSeriesToolTipGenerator(DateFormat.getInstance(),
103                                                                        NumberFormat.getInstance());
104         TimeSeriesToolTipGenerator g2 = null;
105
106         try {
107             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
108             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
109             out.writeObject(g1);
110             out.close();
111
112             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(new ByteArrayInputStream JavaDoc(buffer.toByteArray()));
113             g2 = (TimeSeriesToolTipGenerator) in.readObject();
114             in.close();
115         }
116         catch (Exception JavaDoc e) {
117             System.out.println(e.toString());
118         }
119         assertEquals(g1, g2);
120
121     }
122
123 }
124
Popular Tags