1 19 20 package org.netbeans.api.progress.aggregate; 21 22 import junit.framework.TestCase; 23 import org.netbeans.progress.module.Controller; 24 import org.netbeans.progress.spi.ProgressUIWorker; 25 import org.netbeans.progress.spi.ProgressEvent; 26 27 31 public class AggregateProgressHandleTest extends TestCase { 32 33 public AggregateProgressHandleTest(String testName) { 34 super(testName); 35 } 36 37 protected void setUp() throws Exception { 38 Controller.defaultInstance = new Controller(new ProgressUIWorker() { 39 public void processProgressEvent(ProgressEvent event) { } 40 public void processSelectedProgressEvent(ProgressEvent event) { } 41 }); 42 } 43 44 public void testContributorShare() throws Exception { 45 ProgressContributor contrib1 = AggregateProgressFactory.createProgressContributor("1"); 46 ProgressContributor contrib2 = AggregateProgressFactory.createProgressContributor("2"); 47 AggregateProgressHandle handle = AggregateProgressFactory.createHandle("fact1", new ProgressContributor[] { contrib1, contrib2}, null, null); 48 assertEquals(AggregateProgressHandle.WORKUNITS /2, contrib1.getRemainingParentWorkUnits()); 49 assertEquals(AggregateProgressHandle.WORKUNITS /2, contrib2.getRemainingParentWorkUnits()); 50 51 ProgressContributor contrib3 = AggregateProgressFactory.createProgressContributor("3"); 52 handle.addContributor(contrib3); 53 assertEquals(AggregateProgressHandle.WORKUNITS /3, contrib1.getRemainingParentWorkUnits()); 54 assertEquals(AggregateProgressHandle.WORKUNITS /3, contrib2.getRemainingParentWorkUnits()); 55 assertEquals(AggregateProgressHandle.WORKUNITS /3 + 1, contrib3.getRemainingParentWorkUnits()); 57 } 58 59 public void testDynamicContributorShare() throws Exception { 60 ProgressContributor contrib1 = AggregateProgressFactory.createProgressContributor("1"); 61 AggregateProgressHandle handle = AggregateProgressFactory.createHandle("fact1", new ProgressContributor[] { contrib1}, null, null); 62 assertEquals(AggregateProgressHandle.WORKUNITS, contrib1.getRemainingParentWorkUnits()); 63 64 handle.start(); 65 contrib1.start(100); 66 contrib1.progress(50); 67 assertEquals(AggregateProgressHandle.WORKUNITS /2, contrib1.getRemainingParentWorkUnits()); 68 assertEquals(AggregateProgressHandle.WORKUNITS /2, handle.getCurrentProgress()); 69 70 ProgressContributor contrib2 = AggregateProgressFactory.createProgressContributor("2"); 71 handle.addContributor(contrib2); 72 assertEquals(AggregateProgressHandle.WORKUNITS /4, contrib2.getRemainingParentWorkUnits()); 73 contrib1.finish(); 74 assertEquals(AggregateProgressHandle.WORKUNITS /4 * 3, handle.getCurrentProgress()); 75 76 ProgressContributor contrib3 = AggregateProgressFactory.createProgressContributor("3"); 77 handle.addContributor(contrib3); 78 assertEquals(AggregateProgressHandle.WORKUNITS /8, contrib2.getRemainingParentWorkUnits()); 79 assertEquals(AggregateProgressHandle.WORKUNITS /8, contrib3.getRemainingParentWorkUnits()); 80 contrib3.start(100); 81 contrib3.finish(); 82 assertEquals((AggregateProgressHandle.WORKUNITS /4 * 3) + (AggregateProgressHandle.WORKUNITS /8), 83 handle.getCurrentProgress()); 84 85 86 } 87 88 } 89 | Popular Tags |