Source:
public void testAccumulatingMonitorInUIThread() { final Throwable[] death = new Throwable[1]; final UIThreadAsserterMonitor[] mon2 = new UIThreadAsserterMonitor[1]; TestThread t = new TestThread("Test Accumulating Monitor") { @Override public void run() { try { UIThreadAsserterMonitor tm = new UIThreadAsserterMonitor(); mon2[0] = tm; IProgressMonitorWithBlocking wrapper = ProgressMonitorUtil.createAccumulatingProgressMonitor(tm, Display.getDefault()); wrapper.beginTask("Some Task", 100); wrapper.setTaskName("Task Name"); wrapper.subTask("Subtask"); wrapper.worked(10); wrapper.isCanceled(); wrapper.setCanceled(false); wrapper.setBlocked(new Status(IStatus.ERROR, "org.eclipse.ui.tests", "Some Error")); try { Thread.sleep(200); } catch (InterruptedException ie) { } wrapper.clearBlocked(); wrapper.done(); } catch (Throwable t) { death[0] = t; } } }; t.start(); runEventLoop(3000, t); assertFalse(t.isCanceled()); assertNull("Wrapped monitor not executed in UI thread", death[0]); assertNotNull(mon2[0]); assertTrue(mon2[0].beginTaskCalled); assertTrue(mon2[0].setTaskNameCalled); assertTrue(mon2[0].subTaskCalled); assertFalse(mon2[0].workedCalled); assertTrue(mon2[0].internalWorkedCalled); assertTrue(mon2[0].isCanceledCalled); assertTrue(mon2[0].setCanceledCalled); assertTrue(mon2[0].setBlockedCalled); assertTrue(mon2[0].clearBlockedCalled); assertTrue(mon2[0].doneCalled); }

Target:
public void testAccumulatingMonitorInUIThread() { final int[] state = new int[1]; state[0] = 1; final Object mutex = new Object(); final Throwable[] death = new Throwable[1]; final UIThreadAsserterMonitor[] mon2 = new UIThreadAsserterMonitor[1]; Thread t = new Thread("Test Accumulating Monitor") { @Override public void run() { try { UIThreadAsserterMonitor tm = new UIThreadAsserterMonitor(); mon2[0] = tm; IProgressMonitorWithBlocking wrapper = ProgressMonitorUtil.createAccumulatingProgressMonitor(tm, Display.getDefault()); wrapper.beginTask("Some Task", 100); wrapper.setTaskName("Task Name"); wrapper.subTask("Subtask"); wrapper.worked(10); wrapper.isCanceled(); wrapper.setCanceled(false); wrapper.setBlocked(new Status(IStatus.ERROR, "org.eclipse.ui.tests", "Some Error")); synchronized (mutex) { state[0] = 2; mutex.notifyAll(); } synchronized (mutex) { while (state[0] != 3) { try { mutex.wait(); } catch (InterruptedException e) { } } } wrapper.clearBlocked(); wrapper.done(); synchronized (mutex) { state[0] = 4; mutex.notifyAll(); } } catch (Throwable t) { death[0] = t; } } }; t.start(); synchronized (mutex) { while (state[0] != 2 || death[0] != null) { try { mutex.wait(); } catch (InterruptedException e) { } } } runEventLoopUntilEmpty(); synchronized (mutex) { state[0] = 3; mutex.notifyAll(); } synchronized (mutex) { while (state[0] != 4 || death[0] != null) { try { mutex.wait(); } catch (InterruptedException e) { } } } runEventLoopUntilEmpty(); assertNull("Wrapped monitor not executed in UI thread", death[0]); assertNotNull(mon2[0]); assertTrue(mon2[0].beginTaskCalled); assertTrue(mon2[0].setTaskNameCalled); assertTrue(mon2[0].subTaskCalled); assertFalse(mon2[0].workedCalled); assertTrue(mon2[0].internalWorkedCalled); assertTrue(mon2[0].isCanceledCalled); assertTrue(mon2[0].setCanceledCalled); assertTrue(mon2[0].setBlockedCalled); assertTrue(mon2[0].clearBlockedCalled); assertTrue(mon2[0].doneCalled); }