KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > model > UserTaskTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.usertasks.model;
21
22 import java.util.Date JavaDoc;
23 import junit.framework.Test;
24 import junit.framework.TestCase;
25 import junit.framework.TestSuite;
26 import org.netbeans.modules.tasklist.core.util.ObjectList;
27 import org.netbeans.modules.tasklist.usertasks.options.Settings;
28
29 /**
30  * Tests for o.n.m.t.u.UserTask
31  *
32  * @author tl
33  */

34 public class UserTaskTest extends TestCase {
35
36     public UserTaskTest(java.lang.String JavaDoc testName) {
37         super(testName);
38     }
39
40     public static Test suite() {
41         TestSuite suite = new TestSuite(UserTaskTest.class);
42         return suite;
43     }
44
45     public void testSplitDuration() {
46         Duration d = new Duration(19 * 8 * 60 + 60, 8, 5);
47         assertEquals(d.weeks, 3);
48         assertEquals(d.days, 4);
49         assertEquals(d.hours, 1);
50         assertEquals(d.minutes, 0);
51     }
52     
53     public void testHashCode() {
54         UserTaskList list = new UserTaskList();
55         UserTask a = new UserTask("A", list);
56         UserTask b = new UserTask("B", list);
57         assertTrue(a.hashCode() != b.hashCode());
58     }
59     
60     public void testGetSetStart() {
61         UserTaskList list = new UserTaskList();
62         UserTask a = new UserTask("A", list);
63         assertEquals(-1, a.getStart());
64         assertEquals(null, a.getStartDate());
65         
66         long d = System.currentTimeMillis();
67         a.setStart(d);
68         assertEquals(d, a.getStartDate().getTime());
69         
70         Date JavaDoc dd = new Date JavaDoc();
71         a.setStartDate(dd);
72         assertEquals(dd, a.getStartDate());
73         
74         a.setStartDate(null);
75         assertEquals(a.getStartDate(), null);
76     }
77     
78     public void testMoveUpDown() {
79         UserTaskList list = new UserTaskList();
80         UserTask a = new UserTask("A", list);
81         UserTask b = new UserTask("B", list);
82         
83         list.getSubtasks().add(a);
84         list.getSubtasks().add(b);
85
86         b.moveUp();
87         assertEquals(list.getSubtasks().getUserTask(0).getSummary(), "B");
88         b.moveDown();
89         assertEquals(list.getSubtasks().getUserTask(0).getSummary(), "A");
90     }
91     
92     public void testStartStop() throws InterruptedException JavaDoc {
93         UserTaskList list = new UserTaskList();
94         UserTask a = new UserTask("A", list);
95         list.getSubtasks().add(a);
96         
97         Settings.getDefault().setCollectWorkPeriods(true);
98         a.start();
99         Thread.sleep(65 * 1000);
100         a.stop();
101         
102         ObjectList wp = a.getWorkPeriods();
103         assertEquals(1, wp.size());
104         
105         UserTask.WorkPeriod w = (UserTask.WorkPeriod) wp.get(0);
106         assertEquals(1, w.getDuration());
107     }
108     
109     public void testStopIfSpentTimeComputed() {
110         UserTaskList list = new UserTaskList();
111         UserTask a = new UserTask("A", list);
112         list.getSubtasks().add(a);
113         
114         a.start();
115         
116         UserTask b = new UserTask("B", list);
117         a.setValuesComputed(true);
118         
119         assertFalse(a.isStarted());
120     }
121 }
122
Popular Tags