@Test public void waitForMultiple() { int toWaitFor = 10; waitFor(10); AtomicInteger cnt = new AtomicInteger(); for (int i = 0; i < toWaitFor; i++) { executor.execute(() -> { cnt.incrementAndGet(); complete(); }); } await(); assertEquals(toWaitFor, cnt.get()); }
@Test public void testTimeout() { long timeout = 5000; long start = System.currentTimeMillis(); try { await(timeout, TimeUnit.MILLISECONDS); } catch (IllegalStateException error) { long now = System.currentTimeMillis(); assertTrue(error.getMessage().startsWith("Timed out in waiting for test complete")); long delay = now - start; assertTrue(delay >= timeout); assertTrue(delay < timeout * 1.5); } }
@Test public void testFailFromOtherThread() { String msg = "too many aardvarks!"; executor.execute(() -> { fail(msg); testComplete(); }); try { await(); } catch (AssertionError error) { assertTrue(error.getMessage().equals(msg)); } }
@Test public void testAssertionPassedFromOtherThread() { executor.execute(() -> { assertEquals("foo", "foo"); testComplete(); }); await(); }
@Test public void testAssertionFailedFromOtherThread() { executor.execute(() -> { assertEquals("foo", "bar"); testComplete(); }); try { await(); } catch (ComparisonFailure error) { assertTrue(error.getMessage().startsWith("expected:")); } }
@Test public void testSuccessfulCompletion() { executor.execute(() -> { assertEquals("foo", "foo"); assertFalse(false); testComplete(); }); await(); }
@Test public void testTestCompleteCalledMultipleTimes() { executor.execute(() -> { assertEquals("foo", "foo"); testComplete(); try { testComplete(); } catch (IllegalStateException e) { //OK } }); await(); }
@Test public void testAssertionPassedFromMainThread() { assertEquals("foo", "foo"); testComplete(); await(); }
@Test public void testAssertionFailedFromOtherThreadAwaitBeforeAssertAndTestComplete() { executor.execute(() -> { //Pause to make sure await() is called before assertion and testComplete try { Thread.sleep(1000); } catch (InterruptedException e) { fail(e.getMessage()); } assertEquals("foo", "bar"); testComplete(); }); try { await(); } catch (ComparisonFailure error) { assertTrue(error.getMessage().startsWith("expected:")); } }
@Test public void increaseToWait() { int toWaitFor = 10; waitFor(3); complete(); complete(); waitForMore(9); AtomicInteger cnt = new AtomicInteger(); for (int i = 0; i < toWaitFor; i++) { executor.execute(() -> { cnt.incrementAndGet(); complete(); }); } await(); assertEquals(toWaitFor, cnt.get()); }
@Test public void testTimeout() { long timeout = 5000; long start = System.currentTimeMillis(); try { await(timeout, TimeUnit.MILLISECONDS); } catch (IllegalStateException error) { long now = System.currentTimeMillis(); assertTrue(error.getMessage().startsWith("Timed out in waiting for test complete")); long delay = now - start; assertTrue(delay >= timeout); assertTrue(delay < timeout * 1.5); } }
@Test public void waitForMultiple() { int toWaitFor = 10; waitFor(10); AtomicInteger cnt = new AtomicInteger(); for (int i = 0; i < toWaitFor; i++) { executor.execute(() -> { cnt.incrementAndGet(); complete(); }); } await(); assertEquals(toWaitFor, cnt.get()); }
@Test public void testFailFromOtherThread() { String msg = "too many aardvarks!"; executor.execute(() -> { fail(msg); testComplete(); }); try { await(); } catch (AssertionError error) { assertTrue(error.getMessage().equals(msg)); } }
@Test public void testAssertionPassedFromOtherThread() { executor.execute(() -> { assertEquals("foo", "foo"); testComplete(); }); await(); }
@Test public void testSuccessfulCompletion() { executor.execute(() -> { assertEquals("foo", "foo"); assertFalse(false); testComplete(); }); await(); }
@Test public void testAssertionFailedFromOtherThread() { executor.execute(() -> { assertEquals("foo", "bar"); testComplete(); }); try { await(); } catch (ComparisonFailure error) { assertTrue(error.getMessage().startsWith("expected:")); } }
@Test public void testAssertionPassedFromMainThread() { assertEquals("foo", "foo"); testComplete(); await(); }
@Test public void testTestCompleteCalledMultipleTimes() { executor.execute(() -> { assertEquals("foo", "foo"); testComplete(); try { testComplete(); } catch (IllegalStateException e) { //OK } }); await(); }