KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > data > xy > junit > XIntervalSeriesCollectionTests


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2006, 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  * XIntervalSeriesCollectionTests.java
29  * -----------------------------------
30  * (C) Copyright 2006, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: XIntervalSeriesCollectionTests.java,v 1.1.2.2 2006/10/21 05:11:04 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 20-Oct-2006 : Version 1 (DG);
40  *
41  */

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

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

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

78     public XIntervalSeriesCollectionTests(String JavaDoc name) {
79         super(name);
80     }
81
82     /**
83      * Confirm that the equals method can distinguish all the required fields.
84      */

85     public void testEquals() {
86         XIntervalSeriesCollection c1 = new XIntervalSeriesCollection();
87         XIntervalSeriesCollection c2 = new XIntervalSeriesCollection();
88         assertEquals(c1, c2);
89         
90         // add a series
91
XIntervalSeries s1 = new XIntervalSeries("Series");
92         s1.add(1.0, 1.1, 1.2, 1.3);
93         c1.addSeries(s1);
94         assertFalse(c1.equals(c2));
95         XIntervalSeries s2 = new XIntervalSeries("Series");
96         s2.add(1.0, 1.1, 1.2, 1.3);
97         c2.addSeries(s2);
98         assertTrue(c1.equals(c2));
99         
100         // add an empty series
101
c1.addSeries(new XIntervalSeries("Empty Series"));
102         assertFalse(c1.equals(c2));
103         c2.addSeries(new XIntervalSeries("Empty Series"));
104         assertTrue(c1.equals(c2));
105     }
106
107     /**
108      * Confirm that cloning works.
109      */

110     public void testCloning() {
111         XIntervalSeriesCollection c1 = new XIntervalSeriesCollection();
112         XIntervalSeries s1 = new XIntervalSeries("Series");
113         s1.add(1.0, 1.1, 1.2, 1.3);
114         XIntervalSeriesCollection c2 = null;
115         try {
116             c2 = (XIntervalSeriesCollection) c1.clone();
117         }
118         catch (CloneNotSupportedException JavaDoc e) {
119             e.printStackTrace();
120         }
121         assertTrue(c1 != c2);
122         assertTrue(c1.getClass() == c2.getClass());
123         assertTrue(c1.equals(c2));
124     }
125
126     /**
127      * Serialize an instance, restore it, and check for equality.
128      */

129     public void testSerialization() {
130         XIntervalSeriesCollection c1 = new XIntervalSeriesCollection();
131         XIntervalSeries s1 = new XIntervalSeries("Series");
132         s1.add(1.0, 1.1, 1.2, 1.3);
133         XIntervalSeriesCollection c2 = null;
134         
135         try {
136             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
137             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
138             out.writeObject(c1);
139             out.close();
140
141             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
142                     new ByteArrayInputStream JavaDoc(buffer.toByteArray()));
143             c2 = (XIntervalSeriesCollection) in.readObject();
144             in.close();
145         }
146         catch (Exception JavaDoc e) {
147             e.printStackTrace();
148         }
149         assertEquals(c1, c2);
150     }
151     
152     /**
153      * A test for bug report 1170825 (originally affected XYSeriesCollection,
154      * this test is just copied over).
155      */

156     public void test1170825() {
157         XIntervalSeries s1 = new XIntervalSeries("Series1");
158         XIntervalSeriesCollection dataset = new XIntervalSeriesCollection();
159         dataset.addSeries(s1);
160         try {
161             /* XYSeries s = */ dataset.getSeries(1);
162         }
163         catch (IllegalArgumentException JavaDoc e) {
164             // correct outcome
165
}
166         catch (IndexOutOfBoundsException JavaDoc e) {
167             assertTrue(false); // wrong outcome
168
}
169     }
170     
171 }
172
Popular Tags