Search in sources :

Example 96 with Invocation

use of org.mockito.invocation.Invocation in project mockito by mockito.

the class NumberOfInvocationsInOrderCheckerTest method shouldReportWithFirstUndesiredInvocationStackTrace.

@Test
public void shouldReportWithFirstUndesiredInvocationStackTrace() throws Exception {
    Invocation first = buildSimpleMethod().toInvocation();
    Invocation second = buildSimpleMethod().toInvocation();
    Invocation third = buildSimpleMethod().toInvocation();
    invocations = asList(first, second, third);
    wanted = buildSimpleMethod().toInvocationMatcher();
    exception.expect(VerificationInOrderFailure.class);
    exception.expectMessage("" + third.getLocation());
    NumberOfInvocationsChecker.checkNumberOfInvocations(invocations, wanted, 2, context);
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.junit.Test)

Example 97 with Invocation

use of org.mockito.invocation.Invocation in project mockito by mockito.

the class CallsRealMethodsTest method should_delegate_to_returns_default_when_abstract_method.

@Test
public void should_delegate_to_returns_default_when_abstract_method() throws Throwable {
    Invocation abstractMethod = new InvocationBuilder().method("booleanReturningMethod").toInvocation();
    assertThat(new CallsRealMethods().answer(abstractMethod)).isEqualTo(RETURNS_DEFAULTS.answer(abstractMethod));
}
Also used : Invocation(org.mockito.invocation.Invocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 98 with Invocation

use of org.mockito.invocation.Invocation in project mockito by mockito.

the class CallsRealMethodsTest method should_be_OK_when_calling_real_method_on_concrete_class.

@Test
public void should_be_OK_when_calling_real_method_on_concrete_class() throws Throwable {
    //given
    ArrayList<?> mock = mock(ArrayList.class);
    mock.clear();
    Invocation invocationOnClass = new MockitoCore().getLastInvocation();
    //when
    new CallsRealMethods().validateFor(invocationOnClass);
//then no exception is thrown
}
Also used : Invocation(org.mockito.invocation.Invocation) MockitoCore(org.mockito.internal.MockitoCore) Test(org.junit.Test)

Example 99 with Invocation

use of org.mockito.invocation.Invocation in project mockito by mockito.

the class InvocationInfoTest method should_know_valid_throwables.

@Test
public void should_know_valid_throwables() throws Exception {
    //when
    Invocation invocation = new InvocationBuilder().method("canThrowException").toInvocation();
    InvocationInfo info = new InvocationInfo(invocation);
    //then
    assertThat(info.isValidException(new Exception())).isFalse();
    assertThat(info.isValidException(new CharacterCodingException())).isTrue();
}
Also used : Invocation(org.mockito.invocation.Invocation) TestBase.getLastInvocation(org.mockitoutil.TestBase.getLastInvocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) CharacterCodingException(java.nio.charset.CharacterCodingException) CharacterCodingException(java.nio.charset.CharacterCodingException) Test(org.junit.Test)

Example 100 with Invocation

use of org.mockito.invocation.Invocation in project mockito by mockito.

the class ReturnsArgumentAtTest method should_handle_returning_vararg_as_array.

@Test
public void should_handle_returning_vararg_as_array() throws Throwable {
    Invocation mixedVarargsReturningStringArray = new InvocationBuilder().method("mixedVarargsReturningStringArray").argTypes(Object.class, String[].class).args(new Object(), new String[] { "A", "B", "C" }).toInvocation();
    new ReturnsArgumentAt(1).validateFor(mixedVarargsReturningStringArray);
    assertThat(new ReturnsArgumentAt(1).answer(mixedVarargsReturningStringArray)).isEqualTo(new String[] { "A", "B", "C" });
    Invocation mixedVarargsReturningObjectArray = new InvocationBuilder().method("mixedVarargsReturningStringArray").argTypes(Object.class, String[].class).args(new Object(), new String[] { "A", "B", "C" }).toInvocation();
    new ReturnsArgumentAt(1).validateFor(mixedVarargsReturningObjectArray);
    assertThat(new ReturnsArgumentAt(1).answer(mixedVarargsReturningObjectArray)).isEqualTo(new String[] { "A", "B", "C" });
}
Also used : Invocation(org.mockito.invocation.Invocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Aggregations

Invocation (org.mockito.invocation.Invocation)106 Test (org.junit.Test)71 InvocationBuilder (org.mockito.internal.invocation.InvocationBuilder)28 MatchableInvocation (org.mockito.invocation.MatchableInvocation)19 InvocationMatcher (org.mockito.internal.invocation.InvocationMatcher)11 Location (org.mockito.invocation.Location)7 InvocationsFinder.getLastLocation (org.mockito.internal.invocation.InvocationsFinder.getLastLocation)6 Returns (org.mockito.internal.stubbing.answers.Returns)6 VerificationDataInOrderImpl (org.mockito.internal.verification.api.VerificationDataInOrderImpl)6 Method (java.lang.reflect.Method)5 Discrepancy (org.mockito.internal.reporting.Discrepancy)4 MissingInvocationChecker.checkMissingInvocation (org.mockito.internal.verification.checkers.MissingInvocationChecker.checkMissingInvocation)4 VerificationInOrderFailure (org.mockito.exceptions.verification.VerificationInOrderFailure)3 InvocationsFinder.findFirstMatchingUnverifiedInvocation (org.mockito.internal.invocation.InvocationsFinder.findFirstMatchingUnverifiedInvocation)3 InOrderContextImpl (org.mockito.internal.verification.InOrderContextImpl)3 IMethods (org.mockitousage.IMethods)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 LinkedList (java.util.LinkedList)2 TestCase.assertEquals (junit.framework.TestCase.assertEquals)2 MockingDetails (org.mockito.MockingDetails)2