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 ThrowsExceptionTest method should_raise_wanted_throwable.
@Test
public void should_raise_wanted_throwable() throws Throwable {
try {
new ThrowsException(new IllegalStateException("my dear throwable")).answer(new InvocationBuilder().method("canThrowException").toInvocation());
Assertions.fail("should have raised wanted exception");
} catch (Throwable throwable) {
assertThat(throwable).isInstanceOf(IllegalStateException.class).hasMessage("my dear throwable");
}
}
use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class ThrowsExceptionTest method should_throw_mock_exception_without_stacktrace.
@Test
public void should_throw_mock_exception_without_stacktrace() throws Exception {
try {
new ThrowsException(mock(Exception.class)).answer(new InvocationBuilder().method("canThrowException").toInvocation());
Assertions.fail("should have raised wanted exception");
} catch (Throwable throwable) {
assertThat(throwable.getStackTrace()).describedAs("no stack trace, it's mock").isNull();
}
}
use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.
the class AtLeastXNumberOfInvocationsCheckerTest method shouldReportTooLittleInvocationsInOrder.
@Test
public void shouldReportTooLittleInvocationsInOrder() {
InOrderContext context = new InOrderContextImpl();
//given
Invocation invocation = new InvocationBuilder().simpleMethod().toInvocation();
Invocation invocationTwo = new InvocationBuilder().differentMethod().toInvocation();
exception.expect(VerificationInOrderFailure.class);
exception.expectMessage("iMethods.simpleMethod()");
exception.expectMessage("Wanted *at least* 2 times");
exception.expectMessage("But was 1 time");
//when
checkAtLeastNumberOfInvocations(asList(invocation, invocationTwo), new InvocationMatcher(invocation), 2, context);
}
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);
}
Aggregations