KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > data > gantt > junit > TaskSeriesTests


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

42
43 package org.jfree.data.gantt.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 import java.util.Date JavaDoc;
52
53 import junit.framework.Test;
54 import junit.framework.TestCase;
55 import junit.framework.TestSuite;
56
57 import org.jfree.data.gantt.Task;
58 import org.jfree.data.gantt.TaskSeries;
59
60 /**
61  * Tests for the {@link TaskSeries} class.
62  */

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

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

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

86     public void testEquals() {
87         
88         TaskSeries s1 = new TaskSeries("S");
89         s1.add(new Task("T1", new Date JavaDoc(1), new Date JavaDoc(2)));
90         s1.add(new Task("T2", new Date JavaDoc(11), new Date JavaDoc(22)));
91         TaskSeries s2 = new TaskSeries("S");
92         s2.add(new Task("T1", new Date JavaDoc(1), new Date JavaDoc(2)));
93         s2.add(new Task("T2", new Date JavaDoc(11), new Date JavaDoc(22)));
94         assertTrue(s1.equals(s2));
95         assertTrue(s2.equals(s1));
96
97         s1.add(new Task("T3", new Date JavaDoc(22), new Date JavaDoc(33)));
98         assertFalse(s1.equals(s2));
99         s2.add(new Task("T3", new Date JavaDoc(22), new Date JavaDoc(33)));
100         assertTrue(s1.equals(s2));
101
102     }
103
104     /**
105      * Confirm that cloning works.
106      */

107     public void testCloning() {
108         TaskSeries s1 = new TaskSeries("S");
109         s1.add(new Task("T1", new Date JavaDoc(1), new Date JavaDoc(2)));
110         s1.add(new Task("T2", new Date JavaDoc(11), new Date JavaDoc(22)));
111         TaskSeries s2 = null;
112         try {
113             s2 = (TaskSeries) s1.clone();
114         }
115         catch (CloneNotSupportedException JavaDoc e) {
116             System.err.println("Failed to clone.");
117         }
118         assertTrue(s1 != s2);
119         assertTrue(s1.getClass() == s2.getClass());
120         assertTrue(s1.equals(s2));
121     }
122
123     /**
124      * Serialize an instance, restore it, and check for equality.
125      */

126     public void testSerialization() {
127
128         TaskSeries s1 = new TaskSeries("S");
129         s1.add(new Task("T1", new Date JavaDoc(1), new Date JavaDoc(2)));
130         s1.add(new Task("T2", new Date JavaDoc(11), new Date JavaDoc(22)));
131         TaskSeries s2 = null;
132
133         try {
134             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
135             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
136             out.writeObject(s1);
137             out.close();
138
139             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
140                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
141             );
142             s2 = (TaskSeries) in.readObject();
143             in.close();
144         }
145         catch (Exception JavaDoc e) {
146             System.out.println(e.toString());
147         }
148         assertEquals(s1, s2);
149
150     }
151     
152     /**
153      * Some checks for the getTask() method.
154      */

155     public void testGetTask() {
156         TaskSeries s1 = new TaskSeries("S");
157         s1.add(new Task("T1", new Date JavaDoc(1), new Date JavaDoc(2)));
158         s1.add(new Task("T2", new Date JavaDoc(11), new Date JavaDoc(22)));
159         Task t1 = s1.get("T1");
160         assertTrue(t1.equals(new Task("T1", new Date JavaDoc(1), new Date JavaDoc(2))));
161         Task t2 = s1.get("T2");
162         assertTrue(t2.equals(new Task("T2", new Date JavaDoc(11), new Date JavaDoc(22))));
163         Task t3 = s1.get("T3");
164         assertTrue(t3 == null);
165     }
166
167 }
168
Popular Tags