public void testWhenTrue() throws InterruptedException { final WaitableBoolean blocker = new WaitableBoolean(false); final WaitableBoolean actionPerformed = new WaitableBoolean(false); Runnable switcher = new Runnable() { public void run() { try { Thread.sleep(500); blocker.set(true); } catch (InterruptedException iex) { // ignore } } }; Runnable action = new Runnable() { public void run() { actionPerformed.set(true); } }; new Thread(switcher).start(); blocker.whenTrue(action); assertTrue(blocker.get()); assertTrue(actionPerformed.get()); }
public void onMessage(Message message) { this.message = message; latch.countDown(); try { released.whenTrue(null); } catch (InterruptedException e) { // ignored } }
public void testWhenTrueAlreadyTrue() throws InterruptedException { final WaitableBoolean blocker = new WaitableBoolean(true); final WaitableBoolean actionPerformed = new WaitableBoolean(false); Runnable action = new Runnable() { public void run() { actionPerformed.set(true); } }; blocker.whenTrue(action); assertTrue(blocker.get()); assertTrue(actionPerformed.get()); }