KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > progress > ProgressHandleFactoryTest


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.api.progress;
21
22 import javax.swing.JComponent JavaDoc;
23 import javax.swing.JProgressBar JavaDoc;
24 import junit.framework.TestCase;
25 import org.netbeans.progress.spi.InternalHandle;
26 import org.openide.util.Cancellable;
27
28 /**
29  *
30  * @author Milos Kleint (mkleint@netbeans.org)
31  */

32 public class ProgressHandleFactoryTest extends TestCase {
33
34     public ProgressHandleFactoryTest(String JavaDoc testName) {
35         super(testName);
36     }
37
38     /**
39      * Test of createHandle method, of class org.netbeans.progress.api.ProgressHandleFactory.
40      */

41     public void testCreateHandle() {
42         
43         ProgressHandle handle = ProgressHandleFactory.createHandle("task 1");
44         InternalHandle internal = handle.getInternalHandle();
45         assertEquals("task 1", internal.getDisplayName());
46         assertFalse(internal.isAllowCancel());
47         assertFalse(internal.isCustomPlaced());
48         assertEquals(InternalHandle.STATE_INITIALIZED, internal.getState());
49         
50         handle = ProgressHandleFactory.createHandle("task 2", new TestCancel());
51         internal = handle.getInternalHandle();
52         assertEquals("task 2", internal.getDisplayName());
53         assertTrue(internal.isAllowCancel());
54         assertFalse(internal.isCustomPlaced());
55         assertEquals(InternalHandle.STATE_INITIALIZED, internal.getState());
56         
57     }
58
59     
60     public void testCustomComponentIsInitialized() {
61         ProgressHandle handle = ProgressHandleFactory.createHandle("task 1");
62         JComponent JavaDoc component = ProgressHandleFactory.createProgressComponent(handle);
63         
64         handle.start(15);
65         handle.progress(2);
66         try {
67             // need to sleep longer than is the cycle..
68
Thread.sleep(600);
69         } catch (Exception JavaDoc exc) {
70             
71         }
72         assertEquals(15, ((JProgressBar JavaDoc) component).getMaximum());
73         assertEquals(2, ((JProgressBar JavaDoc) component).getValue());
74         
75         handle = ProgressHandleFactory.createHandle("task 2");
76         component = ProgressHandleFactory.createProgressComponent(handle);
77         
78         handle.start(20);
79         try {
80             // need to sleep longer than is the cycle..
81
Thread.sleep(600);
82         } catch (Exception JavaDoc exc) {
83             
84         }
85         assertEquals(20, ((JProgressBar JavaDoc) component).getMaximum());
86         assertEquals(0, ((JProgressBar JavaDoc) component).getValue());
87         
88     }
89      
90      private static class TestCancel implements Cancellable {
91          public boolean cancel() {
92              return true;
93          }
94          
95    }
96    
97     
98 }
99
Popular Tags