Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/SubMonitorTest.java')
-rw-r--r--bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/SubMonitorTest.java555
1 files changed, 276 insertions, 279 deletions
diff --git a/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/SubMonitorTest.java b/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/SubMonitorTest.java
index d1da6453c..9e6a8bde0 100644
--- a/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/SubMonitorTest.java
+++ b/bundles/org.eclipse.equinox.common.tests/src/org/eclipse/equinox/common/tests/SubMonitorTest.java
@@ -18,63 +18,61 @@
*******************************************************************************/
package org.eclipse.equinox.common.tests;
-import java.util.*;
-import junit.framework.TestCase;
-import org.eclipse.core.runtime.*;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.SubMonitor;
import org.junit.Assert;
+import org.junit.Test;
-/**
- *
- */
-public class SubMonitorTest extends TestCase {
+public class SubMonitorTest {
- private long startTime;
/**
- * <p>Number of calls to worked() within each test. This was chosen to be significantly larger
- * than 1000 to test how well the monitor can optimize unnecessary resolution
- * in reported progress, but small enough that the test completes in a reasonable
- * amount of time.</p>
+ * <p>
+ * Number of calls to worked() within each test. This was chosen to be
+ * significantly larger than 1000 to test how well the monitor can optimize
+ * unnecessary resolution in reported progress, but small enough that the test
+ * completes in a reasonable amount of time.
+ * </p>
*
- * <p>Note: changing this constant will invalidate comparisons with old performance data.</p>
+ * <p>
+ * Note: changing this constant will invalidate comparisons with old performance
+ * data.
+ * </p>
*/
public static final int PROGRESS_SIZE = SubProgressTest.PROGRESS_SIZE;
/**
- * <p>Depth of the chain chain of progress monitors. In all of the tests, we create
+ * <p>
+ * Depth of the chain chain of progress monitors. In all of the tests, we create
* a nested chain of progress monitors rather than a single monitor, to test its
* scalability under recursion. We pick a number representing a moderately deep
- * recursion, but is still small enough that it could correspond to a real call stack
- * without causing overflow.</p>
+ * recursion, but is still small enough that it could correspond to a real call
+ * stack without causing overflow.
+ * </p>
*
- * <p>Note: changing this constant will invalidate comparisons with old performance data.</p>
+ * <p>
+ * Note: changing this constant will invalidate comparisons with old performance
+ * data.
+ * </p>
*/
public static final int CHAIN_DEPTH = SubProgressTest.CHAIN_DEPTH;
- public SubMonitorTest() {
- super();
- }
-
- public SubMonitorTest(String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- startTime = System.currentTimeMillis();
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- long endTime = System.currentTimeMillis();
- reportPerformance(getClass().getName(), getName(), startTime, endTime);
- super.tearDown();
- }
-
/**
- * Reports progress by iterating over a loop of the given size, reporting 1 progress
- * at each iteration. Simulates the progress of worked(int) in loops.
+ * Reports progress by iterating over a loop of the given size, reporting 1
+ * progress at each iteration. Simulates the progress of worked(int) in loops.
*
- * @param monitor progress monitor (callers are responsible for calling done() if necessary)
+ * @param monitor progress monitor (callers are responsible for calling done()
+ * if necessary)
* @param loopSize size of the loop
*/
private static void reportWorkInLoop(IProgressMonitor monitor, int loopSize) {
@@ -85,10 +83,12 @@ public class SubMonitorTest extends TestCase {
}
/**
- * Reports progress by iterating over a loop of the given size, reporting 1 progress
- * at each iteration. Simulates the progress of internalWorked(double) in loops.
+ * Reports progress by iterating over a loop of the given size, reporting 1
+ * progress at each iteration. Simulates the progress of internalWorked(double)
+ * in loops.
*
- * @param monitor progress monitor (callers are responsible for calling done() if necessary)
+ * @param monitor progress monitor (callers are responsible for calling done()
+ * if necessary)
* @param loopSize size of the loop
*/
private static void reportFloatingPointWorkInLoop(IProgressMonitor monitor, int loopSize) {
@@ -99,9 +99,9 @@ public class SubMonitorTest extends TestCase {
}
/**
- * Runs an "infinite progress" loop. Each iteration will consume 1/ratio
- * of the remaining work, and will run for the given number of iterations.
- * Retuns the number of ticks reported (out of 1000).
+ * Runs an "infinite progress" loop. Each iteration will consume 1/ratio of the
+ * remaining work, and will run for the given number of iterations. Retuns the
+ * number of ticks reported (out of 1000).
*
* @param ratio
* @return the number of ticks reported
@@ -118,8 +118,10 @@ public class SubMonitorTest extends TestCase {
return monitor.getTotalWork();
}
+ @Test
public void testInfiniteProgress() {
- // In theory when reporting "infinite" progress, the actual progress reported after
+ // In theory when reporting "infinite" progress, the actual progress reported
+ // after
// n iterations should be f(n) = T(1-(1-R)^n)
//
// where T is the total ticks allocated on the root (T=1000) and R is the ratio
@@ -129,15 +131,18 @@ public class SubMonitorTest extends TestCase {
double test1 = runInfiniteProgress(100, 500);
assertEquals(993.4, test1, 1.0);
- // Reporting 0.1% per iteration, we should be at 950.2 ticks after 3000 iterations
+ // Reporting 0.1% per iteration, we should be at 950.2 ticks after 3000
+ // iterations
double test2 = runInfiniteProgress(1000, 3000);
assertEquals(950.2, test2, 1.0);
- // Reporting 0.01% per iteration, we should be at 393.5 ticks after 5000 iterations
+ // Reporting 0.01% per iteration, we should be at 393.5 ticks after 5000
+ // iterations
double test3 = runInfiniteProgress(10000, 5000);
assertEquals(393.5, test3, 1.0);
- // Reporting 0.01% per iteration, we should be at 864.7 ticks after 20000 iterations
+ // Reporting 0.01% per iteration, we should be at 864.7 ticks after 20000
+ // iterations
double test4 = runInfiniteProgress(10000, 20000);
assertEquals(864.7, test4, 1.0);
@@ -152,6 +157,7 @@ public class SubMonitorTest extends TestCase {
/**
* Ensures that we don't lose any progress when calling setWorkRemaining
*/
+ @Test
public void testSetWorkRemaining() {
TestProgressMonitor monitor = new TestProgressMonitor();
SubMonitor mon = SubMonitor.convert(monitor, 0);
@@ -171,9 +177,10 @@ public class SubMonitorTest extends TestCase {
}
/**
- * Tests that SubMonitor.done() will clean up after an unconsumed child
- * that was created with the explicit constructor
+ * Tests that SubMonitor.done() will clean up after an unconsumed child that was
+ * created with the explicit constructor
*/
+ @Test
public void testCleanupConstructedChildren() {
TestProgressMonitor top = new TestProgressMonitor();
@@ -185,7 +192,8 @@ public class SubMonitorTest extends TestCase {
child2.done();
- Assert.assertEquals("Ensure that done() reports unconsumed progress, even if beginTask wasn't called", 600.0, top.getTotalWork(), 0.01d);
+ assertEquals("Ensure that done() reports unconsumed progress, even if beginTask wasn't called", 600.0,
+ top.getTotalWork(), 0.01d);
SubMonitor child3 = monitor.newChild(100);
@@ -194,18 +202,20 @@ public class SubMonitorTest extends TestCase {
monitor.done();
- Assert.assertEquals("Ensure that done() cleans up after unconsumed children that were created by their constructor", 1000.0, top.getTotalWork(), 0.01d);
+ assertEquals("Ensure that done() cleans up after unconsumed children that were created by their constructor",
+ 1000.0, top.getTotalWork(), 0.01d);
child3.worked(100);
- Assert.assertEquals("Ensure that children can't report any progress if their parent has completed", 1000.0, top.getTotalWork(), 0.01d);
+ assertEquals("Ensure that children can't report any progress if their parent has completed", 1000.0,
+ top.getTotalWork(), 0.01d);
}
/**
- * Tests SubMonitor under typical usage. This is the same
- * as the performance test as the same name, but it verifies correctness
- * rather than performance.
+ * Tests SubMonitor under typical usage. This is the same as the performance
+ * test as the same name, but it verifies correctness rather than performance.
*/
+ @Test
public void testTypicalUsage() {
TestProgressMonitor monitor = new TestProgressMonitor();
SubMonitorTest.runTestTypicalUsage(monitor);
@@ -213,10 +223,10 @@ public class SubMonitorTest extends TestCase {
}
/**
- * Tests creating a tree of SubMonitors. This is the same
- * as the performance test as the same name, but it verifies correctness
- * rather than performance.
+ * Tests creating a tree of SubMonitors. This is the same as the performance
+ * test as the same name, but it verifies correctness rather than performance.
*/
+ @Test
public void testCreateTree() {
TestProgressMonitor monitor = new TestProgressMonitor();
SubMonitorTest.runTestCreateTree(monitor);
@@ -226,6 +236,7 @@ public class SubMonitorTest extends TestCase {
/**
* Tests claimed problem reported in bug 2100394.
*/
+ @Test
public void testBug210394() {
TestProgressMonitor testMonitor = new TestProgressMonitor();
SubMonitor monitor = SubMonitor.convert(testMonitor);
@@ -252,24 +263,25 @@ public class SubMonitorTest extends TestCase {
}
/**
- * Ensures that SubMonitor won't report more than 100% progress
- * when a child is created with more than the amount of available progress.
+ * Ensures that SubMonitor won't report more than 100% progress when a child is
+ * created with more than the amount of available progress.
*/
+ @Test
public void testChildOverflow() {
TestProgressMonitor top = new TestProgressMonitor();
SubMonitor mon1 = SubMonitor.convert(top, 1000);
- Assert.assertEquals(0.0, top.getTotalWork(), 0.1d);
+ assertEquals(0.0, top.getTotalWork(), 0.1d);
SubMonitor child2 = mon1.newChild(700);
child2.done();
- Assert.assertEquals(700.0, top.getTotalWork(), 0.1d);
+ assertEquals(700.0, top.getTotalWork(), 0.1d);
SubMonitor child3 = mon1.newChild(700);
child3.done();
- Assert.assertEquals("The reported work should not exceed 1000", 1000.0, top.getTotalWork(), 0.1d);
+ assertEquals("The reported work should not exceed 1000", 1000.0, top.getTotalWork(), 0.1d);
mon1.done();
@@ -279,45 +291,48 @@ public class SubMonitorTest extends TestCase {
/**
* Tests the 1-argument convert(...) method
*/
+ @Test
public void testConvert() {
TestProgressMonitor top = new TestProgressMonitor();
SubMonitor mon1 = SubMonitor.convert(top);
- Assert.assertEquals(0.0, top.getTotalWork(), 0.1d);
+ assertEquals(0.0, top.getTotalWork(), 0.1d);
mon1.worked(10);
- Assert.assertEquals(0.0, top.getTotalWork(), 0.1d);
+ assertEquals(0.0, top.getTotalWork(), 0.1d);
mon1.setWorkRemaining(100);
mon1.worked(50);
- Assert.assertEquals(500.0, top.getTotalWork(), 0.1d);
+ assertEquals(500.0, top.getTotalWork(), 0.1d);
mon1.done();
- Assert.assertEquals(1000.0, top.getTotalWork(), 0.1d);
+ assertEquals(1000.0, top.getTotalWork(), 0.1d);
top.done();
}
/**
* Tests the function of the SUPPRESS_* flags
*/
+ @Test
public void testFlags() {
TestProgressMonitor top = new TestProgressMonitor();
SubMonitor mon1 = SubMonitor.convert(top, "initial", 100);
// Ensure that we've called begintask on the root with the correct argument
- Assert.assertEquals(top.getBeginTaskCalls(), 1);
- Assert.assertEquals(top.getBeginTaskName(), "initial");
+ assertEquals(top.getBeginTaskCalls(), 1);
+ assertEquals(top.getBeginTaskName(), "initial");
mon1.beginTask("beginTask", 1000);
- // Ensure that beginTask on the child does NOT result in more than 1 call to beginTask on the root
- Assert.assertEquals(top.getBeginTaskCalls(), 1);
+ // Ensure that beginTask on the child does NOT result in more than 1 call to
+ // beginTask on the root
+ assertEquals(top.getBeginTaskCalls(), 1);
// Ensure that the task name was propogated correctly
- Assert.assertEquals(top.getTaskName(), "beginTask");
+ assertEquals(top.getTaskName(), "beginTask");
mon1.setTaskName("setTaskName");
- Assert.assertEquals(top.getTaskName(), "setTaskName");
+ assertEquals(top.getTaskName(), "setTaskName");
mon1.subTask("subTask");
- Assert.assertEquals(top.getSubTaskName(), "subTask");
+ assertEquals(top.getSubTaskName(), "subTask");
// Create a child monitor that permits calls to beginTask
{
@@ -325,13 +340,13 @@ public class SubMonitorTest extends TestCase {
// Ensure that everything is propogated
mon2.beginTask("mon2.beginTask", 100);
- Assert.assertEquals(top.getTaskName(), "mon2.beginTask");
+ assertEquals(top.getTaskName(), "mon2.beginTask");
mon2.setTaskName("mon2.setTaskName");
- Assert.assertEquals(top.getTaskName(), "mon2.setTaskName");
+ assertEquals(top.getTaskName(), "mon2.setTaskName");
mon2.subTask("mon2.subTask");
- Assert.assertEquals(top.getSubTaskName(), "mon2.subTask");
+ assertEquals(top.getSubTaskName(), "mon2.subTask");
}
}
@@ -346,17 +361,15 @@ public class SubMonitorTest extends TestCase {
return results.toArray(new String[results.size()]);
}
+ @Test
public void testSplitPerformsAutoCancel() {
NullProgressMonitor npm = new NullProgressMonitor();
npm.setCanceled(true);
SubMonitor subMonitor = SubMonitor.convert(npm, 1000);
- try {
- subMonitor.split(500);
- fail("split should have thrown an exception");
- } catch (OperationCanceledException exception) {
- }
+ assertThrows(OperationCanceledException.class, () -> subMonitor.split(500));
}
+ @Test
public void testNewChildDoesNotAutoCancel() {
NullProgressMonitor npm = new NullProgressMonitor();
npm.setCanceled(true);
@@ -364,12 +377,14 @@ public class SubMonitorTest extends TestCase {
subMonitor.newChild(500);
}
+ @Test
public void testSplitDoesNotThrowExceptionIfParentNotCanceled() {
NullProgressMonitor npm = new NullProgressMonitor();
SubMonitor subMonitor = SubMonitor.convert(npm, 1000);
subMonitor.split(500);
}
+ @Test
public void testAutoCancelDoesNothingForTrivialConversions() {
NullProgressMonitor npm = new NullProgressMonitor();
npm.setCanceled(true);
@@ -377,6 +392,7 @@ public class SubMonitorTest extends TestCase {
subMonitor.split(1000);
}
+ @Test
public void testAutoCancelDoesNothingForSingleTrivialOperation() {
NullProgressMonitor npm = new NullProgressMonitor();
npm.setCanceled(true);
@@ -384,57 +400,57 @@ public class SubMonitorTest extends TestCase {
subMonitor.split(0);
}
+ @Test
public void testAutoCancelThrowsExceptionEventuallyForManyTrivialOperations() {
NullProgressMonitor npm = new NullProgressMonitor();
npm.setCanceled(true);
SubMonitor subMonitor = SubMonitor.convert(npm, 1000);
- try {
+ assertThrows(OperationCanceledException.class, () -> {
for (int counter = 0; counter < 1000; counter++) {
subMonitor.split(0);
}
- fail("split should have thrown an exception");
- } catch (OperationCanceledException exception) {
- }
+ });
}
+ @Test
public void testConsumingEndOfMonitorNotTreatedAsTrivial() {
NullProgressMonitor npm = new NullProgressMonitor();
SubMonitor subMonitor = SubMonitor.convert(npm, 1000);
subMonitor.newChild(500);
- try {
- npm.setCanceled(true);
- subMonitor.split(500);
- fail("split should have thrown an exception");
- } catch (OperationCanceledException exception) {
- }
+ npm.setCanceled(true);
+ assertThrows(OperationCanceledException.class, () -> subMonitor.split(500));
}
+ @Test
public void testIsCanceled() {
NullProgressMonitor npm = new NullProgressMonitor();
SubMonitor subMonitor = SubMonitor.convert(npm);
- assertTrue("subMonitor should not be canceled", !subMonitor.isCanceled());
+ assertFalse("subMonitor should not be canceled", subMonitor.isCanceled());
npm.setCanceled(true);
assertTrue("subMonitor should be canceled", subMonitor.isCanceled());
}
+ @Test
public void testSuppressIsCanceled() {
NullProgressMonitor npm = new NullProgressMonitor();
SubMonitor subMonitor = SubMonitor.convert(npm).newChild(0, SubMonitor.SUPPRESS_ISCANCELED);
- assertTrue("subMonitor should not be canceled", !subMonitor.isCanceled());
+ assertFalse("subMonitor should not be canceled", subMonitor.isCanceled());
npm.setCanceled(true);
- assertTrue("subMonitor should not be canceled", !subMonitor.isCanceled());
+ assertFalse("subMonitor should not be canceled", subMonitor.isCanceled());
}
+ @Test
public void testSuppressIsCanceledFlagIsInherited() {
NullProgressMonitor npm = new NullProgressMonitor();
SubMonitor subMonitor = SubMonitor.convert(npm).newChild(0, SubMonitor.SUPPRESS_ISCANCELED).newChild(0);
- assertTrue("subMonitor should not be canceled", !subMonitor.isCanceled());
+ assertFalse("subMonitor should not be canceled", subMonitor.isCanceled());
npm.setCanceled(true);
- assertTrue("subMonitor should not be canceled", !subMonitor.isCanceled());
+ assertFalse("subMonitor should not be canceled", subMonitor.isCanceled());
}
+ @Test
public void testSuppressIsCanceledAffectsSplit() {
NullProgressMonitor npm = new NullProgressMonitor();
SubMonitor subMonitor = SubMonitor.convert(npm, 100).newChild(100, SubMonitor.SUPPRESS_ISCANCELED);
@@ -446,83 +462,88 @@ public class SubMonitorTest extends TestCase {
/**
* Tests the style bits in SubProgressMonitor
*/
+ @Test
public void testStyles() {
- int[] styles = new int[] {SubMonitor.SUPPRESS_NONE, SubMonitor.SUPPRESS_BEGINTASK, SubMonitor.SUPPRESS_SETTASKNAME, SubMonitor.SUPPRESS_SUBTASK, SubMonitor.SUPPRESS_BEGINTASK | SubMonitor.SUPPRESS_SETTASKNAME, SubMonitor.SUPPRESS_BEGINTASK | SubMonitor.SUPPRESS_SUBTASK, SubMonitor.SUPPRESS_SETTASKNAME | SubMonitor.SUPPRESS_SUBTASK, SubMonitor.SUPPRESS_ALL_LABELS};
+ int[] styles = new int[] { SubMonitor.SUPPRESS_NONE, SubMonitor.SUPPRESS_BEGINTASK,
+ SubMonitor.SUPPRESS_SETTASKNAME, SubMonitor.SUPPRESS_SUBTASK,
+ SubMonitor.SUPPRESS_BEGINTASK | SubMonitor.SUPPRESS_SETTASKNAME,
+ SubMonitor.SUPPRESS_BEGINTASK | SubMonitor.SUPPRESS_SUBTASK,
+ SubMonitor.SUPPRESS_SETTASKNAME | SubMonitor.SUPPRESS_SUBTASK, SubMonitor.SUPPRESS_ALL_LABELS };
HashMap<String, String[]> expected = new HashMap<>();
- expected.put("style 5 below style 7", new String[] {"", "", ""});
- expected.put("style 7 below style 5", new String[] {"beginTask0", "", "beginTask0"});
- expected.put("style 7 below style 4", new String[] {"beginTask0", "subTask0", "beginTask0"});
- expected.put("style 5 below style 6", new String[] {"", "subTask0", ""});
- expected.put("style 3 below style 7", new String[] {"", "", ""});
- expected.put("style 5 below style 5", new String[] {"beginTask0", "", "beginTask0"});
- expected.put("style 7 below style 3", new String[] {"setTaskName0", "", "setTaskName0"});
- expected.put("style 7 below style 2", new String[] {"setTaskName0", "subTask0", "setTaskName0"});
- expected.put("style 5 below style 4", new String[] {"beginTask0", "subTask0", "beginTask0"});
- expected.put("style 3 below style 6", new String[] {"", "subTask0", ""});
- expected.put("style 1 below style 7", new String[] {"", "", ""});
- expected.put("style 3 below style 5", new String[] {"beginTask0", "", "beginTask0"});
- expected.put("style 5 below style 3", new String[] {"beginTask1", "", "beginTask1"});
- expected.put("style 7 below style 1", new String[] {"setTaskName0", "", "setTaskName0"});
- expected.put("style 3 below style 4", new String[] {"beginTask0", "subTask0", "beginTask0"});
- expected.put("style 5 below style 2", new String[] {"beginTask1", "subTask0", "beginTask1"});
- expected.put("style 7 below style 0", new String[] {"setTaskName0", "subTask0", "setTaskName0"});
- expected.put("style 1 below style 6", new String[] {"", "subTask0", ""});
- expected.put("style 1 below style 5", new String[] {"beginTask0", "", "beginTask0"});
- expected.put("style 3 below style 3", new String[] {"setTaskName0", "", "setTaskName1"});
- expected.put("style 5 below style 1", new String[] {"beginTask1", "", "beginTask1"});
- expected.put("style 1 below style 4", new String[] {"beginTask0", "subTask0", "beginTask0"});
- expected.put("style 3 below style 2", new String[] {"setTaskName0", "subTask0", "setTaskName1"});
- expected.put("style 5 below style 0", new String[] {"beginTask1", "subTask0", "beginTask1"});
- expected.put("style 1 below style 3", new String[] {"beginTask1", "", "setTaskName1"});
- expected.put("style 3 below style 1", new String[] {"setTaskName0", "", "setTaskName1"});
- expected.put("style 1 below style 2", new String[] {"beginTask1", "subTask0", "setTaskName1"});
- expected.put("style 3 below style 0", new String[] {"setTaskName0", "subTask0", "setTaskName1"});
- expected.put("style 1 below style 1", new String[] {"beginTask1", "", "setTaskName1"});
- expected.put("style 1 below style 0", new String[] {"beginTask1", "subTask0", "setTaskName1"});
- expected.put("style 3 as top-level monitor", new String[] {"", "", "setTaskName0"});
- expected.put("style 7 as top-level monitor", new String[] {"", "", ""});
- expected.put("style 2 as top-level monitor", new String[] {"", "subTask0", "setTaskName0"});
- expected.put("style 6 as top-level monitor", new String[] {"", "subTask0", ""});
- expected.put("style 6 below style 7", new String[] {"", "", ""});
- expected.put("style 6 below style 6", new String[] {"", "subTask1", ""});
- expected.put("style 4 below style 7", new String[] {"", "", ""});
- expected.put("style 6 below style 5", new String[] {"beginTask0", "", "beginTask0"});
- expected.put("style 6 below style 4", new String[] {"beginTask0", "subTask1", "beginTask0"});
- expected.put("style 4 below style 6", new String[] {"", "subTask1", ""});
- expected.put("style 2 below style 7", new String[] {"", "", ""});
- expected.put("style 4 below style 5", new String[] {"beginTask0", "", "beginTask0"});
- expected.put("style 6 below style 3", new String[] {"setTaskName0", "", "setTaskName0"});
- expected.put("style 4 below style 4", new String[] {"beginTask0", "subTask1", "beginTask0"});
- expected.put("style 6 below style 2", new String[] {"setTaskName0", "subTask1", "setTaskName0"});
- expected.put("style 2 below style 6", new String[] {"", "subTask1", ""});
- expected.put("style 0 below style 7", new String[] {"", "", ""});
- expected.put("style 2 below style 5", new String[] {"beginTask0", "", "beginTask0"});
- expected.put("style 6 below style 1", new String[] {"setTaskName0", "", "setTaskName0"});
- expected.put("style 4 below style 3", new String[] {"beginTask1", "", "beginTask1"});
- expected.put("style 2 below style 4", new String[] {"beginTask0", "subTask1", "beginTask0"});
- expected.put("style 6 below style 0", new String[] {"setTaskName0", "subTask1", "setTaskName0"});
- expected.put("style 4 below style 2", new String[] {"beginTask1", "subTask1", "beginTask1"});
- expected.put("style 0 below style 6", new String[] {"", "subTask1", ""});
- expected.put("style 0 below style 5", new String[] {"beginTask0", "", "beginTask0"});
- expected.put("style 4 below style 1", new String[] {"beginTask1", "", "beginTask1"});
- expected.put("style 2 below style 3", new String[] {"setTaskName0", "", "setTaskName1"});
- expected.put("style 0 below style 4", new String[] {"beginTask0", "subTask1", "beginTask0"});
- expected.put("style 4 below style 0", new String[] {"beginTask1", "subTask1", "beginTask1"});
- expected.put("style 2 below style 2", new String[] {"setTaskName0", "subTask1", "setTaskName1"});
- expected.put("style 1 as top-level monitor", new String[] {"beginTask0", "", "setTaskName0"});
- expected.put("style 2 below style 1", new String[] {"setTaskName0", "", "setTaskName1"});
- expected.put("style 0 below style 3", new String[] {"beginTask1", "", "setTaskName1"});
- expected.put("style 2 below style 0", new String[] {"setTaskName0", "subTask1", "setTaskName1"});
- expected.put("style 0 below style 2", new String[] {"beginTask1", "subTask1", "setTaskName1"});
- expected.put("style 0 below style 1", new String[] {"beginTask1", "", "setTaskName1"});
- expected.put("style 0 below style 0", new String[] {"beginTask1", "subTask1", "setTaskName1"});
- expected.put("style 5 as top-level monitor", new String[] {"beginTask0", "", "beginTask0"});
- expected.put("style 0 as top-level monitor", new String[] {"beginTask0", "subTask0", "setTaskName0"});
- expected.put("style 4 as top-level monitor", new String[] {"beginTask0", "subTask0", "beginTask0"});
- expected.put("style 7 below style 7", new String[] {"", "", ""});
- expected.put("style 7 below style 6", new String[] {"", "subTask0", ""});
+ expected.put("style 5 below style 7", new String[] { "", "", "" });
+ expected.put("style 7 below style 5", new String[] { "beginTask0", "", "beginTask0" });
+ expected.put("style 7 below style 4", new String[] { "beginTask0", "subTask0", "beginTask0" });
+ expected.put("style 5 below style 6", new String[] { "", "subTask0", "" });
+ expected.put("style 3 below style 7", new String[] { "", "", "" });
+ expected.put("style 5 below style 5", new String[] { "beginTask0", "", "beginTask0" });
+ expected.put("style 7 below style 3", new String[] { "setTaskName0", "", "setTaskName0" });
+ expected.put("style 7 below style 2", new String[] { "setTaskName0", "subTask0", "setTaskName0" });
+ expected.put("style 5 below style 4", new String[] { "beginTask0", "subTask0", "beginTask0" });
+ expected.put("style 3 below style 6", new String[] { "", "subTask0", "" });
+ expected.put("style 1 below style 7", new String[] { "", "", "" });
+ expected.put("style 3 below style 5", new String[] { "beginTask0", "", "beginTask0" });
+ expected.put("style 5 below style 3", new String[] { "beginTask1", "", "beginTask1" });
+ expected.put("style 7 below style 1", new String[] { "setTaskName0", "", "setTaskName0" });
+ expected.put("style 3 below style 4", new String[] { "beginTask0", "subTask0", "beginTask0" });
+ expected.put("style 5 below style 2", new String[] { "beginTask1", "subTask0", "beginTask1" });
+ expected.put("style 7 below style 0", new String[] { "setTaskName0", "subTask0", "setTaskName0" });
+ expected.put("style 1 below style 6", new String[] { "", "subTask0", "" });
+ expected.put("style 1 below style 5", new String[] { "beginTask0", "", "beginTask0" });
+ expected.put("style 3 below style 3", new String[] { "setTaskName0", "", "setTaskName1" });
+ expected.put("style 5 below style 1", new String[] { "beginTask1", "", "beginTask1" });
+ expected.put("style 1 below style 4", new String[] { "beginTask0", "subTask0", "beginTask0" });
+ expected.put("style 3 below style 2", new String[] { "setTaskName0", "subTask0", "setTaskName1" });
+ expected.put("style 5 below style 0", new String[] { "beginTask1", "subTask0", "beginTask1" });
+ expected.put("style 1 below style 3", new String[] { "beginTask1", "", "setTaskName1" });
+ expected.put("style 3 below style 1", new String[] { "setTaskName0", "", "setTaskName1" });
+ expected.put("style 1 below style 2", new String[] { "beginTask1", "subTask0", "setTaskName1" });
+ expected.put("style 3 below style 0", new String[] { "setTaskName0", "subTask0", "setTaskName1" });
+ expected.put("style 1 below style 1", new String[] { "beginTask1", "", "setTaskName1" });
+ expected.put("style 1 below style 0", new String[] { "beginTask1", "subTask0", "setTaskName1" });
+ expected.put("style 3 as top-level monitor", new String[] { "", "", "setTaskName0" });
+ expected.put("style 7 as top-level monitor", new String[] { "", "", "" });
+ expected.put("style 2 as top-level monitor", new String[] { "", "subTask0", "setTaskName0" });
+ expected.put("style 6 as top-level monitor", new String[] { "", "subTask0", "" });
+ expected.put("style 6 below style 7", new String[] { "", "", "" });
+ expected.put("style 6 below style 6", new String[] { "", "subTask1", "" });
+ expected.put("style 4 below style 7", new String[] { "", "", "" });
+ expected.put("style 6 below style 5", new String[] { "beginTask0", "", "beginTask0" });
+ expected.put("style 6 below style 4", new String[] { "beginTask0", "subTask1", "beginTask0" });
+ expected.put("style 4 below style 6", new String[] { "", "subTask1", "" });
+ expected.put("style 2 below style 7", new String[] { "", "", "" });
+ expected.put("style 4 below style 5", new String[] { "beginTask0", "", "beginTask0" });
+ expected.put("style 6 below style 3", new String[] { "setTaskName0", "", "setTaskName0" });
+ expected.put("style 4 below style 4", new String[] { "beginTask0", "subTask1", "beginTask0" });
+ expected.put("style 6 below style 2", new String[] { "setTaskName0", "subTask1", "setTaskName0" });
+ expected.put("style 2 below style 6", new String[] { "", "subTask1", "" });
+ expected.put("style 0 below style 7", new String[] { "", "", "" });
+ expected.put("style 2 below style 5", new String[] { "beginTask0", "", "beginTask0" });
+ expected.put("style 6 below style 1", new String[] { "setTaskName0", "", "setTaskName0" });
+ expected.put("style 4 below style 3", new String[] { "beginTask1", "", "beginTask1" });
+ expected.put("style 2 below style 4", new String[] { "beginTask0", "subTask1", "beginTask0" });
+ expected.put("style 6 below style 0", new String[] { "setTaskName0", "subTask1", "setTaskName0" });
+ expected.put("style 4 below style 2", new String[] { "beginTask1", "subTask1", "beginTask1" });
+ expected.put("style 0 below style 6", new String[] { "", "subTask1", "" });
+ expected.put("style 0 below style 5", new String[] { "beginTask0", "", "beginTask0" });
+ expected.put("style 4 below style 1", new String[] { "beginTask1", "", "beginTask1" });
+ expected.put("style 2 below style 3", new String[] { "setTaskName0", "", "setTaskName1" });
+ expected.put("style 0 below style 4", new String[] { "beginTask0", "subTask1", "beginTask0" });
+ expected.put("style 4 below style 0", new String[] { "beginTask1", "subTask1", "beginTask1" });
+ expected.put("style 2 below style 2", new String[] { "setTaskName0", "subTask1", "setTaskName1" });
+ expected.put("style 1 as top-level monitor", new String[] { "beginTask0", "", "setTaskName0" });
+ expected.put("style 2 below style 1", new String[] { "setTaskName0", "", "setTaskName1" });
+ expected.put("style 0 below style 3", new String[] { "beginTask1", "", "setTaskName1" });
+ expected.put("style 2 below style 0", new String[] { "setTaskName0", "subTask1", "setTaskName1" });
+ expected.put("style 0 below style 2", new String[] { "beginTask1", "subTask1", "setTaskName1" });
+ expected.put("style 0 below style 1", new String[] { "beginTask1", "", "setTaskName1" });
+ expected.put("style 0 below style 0", new String[] { "beginTask1", "subTask1", "setTaskName1" });
+ expected.put("style 5 as top-level monitor", new String[] { "beginTask0", "", "beginTask0" });
+ expected.put("style 0 as top-level monitor", new String[] { "beginTask0", "subTask0", "setTaskName0" });
+ expected.put("style 4 as top-level monitor", new String[] { "beginTask0", "subTask0", "beginTask0" });
+ expected.put("style 7 below style 7", new String[] { "", "", "" });
+ expected.put("style 7 below style 6", new String[] { "", "subTask0", "" });
HashMap<String, String[]> results = new HashMap<>();
for (int style : styles) {
@@ -554,8 +575,8 @@ public class SubMonitorTest extends TestCase {
}
}
- String failure = null;
- // Output the code for the observed results, in case one of them has changed intentionally
+ // Output the code for the observed results, in case one of them has changed
+ // intentionally
for (Map.Entry<String, String[]> entry : results.entrySet()) {
String[] expectedResult = expected.get(entry.getKey());
if (expectedResult == null) {
@@ -563,59 +584,14 @@ public class SubMonitorTest extends TestCase {
}
String[] value = entry.getValue();
- if (compareArray(value, expectedResult)) {
- continue;
- }
-
- System.out.print("expected.put(\"" + entry.getKey() + "\", new String[] {");
- failure = entry.getKey();
- String list = concatArray(value);
- System.out.println(list + "});");
- }
-
- if (failure != null) {
- Assert.assertEquals(failure, concatArray(expected.get(failure)), concatArray(results.get(failure)));
- }
- }
-
- private boolean compareArray(String[] value, String[] expectedResult) {
- if (value == null || expectedResult == null) {
- return value == null && expectedResult == null;
- }
-
- if (value.length != expectedResult.length) {
- return false;
- }
- for (int i = 0; i < expectedResult.length; i++) {
- String next = expectedResult[i];
- if (!next.equals(value[i])) {
- return false;
- }
+ assertArrayEquals(value, expectedResult);
}
- return true;
- }
-
- private String concatArray(String[] value) {
- if (value == null) {
- return "";
- }
-
- StringBuilder buf = new StringBuilder();
- boolean isFirst = true;
- for (String nextValue : value) {
- if (!isFirst) {
- buf.append(", ");
- }
- isFirst = false;
- buf.append("\"" + nextValue + "\"");
- }
- String list = buf.toString();
- return list;
}
/**
* Ensures that SubMonitor doesn't propogate redundant progress to its parent.
*/
+ @Test
public void testRedundantWork() {
TestProgressMonitor top = new TestProgressMonitor();
@@ -634,6 +610,7 @@ public class SubMonitorTest extends TestCase {
top.assertOptimal();
}
+ @Test
public void testCancellation() {
TestProgressMonitor root = new TestProgressMonitor();
@@ -641,13 +618,13 @@ public class SubMonitorTest extends TestCase {
// Test that changes at the root propogate to the child
root.setCanceled(true);
- Assert.assertTrue(spm.isCanceled());
+ assertTrue(spm.isCanceled());
root.setCanceled(false);
Assert.assertFalse(spm.isCanceled());
// Test that changes to the child propogate to the root
spm.setCanceled(true);
- Assert.assertTrue(root.isCanceled());
+ assertTrue(root.isCanceled());
spm.setCanceled(false);
Assert.assertFalse(root.isCanceled());
@@ -657,17 +634,18 @@ public class SubMonitorTest extends TestCase {
// Test that changes at the root propogate to the child
root.setCanceled(true);
- Assert.assertTrue(spm2.isCanceled());
+ assertTrue(spm2.isCanceled());
root.setCanceled(false);
Assert.assertFalse(spm2.isCanceled());
// Test that changes to the child propogate to the root
spm2.setCanceled(true);
- Assert.assertTrue(root.isCanceled());
+ assertTrue(root.isCanceled());
spm2.setCanceled(false);
Assert.assertFalse(root.isCanceled());
}
+ @Test
public void testNullParent() {
// Touch everything in the public API to ensure we don't throw an NPE
SubMonitor mon = SubMonitor.convert(null, 1000);
@@ -678,57 +656,63 @@ public class SubMonitorTest extends TestCase {
mon.internalWorked(50.0);
Assert.assertFalse(mon.isCanceled());
mon.setCanceled(true);
- Assert.assertTrue(mon.isCanceled());
+ assertTrue(mon.isCanceled());
mon.subTask("subtask");
mon.setTaskName("taskname");
mon.done();
}
/**
- * Tests the automatic cleanup when progress monitors are created via their constructor
+ * Tests the automatic cleanup when progress monitors are created via their
+ * constructor
*/
+ @Test
public void testNewChild() {
TestProgressMonitor top = new TestProgressMonitor();
SubMonitor mon = SubMonitor.convert(top, 1000);
- Assert.assertEquals("Ensure no work has been reported yet", 0.0, top.getTotalWork(), 0.01d);
+ assertEquals("Ensure no work has been reported yet", 0.0, top.getTotalWork(), 0.01d);
mon.newChild(100);
- Assert.assertEquals("Ensure no work has been reported yet", 0.0, top.getTotalWork(), 0.01d);
+ assertEquals("Ensure no work has been reported yet", 0.0, top.getTotalWork(), 0.01d);
mon.newChild(200);
- Assert.assertEquals("Ensure monitor1 was collected", 100.0, top.getTotalWork(), 0.01d);
+ assertEquals("Ensure monitor1 was collected", 100.0, top.getTotalWork(), 0.01d);
- // The following behavior is necessary to make it possible to pass multiple progress monitors as
+ // The following behavior is necessary to make it possible to pass multiple
+ // progress monitors as
// arguments to the same method.
- Assert.assertEquals("Monitor2 should not have been collected yet (when the public constructor is used, collection should happen when beginTask() or setWorkRemaining() is called.", 100.0, top.getTotalWork(), 0.01d);
+ assertEquals(
+ "Monitor2 should not have been collected yet (when the public constructor is used, collection should happen when beginTask() or setWorkRemaining() is called.",
+ 100.0, top.getTotalWork(), 0.01d);
SubMonitor monitor4 = mon.newChild(300);
- Assert.assertEquals("Now monitor2 should be collected", 300.0, top.getTotalWork(), 0.01d);
+ assertEquals("Now monitor2 should be collected", 300.0, top.getTotalWork(), 0.01d);
monitor4.done();
- Assert.assertEquals("Now monitor4 should be collected", 600.0, top.getTotalWork(), 0.01d);
+ assertEquals("Now monitor4 should be collected", 600.0, top.getTotalWork(), 0.01d);
mon.newChild(10);
- Assert.assertEquals("Creating a child when there are no active children should not report any work", 600.0, top.getTotalWork(), 0.01d);
+ assertEquals("Creating a child when there are no active children should not report any work", 600.0,
+ top.getTotalWork(), 0.01d);
mon.worked(20);
// Test for bug 210394
- Assert.assertEquals("Reporting work should cause the active child to be destroyed", 630.0, top.getTotalWork(), 0.01d);
+ assertEquals("Reporting work should cause the active child to be destroyed", 630.0, top.getTotalWork(), 0.01d);
mon.newChild(10);
- Assert.assertEquals("monitor5 should have been cleaned up", 630.0, top.getTotalWork(), 0.01d);
+ assertEquals("monitor5 should have been cleaned up", 630.0, top.getTotalWork(), 0.01d);
mon.internalWorked(60);
- Assert.assertEquals("Calling internalWorked should clean up active children", 700.0, top.getTotalWork(), 0.01d);
+ assertEquals("Calling internalWorked should clean up active children", 700.0, top.getTotalWork(), 0.01d);
// Now create a chain of undisposed children
SubMonitor monitor7 = mon.newChild(100);
@@ -739,29 +723,32 @@ public class SubMonitorTest extends TestCase {
mon.done();
- Assert.assertEquals("Calling done should clean up unused work", 1000.0, top.getTotalWork(), 0.01d);
+ assertEquals("Calling done should clean up unused work", 1000.0, top.getTotalWork(), 0.01d);
}
/**
- * Tests creating progress monitors under a custom progress monitor
- * parent. This is the same as the performance test as the same name,
- * but it verifies correctness rather than performance.
+ * Tests creating progress monitors under a custom progress monitor parent. This
+ * is the same as the performance test as the same name, but it verifies
+ * correctness rather than performance.
*/
+ @Test
public void testCreateChildrenUnderCustomParent() {
TestProgressMonitor monitor = new TestProgressMonitor();
createChildrenUnderParent(monitor, SubMonitorTest.PROGRESS_SIZE);
- // We don't actually expect the progress to be optimal in this case since the progress monitor wouldn't
- // know what it was rooted under and would have had to report more progress than necessary... but we
+ // We don't actually expect the progress to be optimal in this case since the
+ // progress monitor wouldn't
+ // know what it was rooted under and would have had to report more progress than
+ // necessary... but we
// should be able to check that there was no redundancy.
- Assert.assertTrue(monitor.getRedundantWorkCalls() == 0);
- Assert.assertTrue(monitor.getWorkCalls() >= 100);
+ assertEquals(0, monitor.getRedundantWorkCalls());
+ assertTrue(monitor.getWorkCalls() >= 100);
}
/**
- * Creates a chain of n nested progress monitors. Calls beginTask on all monitors
- * except for the innermost one.
+ * Creates a chain of n nested progress monitors. Calls beginTask on all
+ * monitors except for the innermost one.
*
* @param parent
* @param depth
@@ -780,11 +767,12 @@ public class SubMonitorTest extends TestCase {
}
/**
- * Creates a balanced binary tree of progress monitors, without calling worked. Tests
- * progress monitor creation and cleanup time, and ensures that excess progress is
- * being collected when IProgressMonitor.done() is called.
+ * Creates a balanced binary tree of progress monitors, without calling worked.
+ * Tests progress monitor creation and cleanup time, and ensures that excess
+ * progress is being collected when IProgressMonitor.done() is called.
*
- * @param monitor progress monitor (callers are responsible for calling done() if necessary)
+ * @param monitor progress monitor (callers are responsible for calling done()
+ * if necessary)
* @param loopSize total size of the recursion tree
*/
public static void createBalancedTree(IProgressMonitor parent, int loopSize) {
@@ -802,13 +790,22 @@ public class SubMonitorTest extends TestCase {
}
/**
- * <p>The innermost loop for the create tree test. We make this a static method so
- * that it can be used both in this performance test and in the correctness test.</p>
+ * <p>
+ * The innermost loop for the create tree test. We make this a static method so
+ * that it can be used both in this performance test and in the correctness
+ * test.
+ * </p>
*
- * <p>The performance test ensures that it is fast to create a lot of progress monitors.</p>
+ * <p>
+ * The performance test ensures that it is fast to create a lot of progress
+ * monitors.
+ * </p>
*
- * <p>The correctness test ensures that creating and destroying SubMonitors
- * is enough to report progress, even if worked(int) and worked(double) are never called</p>
+ * <p>
+ * The correctness test ensures that creating and destroying SubMonitors is
+ * enough to report progress, even if worked(int) and worked(double) are never
+ * called
+ * </p>
*/
public static void runTestCreateTree(IProgressMonitor monitor) {
SubMonitor progress = SubMonitor.convert(monitor, 100);
@@ -821,12 +818,14 @@ public class SubMonitorTest extends TestCase {
}
/**
- * Reports progress by creating a balanced binary tree of progress monitors. Simulates
- * mixed usage of IProgressMonitor in a typical usage. Calls isCanceled once each time work
- * is reported. Half of the work is reported using internalWorked and half is reported using worked,
- * to simulate mixed usage of the progress monitor.
+ * Reports progress by creating a balanced binary tree of progress monitors.
+ * Simulates mixed usage of IProgressMonitor in a typical usage. Calls
+ * isCanceled once each time work is reported. Half of the work is reported
+ * using internalWorked and half is reported using worked, to simulate mixed
+ * usage of the progress monitor.
*
- * @param monitor progress monitor (callers are responsible for calling done() if necessary)
+ * @param monitor progress monitor (callers are responsible for calling done()
+ * if necessary)
* @param loopSize total size of the recursion tree
*/
public static void reportWorkInBalancedTree(IProgressMonitor parent, int loopSize) {
@@ -853,7 +852,8 @@ public class SubMonitorTest extends TestCase {
/**
* The innermost loop for the recursion test. We make this a static method so
- * that it can be used both in this performance test and in the correctness test.
+ * that it can be used both in this performance test and in the correctness
+ * test.
*/
public static void runTestTypicalUsage(IProgressMonitor monitor) {
SubMonitor progress = SubMonitor.convert(monitor, 100);
@@ -866,10 +866,10 @@ public class SubMonitorTest extends TestCase {
}
/**
- * Tests SubMonitor.worked. This is the same
- * as the performance test as the same name, but it verifies correctness
- * rather than performance.
+ * Tests SubMonitor.worked. This is the same as the performance test as the same
+ * name, but it verifies correctness rather than performance.
*/
+ @Test
public void testWorked() {
TestProgressMonitor monitor = new TestProgressMonitor();
SubMonitor progress = SubMonitor.convert(monitor, 100);
@@ -884,10 +884,10 @@ public class SubMonitorTest extends TestCase {
}
/**
- * Tests SubMonitor.worked. This is the same
- * as the performance test as the same name, but it verifies correctness
- * rather than performance.
+ * Tests SubMonitor.worked. This is the same as the performance test as the same
+ * name, but it verifies correctness rather than performance.
*/
+ @Test
public void testInternalWorked() {
TestProgressMonitor monitor = new TestProgressMonitor();
SubMonitor progress = SubMonitor.convert(monitor, 100);
@@ -906,6 +906,7 @@ public class SubMonitorTest extends TestCase {
* {@link SubMonitor#split(int, int)} when passing in the
* {@link SubMonitor#SUPPRESS_ISCANCELED} flag.
*/
+ @Test
public void testSplitDoesNotCancelWhenCancellationSuppressed() {
TestProgressMonitor monitor = new TestProgressMonitor();
monitor.setCanceled(true);
@@ -919,10 +920,11 @@ public class SubMonitorTest extends TestCase {
}
/**
- * Creates and destroys the given number of child progress monitors under the given parent.
+ * Creates and destroys the given number of child progress monitors under the
+ * given parent.
*
- * @param parent monitor to create children under. The caller must call done on this monitor
- * if necessary.
+ * @param parent monitor to create children under. The caller must call
+ * done on this monitor if necessary.
* @param progressSize total number of children to create.
*/
private static void createChildrenUnderParent(IProgressMonitor parent, int progressSize) {
@@ -934,9 +936,4 @@ public class SubMonitorTest extends TestCase {
}
}
- static public void reportPerformance(String className, String methodName, long startTime, long endTime) {
- // enable to see performance results for the progress monitors
- // System.out.println(className + "#" + methodName + " elapsed time: " + (endTime - startTime) / 1000.0d + "s");
- }
-
}

Back to the top