PolledAssertion { public int await() { return await(getTimeoutSeconds()); }  int await(); int await(float seconds); int await(TimeUnit unit, long length); int check(); int check(float seconds); int check(TimeUnit timeUnit, long count);  }
@Test public void testPolledConditionPasses() throws Exception { final boolean[] condition = {false}; new Thread(new Runnable() { public void run() { try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } condition[0] = true; } }).start(); new PolledAssertion() { @Override protected void validate() { assertTrue(condition[0]); } }.await(); }
@Test public void testPolledConditionFails() throws Exception { final boolean[] condition = {false}; try { new PolledAssertion() { @Override protected void validate() { assertTrue(condition[0]); } }.await(1); fail("Should have raised AssertionError"); } catch (AssertionError e) {} }