KickJava   Java API By Example, From Geeks To Geeks.

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


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  * TaskSeriesCollectionTests.java
29  * ------------------------------
30  * (C) Copyright 2004-2006, by Object Refinery Limited.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: TaskSeriesCollectionTests.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  * 12-Jan-2005 : Added tests from TaskSeriesCollectionTests2.java (DG);
41  *
42  */

43
44 package org.jfree.data.gantt.junit;
45
46 import java.io.ByteArrayInputStream JavaDoc;
47 import java.io.ByteArrayOutputStream JavaDoc;
48 import java.io.ObjectInput JavaDoc;
49 import java.io.ObjectInputStream JavaDoc;
50 import java.io.ObjectOutput JavaDoc;
51 import java.io.ObjectOutputStream JavaDoc;
52 import java.util.Date JavaDoc;
53
54 import junit.framework.Test;
55 import junit.framework.TestCase;
56 import junit.framework.TestSuite;
57
58 import org.jfree.data.gantt.Task;
59 import org.jfree.data.gantt.TaskSeries;
60 import org.jfree.data.gantt.TaskSeriesCollection;
61 import org.jfree.data.time.SimpleTimePeriod;
62
63 /**
64  * Tests for the {@link TaskSeriesCollection} class.
65  */

66 public class TaskSeriesCollectionTests extends TestCase {
67
68     /**
69      * Returns the tests as a test suite.
70      *
71      * @return The test suite.
72      */

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

82     public TaskSeriesCollectionTests(String JavaDoc name) {
83         super(name);
84     }
85
86     /**
87      * Creates a sample collection for testing purposes.
88      *
89      * @return A sample collection.
90      */

91     private TaskSeriesCollection createCollection1() {
92         TaskSeriesCollection result = new TaskSeriesCollection();
93         TaskSeries s1 = new TaskSeries("S1");
94         s1.add(new Task("Task 1", new Date JavaDoc(1), new Date JavaDoc(2)));
95         s1.add(new Task("Task 2", new Date JavaDoc(3), new Date JavaDoc(4)));
96         result.add(s1);
97         TaskSeries s2 = new TaskSeries("S2");
98         s2.add(new Task("Task 3", new Date JavaDoc(5), new Date JavaDoc(6)));
99         result.add(s2);
100         return result;
101     }
102     
103     /**
104      * Creates a sample collection for testing purposes.
105      *
106      * @return A sample collection.
107      */

108     private TaskSeriesCollection createCollection2() {
109         TaskSeriesCollection result = new TaskSeriesCollection();
110         TaskSeries s1 = new TaskSeries("S1");
111         Task t1 = new Task("Task 1", new Date JavaDoc(10), new Date JavaDoc(20));
112         t1.addSubtask(new Task("Task 1A", new Date JavaDoc(10), new Date JavaDoc(15)));
113         t1.addSubtask(new Task("Task 1B", new Date JavaDoc(16), new Date JavaDoc(20)));
114         t1.setPercentComplete(0.10);
115         s1.add(t1);
116         Task t2 = new Task("Task 2", new Date JavaDoc(30), new Date JavaDoc(40));
117         t2.addSubtask(new Task("Task 2A", new Date JavaDoc(30), new Date JavaDoc(35)));
118         t2.addSubtask(new Task("Task 2B", new Date JavaDoc(36), new Date JavaDoc(40)));
119         t2.setPercentComplete(0.20);
120         s1.add(t2);
121         result.add(s1);
122         TaskSeries s2 = new TaskSeries("S2");
123         Task t3 = new Task("Task 3", new Date JavaDoc(50), new Date JavaDoc(60));
124         t3.addSubtask(new Task("Task 3A", new Date JavaDoc(50), new Date JavaDoc(55)));
125         t3.addSubtask(new Task("Task 3B", new Date JavaDoc(56), new Date JavaDoc(60)));
126         t3.setPercentComplete(0.30);
127         s2.add(t3);
128         result.add(s2);
129         return result;
130     }
131     
132     /**
133      * Creates a sample collection for testing purposes.
134      *
135      * @return A sample collection.
136      */

137     private TaskSeriesCollection createCollection3() {
138         
139         // define subtasks
140
Task sub1 = new Task("Sub1", new Date JavaDoc(11), new Date JavaDoc(111));
141         Task sub2 = new Task("Sub2", new Date JavaDoc(22), new Date JavaDoc(222));
142         Task sub3 = new Task("Sub3", new Date JavaDoc(33), new Date JavaDoc(333));
143         Task sub4 = new Task("Sub4", new Date JavaDoc(44), new Date JavaDoc(444));
144         Task sub5 = new Task("Sub5", new Date JavaDoc(55), new Date JavaDoc(555));
145         Task sub6 = new Task("Sub6", new Date JavaDoc(66), new Date JavaDoc(666));
146         sub1.setPercentComplete(0.111);
147         sub2.setPercentComplete(0.222);
148         sub3.setPercentComplete(0.333);
149         sub4.setPercentComplete(0.444);
150         sub5.setPercentComplete(0.555);
151         sub6.setPercentComplete(0.666);
152         
153         TaskSeries seriesA = new TaskSeries("Series A");
154         Task taskA1 = new Task("Task 1", new SimpleTimePeriod(new Date JavaDoc(100),
155                 new Date JavaDoc(200)));
156         taskA1.setPercentComplete(0.1);
157         taskA1.addSubtask(sub1);
158         Task taskA2 = new Task("Task 2", new SimpleTimePeriod(new Date JavaDoc(220),
159                 new Date JavaDoc(350)));
160         taskA2.setPercentComplete(0.2);
161         taskA2.addSubtask(sub2);
162         taskA2.addSubtask(sub3);
163         seriesA.add(taskA1);
164         seriesA.add(taskA2);
165          
166         TaskSeries seriesB = new TaskSeries("Series B");
167         // note that we don't define taskB1
168
Task taskB2 = new Task("Task 2", new SimpleTimePeriod(new Date JavaDoc(2220),
169                 new Date JavaDoc(3350)));
170         taskB2.setPercentComplete(0.3);
171         taskB2.addSubtask(sub4);
172         taskB2.addSubtask(sub5);
173         taskB2.addSubtask(sub6);
174         seriesB.add(taskB2);
175
176         TaskSeriesCollection tsc = new TaskSeriesCollection();
177         tsc.add(seriesA);
178         tsc.add(seriesB);
179         
180         return tsc;
181     }
182     
183     /**
184      * A test for the getSeriesCount() method.
185      */

186     public void testGetSeriesCount() {
187         TaskSeriesCollection c = createCollection1();
188         assertEquals(2, c.getSeriesCount());
189     }
190     
191     /**
192      * Some tests for the getSeriesKey() method.
193      */

194     public void testGetSeriesKey() {
195         TaskSeriesCollection c = createCollection1();
196         assertEquals("S1", c.getSeriesKey(0));
197         assertEquals("S2", c.getSeriesKey(1));
198     }
199     
200     /**
201      * A test for the getRowCount() method.
202      */

203     public void testGetRowCount() {
204         TaskSeriesCollection c = createCollection1();
205         assertEquals(2, c.getRowCount());
206     }
207     
208     /**
209      * Some tests for the getRowKey() method.
210      */

211     public void testGetRowKey() {
212         TaskSeriesCollection c = createCollection1();
213         assertEquals("S1", c.getRowKey(0));
214         assertEquals("S2", c.getRowKey(1));
215     }
216     
217     /**
218      * Some tests for the getRowIndex() method.
219      */

220     public void testGetRowIndex() {
221         TaskSeriesCollection c = createCollection1();
222         assertEquals(0, c.getRowIndex("S1"));
223         assertEquals(1, c.getRowIndex("S2"));
224     }
225     
226     /**
227      * Some tests for the getValue() method.
228      */

229     public void testGetValue() {
230         TaskSeriesCollection c = createCollection1();
231         assertEquals(new Long JavaDoc(1L), c.getValue("S1", "Task 1"));
232         assertEquals(new Long JavaDoc(3L), c.getValue("S1", "Task 2"));
233         assertEquals(new Long JavaDoc(5L), c.getValue("S2", "Task 3"));
234         
235         assertEquals(new Long JavaDoc(1L), c.getValue(0, 0));
236         assertEquals(new Long JavaDoc(3L), c.getValue(0, 1));
237         assertEquals(null, c.getValue(0, 2));
238         assertEquals(null, c.getValue(1, 0));
239         assertEquals(null, c.getValue(1, 1));
240         assertEquals(new Long JavaDoc(5L), c.getValue(1, 2));
241     }
242     
243     /**
244      * Some tests for the getStartValue() method.
245      */

246     public void testGetStartValue() {
247         TaskSeriesCollection c = createCollection1();
248         assertEquals(new Long JavaDoc(1L), c.getStartValue("S1", "Task 1"));
249         assertEquals(new Long JavaDoc(3L), c.getStartValue("S1", "Task 2"));
250         assertEquals(new Long JavaDoc(5L), c.getStartValue("S2", "Task 3"));
251         
252         assertEquals(new Long JavaDoc(1L), c.getStartValue(0, 0));
253         assertEquals(new Long JavaDoc(3L), c.getStartValue(0, 1));
254         assertEquals(null, c.getStartValue(0, 2));
255         assertEquals(null, c.getStartValue(1, 0));
256         assertEquals(null, c.getStartValue(1, 1));
257         assertEquals(new Long JavaDoc(5L), c.getStartValue(1, 2));
258         
259         // test collection 3, which doesn't define all tasks in all series
260
TaskSeriesCollection c3 = createCollection3();
261         assertEquals(new Long JavaDoc(100), c3.getStartValue(0, 0));
262         assertEquals(new Long JavaDoc(220), c3.getStartValue(0, 1));
263         assertTrue(c3.getStartValue(1, 0) == null);
264         assertEquals(new Long JavaDoc(2220), c3.getStartValue(1, 1));
265     }
266     
267     /**
268      * Some tests for the getStartValue() method for sub-intervals.
269      */

270     public void testGetStartValue2() {
271         TaskSeriesCollection c = createCollection2();
272         assertEquals(new Long JavaDoc(10L), c.getStartValue("S1", "Task 1", 0));
273         assertEquals(new Long JavaDoc(16L), c.getStartValue("S1", "Task 1", 1));
274         assertEquals(new Long JavaDoc(30L), c.getStartValue("S1", "Task 2", 0));
275         assertEquals(new Long JavaDoc(36L), c.getStartValue("S1", "Task 2", 1));
276         assertEquals(new Long JavaDoc(50L), c.getStartValue("S2", "Task 3", 0));
277         assertEquals(new Long JavaDoc(56L), c.getStartValue("S2", "Task 3", 1));
278         
279         assertEquals(new Long JavaDoc(10L), c.getStartValue(0, 0, 0));
280         assertEquals(new Long JavaDoc(16L), c.getStartValue(0, 0, 1));
281         assertEquals(new Long JavaDoc(30L), c.getStartValue(0, 1, 0));
282         assertEquals(new Long JavaDoc(36L), c.getStartValue(0, 1, 1));
283         assertEquals(new Long JavaDoc(50L), c.getStartValue(1, 2, 0));
284         assertEquals(new Long JavaDoc(56L), c.getStartValue(1, 2, 1));
285
286         TaskSeriesCollection c3 = createCollection3();
287         assertEquals(new Long JavaDoc(11), c3.getStartValue(0, 0, 0));
288         assertEquals(new Long JavaDoc(22), c3.getStartValue(0, 1, 0));
289         assertEquals(new Long JavaDoc(33), c3.getStartValue(0, 1, 1));
290         assertTrue(c3.getStartValue(1, 0, 0) == null);
291         assertEquals(new Long JavaDoc(44), c3.getStartValue(1, 1, 0));
292         assertEquals(new Long JavaDoc(55), c3.getStartValue(1, 1, 1));
293         assertEquals(new Long JavaDoc(66), c3.getStartValue(1, 1, 2));
294     }
295     
296     /**
297      * A check for a null task duration.
298      */

299     public void testGetStartValue3() {
300         TaskSeriesCollection c = new TaskSeriesCollection();
301         TaskSeries s = new TaskSeries("Series 1");
302         s.add(new Task("Task with null duration", null));
303         c.add(s);
304         Number JavaDoc millis = c.getStartValue("Series 1", "Task with null duration");
305         assertTrue(millis == null);
306     }
307     
308     /**
309      * Some tests for the getEndValue() method.
310      */

311     public void testGetEndValue() {
312         TaskSeriesCollection c = createCollection1();
313         assertEquals(new Long JavaDoc(2L), c.getEndValue("S1", "Task 1"));
314         assertEquals(new Long JavaDoc(4L), c.getEndValue("S1", "Task 2"));
315         assertEquals(new Long JavaDoc(6L), c.getEndValue("S2", "Task 3"));
316         
317         assertEquals(new Long JavaDoc(2L), c.getEndValue(0, 0));
318         assertEquals(new Long JavaDoc(4L), c.getEndValue(0, 1));
319         assertEquals(null, c.getEndValue(0, 2));
320         assertEquals(null, c.getEndValue(1, 0));
321         assertEquals(null, c.getEndValue(1, 1));
322         assertEquals(new Long JavaDoc(6L), c.getEndValue(1, 2));
323         
324         // test collection 3, which doesn't define all tasks in all series
325
TaskSeriesCollection c3 = createCollection3();
326         assertEquals(new Long JavaDoc(200), c3.getEndValue(0, 0));
327         assertEquals(new Long JavaDoc(350), c3.getEndValue(0, 1));
328         assertTrue(c3.getEndValue(1, 0) == null);
329         assertEquals(new Long JavaDoc(3350), c3.getEndValue(1, 1));
330     }
331     
332     /**
333      * Some tests for the getEndValue() method for sub-intervals.
334      */

335     public void testGetEndValue2() {
336         TaskSeriesCollection c = createCollection2();
337         assertEquals(new Long JavaDoc(15L), c.getEndValue("S1", "Task 1", 0));
338         assertEquals(new Long JavaDoc(20L), c.getEndValue("S1", "Task 1", 1));
339         assertEquals(new Long JavaDoc(35L), c.getEndValue("S1", "Task 2", 0));
340         assertEquals(new Long JavaDoc(40L), c.getEndValue("S1", "Task 2", 1));
341         assertEquals(new Long JavaDoc(55L), c.getEndValue("S2", "Task 3", 0));
342         assertEquals(new Long JavaDoc(60L), c.getEndValue("S2", "Task 3", 1));
343         
344         assertEquals(new Long JavaDoc(15L), c.getEndValue(0, 0, 0));
345         assertEquals(new Long JavaDoc(20L), c.getEndValue(0, 0, 1));
346         assertEquals(new Long JavaDoc(35L), c.getEndValue(0, 1, 0));
347         assertEquals(new Long JavaDoc(40L), c.getEndValue(0, 1, 1));
348         assertEquals(new Long JavaDoc(55L), c.getEndValue(1, 2, 0));
349         assertEquals(new Long JavaDoc(60L), c.getEndValue(1, 2, 1));
350         
351         TaskSeriesCollection c3 = createCollection3();
352         assertEquals(new Long JavaDoc(111), c3.getEndValue(0, 0, 0));
353         assertEquals(new Long JavaDoc(222), c3.getEndValue(0, 1, 0));
354         assertEquals(new Long JavaDoc(333), c3.getEndValue(0, 1, 1));
355         assertTrue(c3.getEndValue(1, 0, 0) == null);
356         assertEquals(new Long JavaDoc(444), c3.getEndValue(1, 1, 0));
357         assertEquals(new Long JavaDoc(555), c3.getEndValue(1, 1, 1));
358         assertEquals(new Long JavaDoc(666), c3.getEndValue(1, 1, 2));
359     }
360     
361     /**
362      * A check for a null task duration.
363      */

364     public void testGetEndValue3() {
365         TaskSeriesCollection c = new TaskSeriesCollection();
366         TaskSeries s = new TaskSeries("Series 1");
367         s.add(new Task("Task with null duration", null));
368         c.add(s);
369         Number JavaDoc millis = c.getEndValue("Series 1", "Task with null duration");
370         assertTrue(millis == null);
371     }
372
373     /**
374      * Some tests for the getPercentComplete() method.
375      */

376     public void testGetPercentComplete() {
377         TaskSeriesCollection c = createCollection2();
378         assertEquals(new Double JavaDoc(0.10), c.getPercentComplete("S1", "Task 1"));
379         assertEquals(new Double JavaDoc(0.20), c.getPercentComplete("S1", "Task 2"));
380         assertEquals(new Double JavaDoc(0.30), c.getPercentComplete("S2", "Task 3"));
381         
382         assertEquals(new Double JavaDoc(0.10), c.getPercentComplete(0, 0));
383         assertEquals(new Double JavaDoc(0.20), c.getPercentComplete(0, 1));
384         assertEquals(null, c.getPercentComplete(0, 2));
385         assertEquals(null, c.getPercentComplete(1, 0));
386         assertEquals(null, c.getPercentComplete(1, 1));
387         assertEquals(new Double JavaDoc(0.30), c.getPercentComplete(1, 2));
388         
389         // test collection 3, which doesn't define all tasks in all series
390
TaskSeriesCollection c3 = createCollection3();
391         assertEquals(new Double JavaDoc(0.1), c3.getPercentComplete(0, 0));
392         assertEquals(new Double JavaDoc(0.2), c3.getPercentComplete(0, 1));
393         assertTrue(c3.getPercentComplete(1, 0) == null);
394         assertEquals(new Double JavaDoc(0.3), c3.getPercentComplete(1, 1));
395         
396         assertEquals(new Double JavaDoc(0.111), c3.getPercentComplete(0, 0, 0));
397  
398         assertEquals(new Double JavaDoc(0.222), c3.getPercentComplete(0, 1, 0));
399         assertEquals(new Double JavaDoc(0.333), c3.getPercentComplete(0, 1, 1));
400
401         assertEquals(new Double JavaDoc(0.444), c3.getPercentComplete(1, 1, 0));
402         assertEquals(new Double JavaDoc(0.555), c3.getPercentComplete(1, 1, 1));
403         assertEquals(new Double JavaDoc(0.666), c3.getPercentComplete(1, 1, 2));
404     }
405
406     /**
407      * A test for the getColumnCount() method.
408      */

409     public void testGetColumnCount() {
410         TaskSeriesCollection c = createCollection1();
411         assertEquals(3, c.getColumnCount());
412     }
413
414     /**
415      * Some tests for the getColumnKey() method.
416      */

417     public void testGetColumnKey() {
418         TaskSeriesCollection c = createCollection1();
419         assertEquals("Task 1", c.getColumnKey(0));
420         assertEquals("Task 2", c.getColumnKey(1));
421         assertEquals("Task 3", c.getColumnKey(2));
422     }
423     
424     /**
425      * Some tests for the getColumnIndex() method.
426      */

427     public void testGetColumnIndex() {
428         TaskSeriesCollection c = createCollection1();
429         assertEquals(0, c.getColumnIndex("Task 1"));
430         assertEquals(1, c.getColumnIndex("Task 2"));
431         assertEquals(2, c.getColumnIndex("Task 3"));
432     }
433     
434     /**
435      * Confirm that the equals method can distinguish all the required fields.
436      */

437     public void testEquals() {
438         
439         TaskSeries s1 = new TaskSeries("S");
440         s1.add(new Task("T1", new Date JavaDoc(1), new Date JavaDoc(2)));
441         s1.add(new Task("T2", new Date JavaDoc(11), new Date JavaDoc(22)));
442         TaskSeries s2 = new TaskSeries("S");
443         s2.add(new Task("T1", new Date JavaDoc(1), new Date JavaDoc(2)));
444         s2.add(new Task("T2", new Date JavaDoc(11), new Date JavaDoc(22)));
445         TaskSeriesCollection c1 = new TaskSeriesCollection();
446         c1.add(s1);
447         c1.add(s2);
448         
449         TaskSeries s1b = new TaskSeries("S");
450         s1b.add(new Task("T1", new Date JavaDoc(1), new Date JavaDoc(2)));
451         s1b.add(new Task("T2", new Date JavaDoc(11), new Date JavaDoc(22)));
452         TaskSeries s2b = new TaskSeries("S");
453         s2b.add(new Task("T1", new Date JavaDoc(1), new Date JavaDoc(2)));
454         s2b.add(new Task("T2", new Date JavaDoc(11), new Date JavaDoc(22)));
455         TaskSeriesCollection c2 = new TaskSeriesCollection();
456         c2.add(s1b);
457         c2.add(s2b);
458         
459         assertTrue(c1.equals(c2));
460         assertTrue(c2.equals(c1));
461
462     }
463
464     /**
465      * Confirm that cloning works.
466      */

467     public void testCloning() {
468         TaskSeries s1 = new TaskSeries("S");
469         s1.add(new Task("T1", new Date JavaDoc(1), new Date JavaDoc(2)));
470         s1.add(new Task("T2", new Date JavaDoc(11), new Date JavaDoc(22)));
471         TaskSeries s2 = new TaskSeries("S");
472         s2.add(new Task("T1", new Date JavaDoc(1), new Date JavaDoc(2)));
473         s2.add(new Task("T2", new Date JavaDoc(11), new Date JavaDoc(22)));
474         TaskSeriesCollection c1 = new TaskSeriesCollection();
475         c1.add(s1);
476         c1.add(s2);
477
478         TaskSeriesCollection c2 = null;
479         try {
480             c2 = (TaskSeriesCollection) c1.clone();
481         }
482         catch (CloneNotSupportedException JavaDoc e) {
483             System.err.println("Failed to clone.");
484         }
485         assertTrue(c1 != c2);
486         assertTrue(c1.getClass() == c2.getClass());
487         assertTrue(c1.equals(c2));
488     }
489
490     /**
491      * Serialize an instance, restore it, and check for equality.
492      */

493     public void testSerialization() {
494
495         TaskSeries s1 = new TaskSeries("S");
496         s1.add(new Task("T1", new Date JavaDoc(1), new Date JavaDoc(2)));
497         s1.add(new Task("T2", new Date JavaDoc(11), new Date JavaDoc(22)));
498         TaskSeries s2 = new TaskSeries("S");
499         s2.add(new Task("T1", new Date JavaDoc(1), new Date JavaDoc(2)));
500         s2.add(new Task("T2", new Date JavaDoc(11), new Date JavaDoc(22)));
501         TaskSeriesCollection c1 = new TaskSeriesCollection();
502         c1.add(s1);
503         c1.add(s2);
504         TaskSeriesCollection c2 = null;
505
506         try {
507             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
508             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
509             out.writeObject(c1);
510             out.close();
511
512             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(new ByteArrayInputStream JavaDoc(
513                     buffer.toByteArray()));
514             c2 = (TaskSeriesCollection) in.readObject();
515             in.close();
516         }
517         catch (Exception JavaDoc e) {
518             System.out.println(e.toString());
519         }
520         assertEquals(c1, c2);
521
522     }
523
524     /**
525      * A test for bug report 697153.
526      */

527     public void test697153() {
528
529         TaskSeries s1 = new TaskSeries("S1");
530         s1.add(new Task("Task 1", new SimpleTimePeriod(new Date JavaDoc(),
531                 new Date JavaDoc())));
532         s1.add(new Task("Task 2", new SimpleTimePeriod(new Date JavaDoc(),
533                 new Date JavaDoc())));
534         s1.add(new Task("Task 3", new SimpleTimePeriod(new Date JavaDoc(),
535                 new Date JavaDoc())));
536
537         TaskSeries s2 = new TaskSeries("S2");
538         s2.add(new Task("Task 2", new SimpleTimePeriod(new Date JavaDoc(),
539                 new Date JavaDoc())));
540         s2.add(new Task("Task 3", new SimpleTimePeriod(new Date JavaDoc(),
541                 new Date JavaDoc())));
542         s2.add(new Task("Task 4", new SimpleTimePeriod(new Date JavaDoc(),
543                 new Date JavaDoc())));
544
545         TaskSeriesCollection tsc = new TaskSeriesCollection();
546         tsc.add(s1);
547         tsc.add(s2);
548
549         s1.removeAll();
550
551         int taskCount = tsc.getColumnCount();
552
553         assertEquals(3, taskCount);
554
555     }
556
557     /**
558      * A test for bug report 800324.
559      */

560     public void test800324() {
561         TaskSeries s1 = new TaskSeries("S1");
562         s1.add(new Task("Task 1", new SimpleTimePeriod(new Date JavaDoc(),
563                 new Date JavaDoc())));
564         s1.add(new Task("Task 2", new SimpleTimePeriod(new Date JavaDoc(),
565                 new Date JavaDoc())));
566         s1.add(new Task("Task 3", new SimpleTimePeriod(new Date JavaDoc(),
567                 new Date JavaDoc())));
568                 
569         TaskSeriesCollection tsc = new TaskSeriesCollection();
570         tsc.add(s1);
571
572         // these methods should throw an IndexOutOfBoundsException since the
573
// column is too high...
574
try {
575             /* Number start = */ tsc.getStartValue(0, 3);
576             assertTrue(false);
577         }
578         catch (IndexOutOfBoundsException JavaDoc e) {
579             // expected
580
}
581         try {
582             /* Number end = */ tsc.getEndValue(0, 3);
583             assertTrue(false);
584         }
585         catch (IndexOutOfBoundsException JavaDoc e) {
586             // expected
587
}
588         try {
589             /* int count = */ tsc.getSubIntervalCount(0, 3);
590             assertTrue(false);
591         }
592         catch (IndexOutOfBoundsException JavaDoc e) {
593             // expected
594
}
595     }
596     
597     /**
598      * Some tests for the bug report 1099331. We create a TaskSeriesCollection
599      * with two series - the first series has two tasks, but the second has
600      * only one. The key is to ensure that the methods in TaskSeriesCollection
601      * translate the index values to key values *before* accessing the tasks
602      * in the series.
603      */

604     public void testGetSubIntervalCount() {
605         TaskSeriesCollection tsc = createCollection3();
606         assertEquals(1, tsc.getSubIntervalCount(0, 0));
607         assertEquals(2, tsc.getSubIntervalCount(0, 1));
608         assertEquals(0, tsc.getSubIntervalCount(1, 0));
609         assertEquals(3, tsc.getSubIntervalCount(1, 1));
610     }
611     
612     /**
613      * Some basic tests for the getSeries() methods.
614      */

615     public void testGetSeries() {
616         TaskSeries s1 = new TaskSeries("S1");
617         TaskSeries s2 = new TaskSeries("S2");
618         TaskSeriesCollection c = new TaskSeriesCollection();
619         c.add(s1);
620         
621         assertEquals(c.getSeries(0), s1);
622         assertEquals(c.getSeries("S1"), s1);
623         assertEquals(c.getSeries("XX"), null);
624         
625         c.add(s2);
626         assertEquals(c.getSeries(1), s2);
627         assertEquals(c.getSeries("S2"), s2);
628         
629         boolean pass = false;
630         try {
631             c.getSeries(null);
632         }
633         catch (NullPointerException JavaDoc e) {
634             pass = true;
635         }
636         assertTrue(pass);
637     }
638     
639 }
640
Popular Tags