use of org.mockito.invocation.Invocation in project mockito by mockito.
the class InvocationImplTest method shouldBeAbleToCallRealMethod.
@Test
public void shouldBeAbleToCallRealMethod() throws Throwable {
//when
Invocation invocation = invocationOf(Foo.class, "bark", new RealMethod() {
public Object invoke(Object target, Object[] arguments) throws Throwable {
return new Foo().bark();
}
});
//then
assertEquals("woof", invocation.callRealMethod());
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class InOrderImplTest method shouldMarkVerifiedInOrder.
@Test
public void shouldMarkVerifiedInOrder() throws Exception {
//given
InOrderImpl impl = new InOrderImpl(singletonList(mock));
Invocation i = new InvocationBuilder().toInvocation();
assertFalse(impl.isVerified(i));
//when
impl.markVerified(i);
//then
assertTrue(impl.isVerified(i));
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class InvocationContainerImplStubbingTest method should_get_results_for_methods_stub_only.
@Test
public void should_get_results_for_methods_stub_only() throws Throwable {
invocationContainerImplStubOnly.setInvocationForPotentialStubbing(new InvocationMatcher(simpleMethod));
invocationContainerImplStubOnly.addAnswer(new Returns("simpleMethod"));
Invocation differentMethod = new InvocationBuilder().differentMethod().toInvocation();
invocationContainerImplStubOnly.setInvocationForPotentialStubbing(new InvocationMatcher(differentMethod));
invocationContainerImplStubOnly.addAnswer(new ThrowsException(new MyException()));
assertEquals("simpleMethod", invocationContainerImplStubOnly.answerTo(simpleMethod));
try {
invocationContainerImplStubOnly.answerTo(differentMethod);
fail();
} catch (MyException e) {
}
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class InvocationContainerImplStubbingTest method should_get_results_for_methods.
@Test
public void should_get_results_for_methods() throws Throwable {
invocationContainerImpl.setInvocationForPotentialStubbing(new InvocationMatcher(simpleMethod));
invocationContainerImpl.addAnswer(new Returns("simpleMethod"));
Invocation differentMethod = new InvocationBuilder().differentMethod().toInvocation();
invocationContainerImpl.setInvocationForPotentialStubbing(new InvocationMatcher(differentMethod));
invocationContainerImpl.addAnswer(new ThrowsException(new MyException()));
assertEquals("simpleMethod", invocationContainerImpl.answerTo(simpleMethod));
try {
invocationContainerImpl.answerTo(differentMethod);
fail();
} catch (MyException e) {
}
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class AtLeastXNumberOfInvocationsCheckerTest method shouldMarkActualInvocationsAsVerifiedInOrder.
@Test
public void shouldMarkActualInvocationsAsVerifiedInOrder() {
InOrderContext context = new InOrderContextImpl();
//given
Invocation invocation = new InvocationBuilder().simpleMethod().toInvocation();
Invocation invocationTwo = new InvocationBuilder().differentMethod().toInvocation();
//when
checkAtLeastNumberOfInvocations(asList(invocation, invocationTwo), new InvocationMatcher(invocation), 1, context);
//then
assertThat(invocation.isVerified()).isTrue();
}
Aggregations