1 19 20 package org.netbeans.api.progress; 21 22 import javax.swing.JComponent ; 23 import javax.swing.JProgressBar ; 24 import junit.framework.TestCase; 25 import org.netbeans.progress.spi.InternalHandle; 26 import org.openide.util.Cancellable; 27 28 32 public class ProgressHandleFactoryTest extends TestCase { 33 34 public ProgressHandleFactoryTest(String testName) { 35 super(testName); 36 } 37 38 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 component = ProgressHandleFactory.createProgressComponent(handle); 63 64 handle.start(15); 65 handle.progress(2); 66 try { 67 Thread.sleep(600); 69 } catch (Exception exc) { 70 71 } 72 assertEquals(15, ((JProgressBar ) component).getMaximum()); 73 assertEquals(2, ((JProgressBar ) component).getValue()); 74 75 handle = ProgressHandleFactory.createHandle("task 2"); 76 component = ProgressHandleFactory.createProgressComponent(handle); 77 78 handle.start(20); 79 try { 80 Thread.sleep(600); 82 } catch (Exception exc) { 83 84 } 85 assertEquals(20, ((JProgressBar ) component).getMaximum()); 86 assertEquals(0, ((JProgressBar ) 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 |