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