KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > data > time > junit > TimePeriodValuesCollectionTests


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  * TimePeriodValuesCollectionTests.java
29  * ------------------------------------
30  * (C) Copyright 2005, by Object Refinery Limited.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: TimePeriodValuesCollectionTests.java,v 1.1.2.1 2006/10/03 15:41:39 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 11-Mar-2005 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.data.time.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.time.Day;
57 import org.jfree.data.time.TimePeriodAnchor;
58 import org.jfree.data.time.TimePeriodValues;
59 import org.jfree.data.time.TimePeriodValuesCollection;
60
61 /**
62  * Some tests for the {@link TimePeriodValuesCollection} class.
63  */

64 public class TimePeriodValuesCollectionTests extends TestCase {
65
66     /**
67      * Returns the tests as a test suite.
68      *
69      * @return The test suite.
70      */

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

80     public TimePeriodValuesCollectionTests(String JavaDoc name) {
81         super(name);
82     }
83
84     /**
85      * Common test setup.
86      */

87     protected void setUp() {
88         // no setup
89
}
90
91     /**
92      * A test for bug report 1161340. I wasn't able to reproduce the problem
93      * with this test.
94      */

95     public void test1161340() {
96         TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();
97         TimePeriodValues v1 = new TimePeriodValues("V1");
98         v1.add(new Day(11, 3, 2005), 1.2);
99         v1.add(new Day(12, 3, 2005), 3.4);
100         dataset.addSeries(v1);
101         assertEquals(1, dataset.getSeriesCount());
102         dataset.removeSeries(v1);
103         assertEquals(0, dataset.getSeriesCount());
104         
105         TimePeriodValues v2 = new TimePeriodValues("V2");
106         v1.add(new Day(5, 3, 2005), 1.2);
107         v1.add(new Day(6, 3, 2005), 3.4);
108         dataset.addSeries(v2);
109         assertEquals(1, dataset.getSeriesCount());
110     }
111     
112     /**
113      * Tests the equals() method.
114      */

115     public void testEquals() {
116         
117         TimePeriodValuesCollection c1 = new TimePeriodValuesCollection();
118         TimePeriodValuesCollection c2 = new TimePeriodValuesCollection();
119         assertTrue(c1.equals(c2));
120         
121         c1.setDomainIsPointsInTime(!c1.getDomainIsPointsInTime());
122         assertFalse(c1.equals(c2));
123         c2.setDomainIsPointsInTime(c1.getDomainIsPointsInTime());
124         assertTrue(c1.equals(c2));
125         
126         c1.setXPosition(TimePeriodAnchor.END);
127         assertFalse(c1.equals(c2));
128         c2.setXPosition(TimePeriodAnchor.END);
129         assertTrue(c1.equals(c2));
130         
131         TimePeriodValues v1 = new TimePeriodValues("Test");
132         TimePeriodValues v2 = new TimePeriodValues("Test");
133         
134         c1.addSeries(v1);
135         assertFalse(c1.equals(c2));
136         c2.addSeries(v2);
137         assertTrue(c1.equals(c2));
138     }
139
140     /**
141      * Serialize an instance, restore it, and check for equality.
142      */

143     public void testSerialization() {
144
145         TimePeriodValuesCollection c1 = new TimePeriodValuesCollection();
146         TimePeriodValuesCollection c2 = null;
147
148         try {
149             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
150             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
151             out.writeObject(c1);
152             out.close();
153
154             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
155                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
156             );
157             c2 = (TimePeriodValuesCollection) in.readObject();
158             in.close();
159         }
160         catch (Exception JavaDoc e) {
161             System.out.println(e.toString());
162         }
163         assertEquals(c1, c2);
164
165     }
166
167 }
168
Popular Tags