use of org.mockito.exceptions.verification.NoInteractionsWanted in project dexmaker by linkedin.
the class GeneralMocking method verifyAdditionalInvocations.
@Test
public void verifyAdditionalInvocations() {
TestClass t = mock(TestClass.class);
t.returnA();
t.returnA();
try {
verifyNoMoreInteractions(t);
} catch (NoInteractionsWanted e) {
try {
throw new Exception();
} catch (Exception here) {
// The error message should indicate where the additional invocations have been made
assertTrue(e.getMessage(), e.getMessage().contains(here.getStackTrace()[0].getMethodName()));
}
}
}
use of org.mockito.exceptions.verification.NoInteractionsWanted in project mockito by mockito.
the class SelectedMocksInOrderVerificationTest method shouldAllowTwoTimesOnMockTwo.
@Test
public void shouldAllowTwoTimesOnMockTwo() {
InOrder inOrder = inOrder(mockTwo, mockThree);
inOrder.verify(mockTwo, times(2)).simpleMethod(2);
try {
verifyNoMoreInteractions(mockTwo);
fail();
} catch (NoInteractionsWanted e) {
}
}
use of org.mockito.exceptions.verification.NoInteractionsWanted in project mockito by mockito.
the class Reporter method noMoreInteractionsWanted.
public static MockitoAssertionError noMoreInteractionsWanted(Invocation undesired, List<VerificationAwareInvocation> invocations) {
ScenarioPrinter scenarioPrinter = new ScenarioPrinter();
String scenario = scenarioPrinter.print(invocations);
return new NoInteractionsWanted(join("No interactions wanted here:", new LocationImpl(), "But found this interaction on mock '" + MockUtil.getMockName(undesired.getMock()) + "':", undesired.getLocation(), scenario));
}
use of org.mockito.exceptions.verification.NoInteractionsWanted in project mockito by mockito.
the class Reporter method noInteractionsWanted.
public static MockitoAssertionError noInteractionsWanted(Object mock, List<VerificationAwareInvocation> invocations) {
ScenarioPrinter scenarioPrinter = new ScenarioPrinter();
String scenario = scenarioPrinter.print(invocations);
List<Location> locations = new ArrayList<>();
for (VerificationAwareInvocation invocation : invocations) {
locations.add(invocation.getLocation());
}
return new NoInteractionsWanted(join("No interactions wanted here:", new LocationImpl(), "But found these interactions on mock '" + MockUtil.getMockName(mock) + "':", join("", locations), scenario));
}
use of org.mockito.exceptions.verification.NoInteractionsWanted in project mockito by mockito.
the class NoInteractionsTest method noInteractionsExceptionMessageShouldDescribeMock.
@Test
public void noInteractionsExceptionMessageShouldDescribeMock() {
// given
NoInteractions n = new NoInteractions();
IMethods mock = mock(IMethods.class, "a mock");
InvocationMatcher i = new InvocationBuilder().mock(mock).toInvocationMatcher();
InvocationContainerImpl invocations = new InvocationContainerImpl(new MockSettingsImpl());
invocations.setInvocationForPotentialStubbing(i);
try {
// when
n.verify(new VerificationDataImpl(invocations, null));
// then
fail();
} catch (NoInteractionsWanted e) {
Assertions.assertThat(e.toString()).contains(mock.toString());
}
}
Aggregations