Esempio n. 1
0
  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());
  }
Esempio n. 2
0
 public void onMessage(Message message) {
   this.message = message;
   latch.countDown();
   try {
     released.whenTrue(null);
   } catch (InterruptedException e) {
     // ignored
   }
 }
Esempio n. 3
0
  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());
  }