use of org.mockito.invocation.Invocation in project mockito by mockito.
the class ScenarioPrinterTest method shouldNotPrintInvocationsWhenSingleUnwanted.
@Test
public void shouldNotPrintInvocationsWhenSingleUnwanted() {
//given
Invocation unverified = new InvocationBuilder().differentMethod().toInvocation();
//when
String out = sp.print((List) asList(unverified));
//then
assertThat(out).contains("Actually, above is the only interaction with this mock.");
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class CallsRealMethodsTest method should_fail_when_calling_real_method_on_interface.
@Test
public void should_fail_when_calling_real_method_on_interface() throws Throwable {
//given
Invocation invocationOnInterface = new InvocationBuilder().method("simpleMethod").toInvocation();
try {
//when
new CallsRealMethods().validateFor(invocationOnInterface);
//then
Assertions.fail("can not invoke interface");
} catch (MockitoException expected) {
}
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class CallsRealMethodsTest method should_invoke_real_method.
@Test
public void should_invoke_real_method() throws Throwable {
class Concrete {
void concrete() {
throw new RuntimeException("real code");
}
}
Concrete mock = mock(Concrete.class);
Invocation concrete = new InvocationBuilder().mock(mock).method(Concrete.class.getDeclaredMethod("concrete")).toInvocation();
try {
new CallsRealMethods().answer(concrete);
} catch (RuntimeException throwable) {
throwable.printStackTrace();
assertThat(throwable).hasMessage("real code");
}
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class DefaultRegisteredInvocationsTest method should_not_return_to_string_method.
@Test
public void should_not_return_to_string_method() throws Exception {
Invocation toString = new InvocationBuilder().method("toString").toInvocation();
Invocation simpleMethod = new InvocationBuilder().simpleMethod().toInvocation();
invocations.add(toString);
invocations.add(simpleMethod);
assertTrue(invocations.getAll().contains(simpleMethod));
assertFalse(invocations.getAll().contains(toString));
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class NoMoreInteractionsTest method shouldVerifyInOrderMultipleInvoctions.
@Test
public void shouldVerifyInOrderMultipleInvoctions() {
//given
NoMoreInteractions n = new NoMoreInteractions();
Invocation i = new InvocationBuilder().seq(1).toInvocation();
Invocation i2 = new InvocationBuilder().seq(2).toInvocation();
//when
context.markVerified(i2);
//then no exception is thrown
n.verifyInOrder(new VerificationDataInOrderImpl(context, asList(i, i2), null));
}
Aggregations