use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class WarningsFinderTest method shouldPrintUnstubbedInvocation.
@Test
public void shouldPrintUnstubbedInvocation() {
// given
InvocationMatcher unstubbedInvocation = new InvocationBuilder().differentMethod().toInvocationMatcher();
// when
WarningsFinder finder = new WarningsFinder(Arrays.<Invocation>asList(), Arrays.<InvocationMatcher>asList(unstubbedInvocation));
finder.find(listener);
// then
verify(listener, only()).foundUnstubbed(unstubbedInvocation);
}
use of org.mockito.internal.invocation.InvocationBuilder 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.internal.invocation.InvocationBuilder 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.internal.invocation.InvocationBuilder 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.internal.invocation.InvocationBuilder in project mockito by mockito.
the class DefaultAnswerValidatorTest method should_fail_if_returned_value_of_answer_is_incompatible_with_return_type.
@Test
public void should_fail_if_returned_value_of_answer_is_incompatible_with_return_type() throws Throwable {
// given
class AWrongType {
}
try {
// when
DefaultAnswerValidator.validateReturnValueFor(new InvocationBuilder().method("toString").toInvocation(), new AWrongType());
fail("expected validation to fail");
} catch (WrongTypeOfReturnValue e) {
// then
assertThat(e.getMessage()).containsIgnoringCase("Default answer returned a result with the wrong type").containsIgnoringCase("AWrongType cannot be returned by toString()").containsIgnoringCase("toString() should return String");
}
}
Aggregations