KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > plot > junit > CompassPlotTests


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  * CompassPlotTests.java
28  * ---------------------
29  * (C) Copyright 2003, 2004, by Object Refinery Limited and Contributors.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: CompassPlotTests.java,v 1.3 2005/04/18 05:12:35 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 27-Mar-2003 : Version 1 (DG);
39  *
40  */

41
42 package org.jfree.chart.plot.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
51 import junit.framework.Test;
52 import junit.framework.TestCase;
53 import junit.framework.TestSuite;
54
55 import org.jfree.chart.plot.CompassPlot;
56 import org.jfree.data.general.DefaultValueDataset;
57
58 /**
59  * Tests for the {@link CompassPlot} class.
60  */

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

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

77     public CompassPlotTests(String JavaDoc name) {
78         super(name);
79     }
80
81     /**
82      * Test the equals() method.
83      */

84     public void testEquals() {
85         CompassPlot plot1 = new CompassPlot();
86         CompassPlot plot2 = new CompassPlot();
87         assertTrue(plot1.equals(plot2));
88         
89         // labelType...
90
plot1.setLabelType(CompassPlot.VALUE_LABELS);
91         assertFalse(plot1.equals(plot2));
92         plot2.setLabelType(CompassPlot.VALUE_LABELS);
93         assertTrue(plot1.equals(plot2));
94         
95     }
96     
97     /**
98      * Serialize an instance, restore it, and check for equality.
99      */

100     public void testSerialization() {
101
102         CompassPlot p1 = new CompassPlot(null);
103         CompassPlot p2 = null;
104
105         try {
106             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
107             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
108             out.writeObject(p1);
109             out.close();
110
111             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
112                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
113             );
114             p2 = (CompassPlot) in.readObject();
115             in.close();
116         }
117         catch (Exception JavaDoc e) {
118             System.out.println(e.toString());
119         }
120         assertEquals(p1, p2);
121
122     }
123     
124     /**
125      * Confirm that cloning works.
126      */

127     public void testCloning() {
128         CompassPlot p1 = new CompassPlot(new DefaultValueDataset(15.0));
129         CompassPlot p2 = null;
130         try {
131             p2 = (CompassPlot) p1.clone();
132         }
133         catch (CloneNotSupportedException JavaDoc e) {
134             e.printStackTrace();
135             System.err.println("Failed to clone.");
136         }
137         assertTrue(p1 != p2);
138         assertTrue(p1.getClass() == p2.getClass());
139         assertTrue(p1.equals(p2));
140     }
141
142 }
143
Popular Tags