diff --git a/src/main/java/org/mockito/Mockito.java b/src/main/java/org/mockito/Mockito.java index aea283881e..af1ceb22e9 100644 --- a/src/main/java/org/mockito/Mockito.java +++ b/src/main/java/org/mockito/Mockito.java @@ -4,8 +4,6 @@ */ package org.mockito; -import java.time.Duration; - import org.mockito.exceptions.misusing.PotentialStubbingProblem; import org.mockito.exceptions.misusing.UnnecessaryStubbingException; import org.mockito.internal.InternalMockHandler; @@ -888,15 +886,15 @@ *
* //passes when someMethod() is called no later than within 100 ms
* //exits immediately when verification is satisfied (e.g. may not wait full 100 ms)
- * verify(mock, timeout(Duration.ofMillis(100))).someMethod();
+ * verify(mock, timeout(100)).someMethod();
* //above is an alias to:
- * verify(mock, timeout(Duration.ofMillis(100)).times(1)).someMethod();
+ * verify(mock, timeout(100).times(1)).someMethod();
*
* //passes as soon as someMethod() has been called 2 times under 100 ms
- * verify(mock, timeout(Duration.ofMillis(100)).times(2)).someMethod();
+ * verify(mock, timeout(100).times(2)).someMethod();
*
* //equivalent: this also passes as soon as someMethod() has been called 2 times under 100 ms
- * verify(mock, timeout(Duration.ofMillis(100)).atLeast(2)).someMethod();
+ * verify(mock, timeout(100).atLeast(2)).someMethod();
*
*
*
@@ -2848,45 +2846,10 @@ public static VerificationMode only() {
* @param millis - duration in milliseconds
*
* @return object that allows fluent specification of the verification (times(x), atLeast(y), etc.)
- * @deprecated Use {@link #timeout(Duration)} instead.
*/
@CheckReturnValue
- @Deprecated
public static VerificationWithTimeout timeout(long millis) {
- return timeout(Duration.ofMillis(millis));
- }
-
- /**
- * Verification will be triggered over and over until the given amount of time, allowing testing of async code.
- * Useful when interactions with the mock object did not happened yet.
- * Extensive use of {@code timeout()} method can be a code smell - there are better ways of testing concurrent code.
- * - * See also {@link #after(Duration)} method for testing async code. - * Differences between {@code timeout()} and {@code after} are explained in Javadoc for {@link #after(Duration)}. - * - *
- * //passes when someMethod() is called no later than within 100 ms
- * //exits immediately when verification is satisfied (e.g. may not wait full 100 ms)
- * verify(mock, timeout(Duration.ofMillis(100))).someMethod();
- * //above is an alias to:
- * verify(mock, timeout(Duration.ofMillis(100)).times(1)).someMethod();
- *
- * //passes as soon as someMethod() has been called 2 times under 100 ms
- * verify(mock, timeout(Duration.ofMillis(100)).times(2)).someMethod();
- *
- * //equivalent: this also passes as soon as someMethod() has been called 2 times under 100 ms
- * verify(mock, timeout(Duration.ofMillis(100)).atLeast(2)).someMethod();
- *
- *
- * See examples in javadoc for {@link Mockito} class
- *
- * @param timeout how long to wait before timing out
- *
- * @return object that allows fluent specification of the verification (times(x), atLeast(y), etc.)
- */
- @CheckReturnValue
- public static VerificationWithTimeout timeout(Duration timeout) {
- return new Timeout(timeout, VerificationModeFactory.times(1));
+ return new Timeout(millis, VerificationModeFactory.times(1));
}
/**
@@ -2926,7 +2889,7 @@ public static VerificationWithTimeout timeout(Duration timeout) {
* //1.
* mock.foo();
* verify(mock, after(1000)).foo();
- * //waits 1 second and succeeds
+ * //waits 1000 millis and succeeds
*
* //2.
* mock.foo();
@@ -2939,68 +2902,10 @@ public static VerificationWithTimeout timeout(Duration timeout) {
* @param millis - duration in milliseconds
*
* @return object that allows fluent specification of the verification
- * @deprecated Use {@link #after(Duration)} instead.
*/
@CheckReturnValue
- @Deprecated
public static VerificationAfterDelay after(long millis) {
- return after(Duration.ofMillis(millis));
- }
-
- /**
- * Verification will be triggered after given amount of time, allowing testing of async code.
- * Useful when interactions with the mock object did not happened yet.
- * Extensive use of {@code after()} method can be a code smell - there are better ways of testing concurrent code.
- * - * Not yet implemented to work with InOrder verification. - *
- * See also {@link #timeout(Duration)} method for testing async code. - * Differences between {@code timeout()} and {@code after()} are explained below. - * - *
- * //passes after 100ms, if someMethod() has only been called once at that time.
- * verify(mock, after(Duration.ofMillis(100))).someMethod();
- * //above is an alias to:
- * verify(mock, after(Duration.ofMillis(100)).times(1)).someMethod();
- *
- * //passes if someMethod() is called *exactly* 2 times, as tested after 100 millis
- * verify(mock, after(Duration.ofMillis(100)).times(2)).someMethod();
- *
- * //passes if someMethod() has not been called, as tested after 100 millis
- * verify(mock, after(Duration.ofMillis(100)).never()).someMethod();
- *
- * //verifies someMethod() after a given time span using given verification mode
- * //useful only if you have your own custom verification modes.
- * verify(mock, new After(Duration.ofMillis(100), yourOwnVerificationMode)).someMethod();
- *
- *
- * timeout() vs. after()
- *
- * //1.
- * mock.foo();
- * verify(mock, after(Duration.ofSeconds(1))).foo();
- * //waits 1 second and succeeds
- *
- * //2.
- * mock.foo();
- * verify(mock, timeout(Duration.ofSeconds(1))).foo();
- * //succeeds immediately
- *
- *
- * See examples in javadoc for {@link Mockito} class
- *
- * @param delay how to to wait before triggering verification
- *
- * @return object that allows fluent specification of the verification
- */
- @CheckReturnValue
- public static VerificationAfterDelay after(Duration delay) {
- return new After(delay, VerificationModeFactory.times(1));
+ return new After(millis, VerificationModeFactory.times(1));
}
/**
diff --git a/src/main/java/org/mockito/internal/exceptions/Reporter.java b/src/main/java/org/mockito/internal/exceptions/Reporter.java
index db8bbbeacc..f661b81e5c 100644
--- a/src/main/java/org/mockito/internal/exceptions/Reporter.java
+++ b/src/main/java/org/mockito/internal/exceptions/Reporter.java
@@ -10,7 +10,6 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
-import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -864,12 +863,12 @@ public static MockitoException usingConstructorWithFancySerializable(Serializabl
return new MockitoException("Mocks instantiated with constructor cannot be combined with " + mode + " serialization mode.");
}
- public static MockitoException cannotCreateTimerWithNegativeDurationTime(Duration duration) {
+ public static MockitoException cannotCreateTimerWithNegativeDurationTime(long durationMillis) {
return new FriendlyReminderException(join(
"",
"Don't panic! I'm just a friendly reminder!",
"It is impossible for time to go backward, therefore...",
- "You cannot put negative value of duration: (" + duration + ")",
+ "You cannot put negative value of duration: (" + durationMillis + ")",
"as argument of timer methods (after(), timeout())",
""
));
diff --git a/src/main/java/org/mockito/internal/util/Timer.java b/src/main/java/org/mockito/internal/util/Timer.java
index 650e887660..783f580c92 100644
--- a/src/main/java/org/mockito/internal/util/Timer.java
+++ b/src/main/java/org/mockito/internal/util/Timer.java
@@ -6,42 +6,38 @@
import static org.mockito.internal.exceptions.Reporter.cannotCreateTimerWithNegativeDurationTime;
-import java.time.Duration;
-import java.time.Instant;
-
public class Timer {
- private final Duration duration;
- private Instant startTime = null;
+ private final long durationMillis;
+ private long startTime = -1;
- public Timer(Duration duration) {
- validateInput(duration);
- this.duration = duration;
+ public Timer(long durationMillis) {
+ validateInput(durationMillis);
+ this.durationMillis = durationMillis;
}
/**
* Informs whether the timer is still counting down.
*/
public boolean isCounting() {
- assert startTime != null;
- Duration elapsed = Duration.between(startTime, Instant.now());
- return elapsed.compareTo(duration) <= 0;
+ assert startTime != -1;
+ return System.currentTimeMillis() - startTime <= durationMillis;
}
/**
* Starts the timer count down.
*/
public void start() {
- startTime = Instant.now();
+ startTime = System.currentTimeMillis();
}
- private void validateInput(Duration duration) {
- if (duration.isNegative()) {
- throw cannotCreateTimerWithNegativeDurationTime(duration);
+ private void validateInput(long durationMillis) {
+ if (durationMillis < 0) {
+ throw cannotCreateTimerWithNegativeDurationTime(durationMillis);
}
}
- public Duration duration() {
- return duration;
+ public long duration() {
+ return durationMillis;
}
}
diff --git a/src/main/java/org/mockito/internal/verification/VerificationOverTimeImpl.java b/src/main/java/org/mockito/internal/verification/VerificationOverTimeImpl.java
index edcf77cf62..24ec61a90d 100644
--- a/src/main/java/org/mockito/internal/verification/VerificationOverTimeImpl.java
+++ b/src/main/java/org/mockito/internal/verification/VerificationOverTimeImpl.java
@@ -4,8 +4,6 @@
*/
package org.mockito.internal.verification;
-import java.time.Duration;
-
import org.mockito.exceptions.base.MockitoAssertionError;
import org.mockito.internal.util.Timer;
import org.mockito.internal.verification.api.VerificationData;
@@ -13,12 +11,12 @@
/**
* Verifies that another verification mode (the delegate) is satisfied within a certain timeframe
- * (before timeout has passed, measured from the call to verify()), and either returns immediately
+ * (before timeoutMillis has passed, measured from the call to verify()), and either returns immediately
* once it does, or waits until it is definitely satisfied once the full time has passed.
*/
public class VerificationOverTimeImpl implements VerificationMode {
- private final Duration pollingPeriod;
+ private final long pollingPeriodMillis;
private final VerificationMode delegate;
private final boolean returnOnSuccess;
private final Timer timer;
@@ -26,22 +24,22 @@ public class VerificationOverTimeImpl implements VerificationMode {
/**
* Create this verification mode, to be used to verify invocation ongoing data later.
*
- * @param pollingPeriod The frequency to poll delegate.verify(), to check whether the delegate has been satisfied
- * @param duration The max time to wait for the delegate verification mode to be satisfied
+ * @param pollingPeriodMillis The frequency to poll delegate.verify(), to check whether the delegate has been satisfied
+ * @param durationMillis The max time to wait (in millis) for the delegate verification mode to be satisfied
* @param delegate The verification mode to delegate overall success or failure to
* @param returnOnSuccess Whether to immediately return successfully once the delegate is satisfied (as in
* {@link org.mockito.verification.VerificationWithTimeout}, or to only return once
* the delegate is satisfied and the full duration has passed (as in
* {@link org.mockito.verification.VerificationAfterDelay}).
*/
- public VerificationOverTimeImpl(Duration pollingPeriod, Duration duration, VerificationMode delegate, boolean returnOnSuccess) {
- this(pollingPeriod, delegate, returnOnSuccess, new Timer(duration));
+ public VerificationOverTimeImpl(long pollingPeriodMillis, long durationMillis, VerificationMode delegate, boolean returnOnSuccess) {
+ this(pollingPeriodMillis, delegate, returnOnSuccess, new Timer(durationMillis));
}
/**
* Create this verification mode, to be used to verify invocation ongoing data later.
*
- * @param pollingPeriod The frequency to poll delegate.verify(), to check whether the delegate has been satisfied
+ * @param pollingPeriodMillis The frequency to poll delegate.verify(), to check whether the delegate has been satisfied
* @param delegate The verification mode to delegate overall success or failure to
* @param returnOnSuccess Whether to immediately return successfully once the delegate is satisfied (as in
* {@link org.mockito.verification.VerificationWithTimeout}, or to only return once
@@ -49,8 +47,8 @@ public VerificationOverTimeImpl(Duration pollingPeriod, Duration duration, Verif
* {@link org.mockito.verification.VerificationAfterDelay}).
* @param timer Checker of whether the duration of the verification is still acceptable
*/
- public VerificationOverTimeImpl(Duration pollingPeriod, VerificationMode delegate, boolean returnOnSuccess, Timer timer) {
- this.pollingPeriod = pollingPeriod;
+ public VerificationOverTimeImpl(long pollingPeriodMillis, VerificationMode delegate, boolean returnOnSuccess, Timer timer) {
+ this.pollingPeriodMillis = pollingPeriodMillis;
this.delegate = delegate;
this.returnOnSuccess = returnOnSuccess;
this.timer = timer;
@@ -99,7 +97,7 @@ public void verify(VerificationData data) {
private AssertionError handleVerifyException(AssertionError e) {
if (canRecoverFromFailure(delegate)) {
- sleep(pollingPeriod);
+ sleep(pollingPeriodMillis);
return e;
} else {
throw e;
@@ -111,12 +109,12 @@ protected boolean canRecoverFromFailure(VerificationMode verificationMode) {
}
public VerificationOverTimeImpl copyWithVerificationMode(VerificationMode verificationMode) {
- return new VerificationOverTimeImpl(pollingPeriod, timer.duration(), verificationMode, returnOnSuccess);
+ return new VerificationOverTimeImpl(pollingPeriodMillis, timer.duration(), verificationMode, returnOnSuccess);
}
- private void sleep(Duration sleep) {
+ private void sleep(long sleep) {
try {
- Thread.sleep(sleep.toMillis());
+ Thread.sleep(sleep);
} catch (InterruptedException ie) {
throw new RuntimeException("Thread sleep has been interrupted", ie);
}
@@ -126,8 +124,8 @@ public boolean isReturnOnSuccess() {
return returnOnSuccess;
}
- public Duration getPollingPeriod() {
- return pollingPeriod;
+ public long getPollingPeriodMillis() {
+ return pollingPeriodMillis;
}
public Timer getTimer() {
diff --git a/src/main/java/org/mockito/internal/verification/VerificationWrapperInOrderWrapper.java b/src/main/java/org/mockito/internal/verification/VerificationWrapperInOrderWrapper.java
index 0f3845b6cd..87d9076e00 100644
--- a/src/main/java/org/mockito/internal/verification/VerificationWrapperInOrderWrapper.java
+++ b/src/main/java/org/mockito/internal/verification/VerificationWrapperInOrderWrapper.java
@@ -35,7 +35,7 @@ private VerificationMode wrapInOrder(VerificationWrapper> verificationWrapper,
if (verificationMode instanceof VerificationOverTimeImpl) {
final VerificationOverTimeImpl verificationOverTime = (VerificationOverTimeImpl)verificationMode;
if (verificationOverTime.isReturnOnSuccess()) {
- return new VerificationOverTimeImpl(verificationOverTime.getPollingPeriod(),
+ return new VerificationOverTimeImpl(verificationOverTime.getPollingPeriodMillis(),
verificationOverTime.getTimer().duration(),
wrapInOrder(verificationWrapper, verificationOverTime.getDelegate(), inOrder),
verificationOverTime.isReturnOnSuccess());
diff --git a/src/main/java/org/mockito/verification/After.java b/src/main/java/org/mockito/verification/After.java
index a65a244ef7..54d7453022 100644
--- a/src/main/java/org/mockito/verification/After.java
+++ b/src/main/java/org/mockito/verification/After.java
@@ -4,8 +4,6 @@
*/
package org.mockito.verification;
-import java.time.Duration;
-
import org.mockito.internal.verification.VerificationOverTimeImpl;
import org.mockito.internal.verification.VerificationWrapper;
@@ -22,25 +20,13 @@ public class After extends VerificationWrapper* Typically, you won't use this class explicitly. Instead use timeout() method on Mockito class. * See javadoc for {@link VerificationWithTimeout} - * @deprecated Use {@link After#After(Duration, VerificationMode)} instead. */ - @Deprecated public After(long delayMillis, VerificationMode verificationMode) { - this(Duration.ofMillis(delayMillis), verificationMode); - } - - /** - * See the javadoc for {@link VerificationAfterDelay} - *
- * Typically, you won't use this class explicitly. Instead use timeout() method on Mockito class.
- * See javadoc for {@link VerificationWithTimeout}
- */
- public After(Duration delay, VerificationMode verificationMode) {
- this(Duration.ofMillis(10), delay, verificationMode);
+ this(10, delayMillis, verificationMode);
}
- After(Duration pollingPeriod, Duration delay, VerificationMode verificationMode) {
- this(new VerificationOverTimeImpl(pollingPeriod, delay, verificationMode, false));
+ After(long pollingPeriod, long delayMillis, VerificationMode verificationMode) {
+ this(new VerificationOverTimeImpl(pollingPeriod, delayMillis, verificationMode, false));
}
After(VerificationOverTimeImpl verificationOverTime) {
diff --git a/src/main/java/org/mockito/verification/Timeout.java b/src/main/java/org/mockito/verification/Timeout.java
index b7679abf26..99dcc45f53 100644
--- a/src/main/java/org/mockito/verification/Timeout.java
+++ b/src/main/java/org/mockito/verification/Timeout.java
@@ -6,8 +6,6 @@
import static org.mockito.internal.exceptions.Reporter.atMostAndNeverShouldNotBeUsedWithTimeout;
-import java.time.Duration;
-
import org.mockito.internal.util.Timer;
import org.mockito.internal.verification.VerificationOverTimeImpl;
import org.mockito.internal.verification.VerificationWrapper;
@@ -25,35 +23,23 @@ public class Timeout extends VerificationWrapper
* Typically, you won't use this class explicitly. Instead use timeout() method on Mockito class.
* See javadoc for {@link VerificationWithTimeout}
- * @deprecated Use {@link Timeout#Timeout(Duration, VerificationMode)} instead.
*/
- @Deprecated
public Timeout(long millis, VerificationMode delegate) {
- this(Duration.ofMillis(millis), delegate);
- }
-
- /**
- * See the javadoc for {@link VerificationWithTimeout}
- *
- * Typically, you won't use this class explicitly. Instead use timeout() method on Mockito class.
- * See javadoc for {@link VerificationWithTimeout}
- */
- public Timeout(Duration timeout, VerificationMode delegate) {
- this(Duration.ofMillis(10), timeout, delegate);
+ this(10, millis, delegate);
}
/**
* See the javadoc for {@link VerificationWithTimeout}
*/
- Timeout(Duration pollingPeriod, Duration timeout, VerificationMode delegate) {
- this(new VerificationOverTimeImpl(pollingPeriod, timeout, delegate, true));
+ Timeout(long pollingPeriodMillis, long millis, VerificationMode delegate) {
+ this(new VerificationOverTimeImpl(pollingPeriodMillis, millis, delegate, true));
}
/**
* See the javadoc for {@link VerificationWithTimeout}
*/
- Timeout(Duration pollingPeriod, VerificationMode delegate, Timer timer) {
- this(new VerificationOverTimeImpl(pollingPeriod, delegate, true, timer));
+ Timeout(long pollingPeriodMillis, VerificationMode delegate, Timer timer) {
+ this(new VerificationOverTimeImpl(pollingPeriodMillis, delegate, true, timer));
}
Timeout(VerificationOverTimeImpl verificationOverTime) {
diff --git a/src/test/java/org/mockito/internal/util/TimerTest.java b/src/test/java/org/mockito/internal/util/TimerTest.java
index 2f2885b0da..8a4a173e02 100644
--- a/src/test/java/org/mockito/internal/util/TimerTest.java
+++ b/src/test/java/org/mockito/internal/util/TimerTest.java
@@ -4,8 +4,6 @@
*/
package org.mockito.internal.util;
-import java.time.Duration;
-
import org.assertj.core.api.Assertions;
import org.junit.Rule;
import org.junit.Test;
@@ -20,7 +18,7 @@ public class TimerTest extends TestBase {
@Test
public void should_return_true_if_task_is_in_acceptable_time_bounds() {
//given
- Duration duration = Duration.ofSeconds(10);
+ long duration = 10000L;
Timer timer = new Timer(duration);
//when
@@ -33,7 +31,7 @@ public void should_return_true_if_task_is_in_acceptable_time_bounds() {
@Test
public void should_return_false_when_time_run_out() throws Exception {
//given
- Timer timer = new Timer(Duration.ZERO);
+ Timer timer = new Timer(0);
timer.start();
//when
@@ -47,7 +45,7 @@ public void should_return_false_when_time_run_out() throws Exception {
public void should_throw_friendly_reminder_exception_when_duration_is_negative() {
expectedException.expect(FriendlyReminderException.class);
expectedException.expectMessage("Don't panic! I'm just a friendly reminder!");
- new Timer(Duration.ofMillis(-1));
+ new Timer(-1);
}
private void oneMillisecondPasses() throws InterruptedException {
diff --git a/src/test/java/org/mockito/internal/verification/VerificationOverTimeImplTest.java b/src/test/java/org/mockito/internal/verification/VerificationOverTimeImplTest.java
index 5f206c5420..82cceeaea7 100644
--- a/src/test/java/org/mockito/internal/verification/VerificationOverTimeImplTest.java
+++ b/src/test/java/org/mockito/internal/verification/VerificationOverTimeImplTest.java
@@ -9,8 +9,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
-import java.time.Duration;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -31,8 +29,7 @@ public class VerificationOverTimeImplTest {
@Before
public void setUp() {
initMocks(this);
- impl = new VerificationOverTimeImpl(
- Duration.ofMillis(10), Duration.ofSeconds(1), delegate, true);
+ impl = new VerificationOverTimeImpl(10, 1000, delegate, true);
}
@Test
diff --git a/src/test/java/org/mockito/verification/TimeoutTest.java b/src/test/java/org/mockito/verification/TimeoutTest.java
index 3719ae4215..ae6e5d2e84 100644
--- a/src/test/java/org/mockito/verification/TimeoutTest.java
+++ b/src/test/java/org/mockito/verification/TimeoutTest.java
@@ -7,8 +7,6 @@
import static org.junit.Assert.fail;
import static org.mockito.Mockito.*;
-import java.time.Duration;
-
import org.junit.Test;
import org.mockito.InOrder;
import org.mockito.Mock;
@@ -30,7 +28,7 @@ public class TimeoutTest extends TestBase {
@Test
public void should_pass_when_verification_passes() {
- Timeout t = new Timeout(Duration.ofMillis(1), mode, timer);
+ Timeout t = new Timeout(1, mode, timer);
when(timer.isCounting()).thenReturn(true);
doNothing().when(mode).verify(data);
@@ -44,7 +42,7 @@ public void should_pass_when_verification_passes() {
@Test
public void should_fail_because_verification_fails() {
- Timeout t = new Timeout(Duration.ofMillis(1), mode, timer);
+ Timeout t = new Timeout(1, mode, timer);
when(timer.isCounting()).thenReturn(true, true, true, false);
doThrow(error).
@@ -62,7 +60,7 @@ public void should_fail_because_verification_fails() {
@Test
public void should_pass_even_if_first_verification_fails() {
- Timeout t = new Timeout(Duration.ofMillis(1), mode, timer);
+ Timeout t = new Timeout(1, mode, timer);
when(timer.isCounting()).thenReturn(true, true, true, false);
doThrow(error).
@@ -76,7 +74,7 @@ public void should_pass_even_if_first_verification_fails() {
@Test
public void should_try_to_verify_correct_number_of_times() {
- Timeout t = new Timeout(Duration.ofMillis(10), mode, timer);
+ Timeout t = new Timeout(10, mode, timer);
doThrow(error).when(mode).verify(data);
when(timer.isCounting()).thenReturn(true, true, true, true, true, false);
diff --git a/src/test/java/org/mockitousage/verification/VerificationWithTimeoutTest.java b/src/test/java/org/mockitousage/verification/VerificationWithTimeoutTest.java
index 230b632910..0c50578f6c 100644
--- a/src/test/java/org/mockitousage/verification/VerificationWithTimeoutTest.java
+++ b/src/test/java/org/mockitousage/verification/VerificationWithTimeoutTest.java
@@ -10,7 +10,6 @@
import static org.mockito.junit.MockitoJUnit.rule;
import static org.mockitoutil.Stopwatch.createNotStarted;
-import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.assertj.core.api.Assertions;
@@ -58,17 +57,6 @@ public void should_verify_with_timeout() {
verify(mock).oneArg('c'); //sanity check
}
- @Test
- public void should_verify_with_timeout_duration() {
- // when
- async.runAfter(50, callMock('c'));
- async.runAfter(500, callMock('c'));
-
- // then
- verify(mock, timeout(Duration.ofMillis(200)).only()).oneArg('c');
- verify(mock).oneArg('c'); //sanity check
- }
-
@Test
public void should_verify_with_timeout_and_fail() {
// when
@@ -84,21 +72,6 @@ public void call() {
//TODO let's have a specific exception vs. generic assertion error + message
}
- @Test
- public void should_verify_with_timeout_and_fail_duration() {
- // when
- async.runAfter(200, callMock('c'));
-
- // then
- Assertions.assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
- @Override
- public void call() {
- verify(mock, timeout(Duration.ofMillis(50)).only()).oneArg('c');
- }
- }).isInstanceOf(AssertionError.class).hasMessageContaining("Wanted but not invoked");
- //TODO let's have a specific exception vs. generic assertion error + message
- }
-
@Test
@Ignore //TODO nice to have
public void should_verify_with_timeout_and_fail_early() {