Search in sources :

Example 76 with Invocation

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

the class InvocationMatcherTest method should_capture_arguments_when_args_count_does_NOT_match.

// like using several time the captor in the vararg
@Test
public void should_capture_arguments_when_args_count_does_NOT_match() throws Exception {
    //given
    mock.varargs();
    Invocation invocation = getLastInvocation();
    //when
    InvocationMatcher invocationMatcher = new InvocationMatcher(invocation, (List) asList(ANY));
    //then
    invocationMatcher.captureArgumentsFrom(invocation);
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.junit.Test)

Example 77 with Invocation

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

the class InvocationMatcherTest method should_match_varargs_using_any_varargs.

@Test
public void should_match_varargs_using_any_varargs() throws Exception {
    //given
    mock.varargs("1", "2");
    Invocation invocation = getLastInvocation();
    InvocationMatcher invocationMatcher = new InvocationMatcher(invocation, (List) asList(ANY));
    //when
    boolean match = invocationMatcher.matches(invocation);
    //then
    assertTrue(match);
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.junit.Test)

Example 78 with Invocation

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

the class MockHandlerImplTest method should_remove_verification_mode_even_when_invalid_matchers.

@Test
public void should_remove_verification_mode_even_when_invalid_matchers() throws Throwable {
    // given
    Invocation invocation = new InvocationBuilder().toInvocation();
    @SuppressWarnings("rawtypes") MockHandlerImpl<?> handler = new MockHandlerImpl(new MockSettingsImpl());
    mockingProgress().verificationStarted(VerificationModeFactory.atLeastOnce());
    handler.matchersBinder = new MatchersBinder() {

        public InvocationMatcher bindMatchers(ArgumentMatcherStorage argumentMatcherStorage, Invocation invocation) {
            throw new InvalidUseOfMatchersException();
        }
    };
    try {
        // when
        handler.handle(invocation);
        // then
        fail();
    } catch (InvalidUseOfMatchersException ignored) {
    }
    assertNull(mockingProgress().pullVerificationMode());
}
Also used : InvalidUseOfMatchersException(org.mockito.exceptions.misusing.InvalidUseOfMatchersException) Invocation(org.mockito.invocation.Invocation) MatchersBinder(org.mockito.internal.invocation.MatchersBinder) MockSettingsImpl(org.mockito.internal.creation.MockSettingsImpl) InvocationMatcher(org.mockito.internal.invocation.InvocationMatcher) StubbedInvocationMatcher(org.mockito.internal.stubbing.StubbedInvocationMatcher) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) ArgumentMatcherStorage(org.mockito.internal.progress.ArgumentMatcherStorage) Test(org.junit.Test)

Example 79 with Invocation

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

the class InvocationImplTest method shouldKnowIfIsEqualTo.

@Test
public void shouldKnowIfIsEqualTo() {
    Invocation equal = new InvocationBuilder().args(" ").mock("mock").toInvocation();
    Invocation nonEqual = new InvocationBuilder().args("X").mock("mock").toInvocation();
    Invocation withNewStringInstance = new InvocationBuilder().args(new String(" ")).mock("mock").toInvocation();
    assertFalse(invocation.equals(null));
    assertFalse(invocation.equals(""));
    assertTrue(invocation.equals(equal));
    assertFalse(invocation.equals(nonEqual));
    assertTrue(invocation.equals(withNewStringInstance));
}
Also used : Invocation(org.mockito.invocation.Invocation) Test(org.junit.Test)

Example 80 with Invocation

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

the class InvocationImplTest method shouldEqualToNotConsiderSequenceNumber.

@Test
public void shouldEqualToNotConsiderSequenceNumber() {
    Invocation equal = new InvocationBuilder().args(" ").mock("mock").seq(2).toInvocation();
    assertTrue(invocation.equals(equal));
    assertTrue(invocation.getSequenceNumber() != equal.getSequenceNumber());
}
Also used : Invocation(org.mockito.invocation.Invocation) 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