use of org.mockito.exceptions.base.MockitoAssertionError in project mockito by mockito.
the class VerificationOverTimeImpl method verify.
/**
* Verify the given ongoing verification data, and confirm that it satisfies the delegate verification mode
* before the full duration has passed.
*
* In practice, this polls the delegate verification mode until it is satisfied. If it is not satisfied once
* the full duration has passed, the last error returned by the delegate verification mode will be thrown
* here in turn. This may be thrown early if the delegate is unsatisfied and the verification mode is known
* to never recover from this situation (e.g. {@link AtMost}).
*
* If it is satisfied before the full duration has passed, behaviour is dependent on the returnOnSuccess parameter
* given in the constructor. If true, this verification mode is immediately satisfied once the delegate is. If
* false, this verification mode is not satisfied until the delegate is satisfied and the full time has passed.
*
* @throws MockitoAssertionError if the delegate verification mode does not succeed before the timeout
*/
public void verify(VerificationData data) {
AssertionError error = null;
timer.start();
while (timer.isCounting()) {
try {
delegate.verify(data);
if (returnOnSuccess) {
return;
} else {
error = null;
}
} catch (MockitoAssertionError e) {
error = handleVerifyException(e);
} catch (AssertionError e) {
error = handleVerifyException(e);
}
}
if (error != null) {
throw error;
}
}
use of org.mockito.exceptions.base.MockitoAssertionError in project mockito by mockito.
the class OnlyTest method shouldNotMarkAsVerifiedWhenAssertionFailed.
@Test
public void shouldNotMarkAsVerifiedWhenAssertionFailed() {
//given
Invocation invocation = new InvocationBuilder().toInvocation();
assertFalse(invocation.isVerified());
//when
try {
only.verify(new VerificationDataStub(new InvocationBuilder().toInvocationMatcher(), invocation));
fail();
} catch (MockitoAssertionError e) {
}
//then
assertFalse(invocation.isVerified());
}
use of org.mockito.exceptions.base.MockitoAssertionError in project mockito by mockito.
the class VerificationCollectorImplTest method should_collect_multiple_verification_failures.
@Test
public void should_collect_multiple_verification_failures() {
VerificationCollector collector = MockitoJUnit.collector().assertLazily();
IMethods methods = mock(IMethods.class);
verify(methods).simpleMethod();
verify(methods).byteReturningMethod();
try {
collector.collectAndReport();
fail();
} catch (MockitoAssertionError error) {
assertThat(error).hasMessageContaining("1. Wanted but not invoked:");
assertThat(error).hasMessageContaining("2. Wanted but not invoked:");
}
}
use of org.mockito.exceptions.base.MockitoAssertionError in project powermock by powermock.
the class VerifyNoMoreInteractionsTest method verifyNoMoreInteractionsOnNewInstancesThrowsAssertionErrorWhenMoreInteractionsTookPlace.
@Test
public void verifyNoMoreInteractionsOnNewInstancesThrowsAssertionErrorWhenMoreInteractionsTookPlace() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock = mock(MyClass.class);
whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock);
tested.simpleMultipleNew();
try {
verifyNoMoreInteractions(MyClass.class);
fail("Should throw exception!");
} catch (MockitoAssertionError e) {
assertTrue(e.getMessage().startsWith("\nNo interactions wanted here:\n-> at samples.powermockito.junit4.verifynomoreinteractions.VerifyNoMoreInteractionsTest.verifyNoMoreInteractionsOnNewInstancesThrowsAssertionErrorWhenMoreInteractionsTookPlace(VerifyNoMoreInteractionsTest.java:"));
}
}
use of org.mockito.exceptions.base.MockitoAssertionError in project powermock by powermock.
the class MockitoMethodInvocationControl method verifyNoMoreInteractions.
public void verifyNoMoreInteractions() {
try {
final MockHandler mockHandler = methodInterceptorFilter.getHandler();
if (mockHandler instanceof MockHandler) {
InvocationContainer invocationContainer = Whitebox.invokeMethod(mockHandler, "getInvocationContainer");
VerificationDataImpl data = new VerificationDataImpl(invocationContainer, null);
VerificationModeFactory.noMoreInteractions().verify(data);
} else {
throw new RuntimeException("Cannot perform verifyNoMoreInteractions because of unknown mockhandler type " + mockHandler.getClass());
}
} catch (MockitoAssertionError e) {
InvocationControlAssertionError.updateErrorMessageForVerifyNoMoreInteractions(e);
throw e;
} catch (Exception e) {
throw new RuntimeException("PowerMock internal error", e);
}
}
Aggregations