@Test(timeout = 2000) public void awaitingForeverReturnsLongMaxValueAsRemainingTime() { final Set<Long> remainingTimes = new HashSet<Long>(); final Set<Long> elapsedTimes = new HashSet<Long>(); with() .conditionEvaluationListener(new ConditionEvaluationListener<Integer>() { public void conditionEvaluated(EvaluatedCondition<Integer> condition) { remainingTimes.add(condition.getRemainingTimeInMS()); elapsedTimes.add(condition.getElapsedTimeInMS()); } }) .forever() .until(new CountDown(10), is(equalTo(5))); assertThat(remainingTimes, everyItem(is(Long.MAX_VALUE))); assertThat(elapsedTimes, everyItem(is(not(Long.MAX_VALUE)))); }
@Test(timeout = 2000, expected = IllegalStateException.class) public void uncaughtExceptionsArePropagatedToAwaitingThreadAndBreaksForeverBlockWhenSetToCatchAllUncaughtExceptions() { catchUncaughtExceptionsByDefault(); new ExceptionThrowingAsynch(new IllegalStateException("Illegal state!")).perform(); await().forever().until(value(), equalTo(1)); }
@Test(timeout = 2000, expected = IllegalStateException.class) public void uncaughtExceptionsArePropagatedToAwaitingThreadAndBreaksForeverBlockWhenCatchingAllUncaughtExceptions() { new ExceptionThrowingAsynch(new IllegalStateException("Illegal state!")).perform(); catchUncaughtExceptions().and().await().forever().until(value(), equalTo(1)); }
@Test(timeout = 2000, expected = ComparisonFailure.class) public void uncaughtThrowablesArePropagatedToAwaitingThreadAndBreaksForeverBlockWhenSetToCatchAllUncaughtExceptions() { new ExceptionThrowingAsynch(new ComparisonFailure("Message", "Something", "Something else")).perform(); await().forever().until(value(), equalTo(1)); }
@Test(timeout = 2000) public void foreverConditionWithHamcrestMatchersWithDirectBlock() { new Asynch(fakeRepository).perform(); await().forever().until(value(), equalTo(1)); assertEquals(1, fakeRepository.getValue()); }
@Test(timeout = 2000) public void foreverConditionWithHamcrestCollectionMatchersWithDirectBlock() { new Asynch(fakeRepository).perform(); await().forever().until(valueAsList(), hasItem(1)); assertEquals(1, fakeRepository.getValue()); }
@Test(timeout = 2000) public void foreverConditionSpecificationUsingUntilWithDirectBlock() { new Asynch(fakeRepository).perform(); await().forever().until(fakeRepositoryValueEqualsOne()); assertEquals(1, fakeRepository.getValue()); }