Search in sources :

Example 51 with Invocation

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

the class MockitoCore method ignoreStubs.

public Object[] ignoreStubs(Object... mocks) {
    for (Object m : mocks) {
        InvocationContainer invocationContainer = getMockHandler(m).getInvocationContainer();
        List<Invocation> ins = invocationContainer.getInvocations();
        for (Invocation in : ins) {
            if (in.stubInfo() != null) {
                in.ignoreForVerification();
            }
        }
    }
    return mocks;
}
Also used : Invocation(org.mockito.invocation.Invocation) Reporter.missingMethodInvocation(org.mockito.internal.exceptions.Reporter.missingMethodInvocation) InvocationContainer(org.mockito.internal.stubbing.InvocationContainer)

Example 52 with Invocation

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

the class WarningsFinderTest method shouldPrintStubWasUsedWithDifferentArgs.

@Test
public void shouldPrintStubWasUsedWithDifferentArgs() {
    // given
    Invocation stub = new InvocationBuilder().arg("foo").mock(mock).toInvocation();
    InvocationMatcher wrongArg = new InvocationBuilder().arg("bar").mock(mock).toInvocationMatcher();
    // when
    WarningsFinder finder = new WarningsFinder(Arrays.<Invocation>asList(stub), Arrays.<InvocationMatcher>asList(wrongArg));
    finder.find(listener);
    // then
    verify(listener, only()).foundStubCalledWithDifferentArgs(stub, wrongArg);
}
Also used : Invocation(org.mockito.invocation.Invocation) InvocationMatcher(org.mockito.internal.invocation.InvocationMatcher) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 53 with Invocation

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

the class WarningsFinderTest method shouldPrintUnusedStub.

@Test
public void shouldPrintUnusedStub() {
    // given
    Invocation unusedStub = new InvocationBuilder().simpleMethod().toInvocation();
    // when
    WarningsFinder finder = new WarningsFinder(asList(unusedStub), Arrays.<InvocationMatcher>asList());
    finder.find(listener);
    // then
    verify(listener, only()).foundUnusedStub(unusedStub);
}
Also used : Invocation(org.mockito.invocation.Invocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 54 with Invocation

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

the class ReporterTest method can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_delegate_method_has_wrong_return_type.

@Test(expected = MockitoException.class)
public void can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_delegate_method_has_wrong_return_type() throws Exception {
    Invocation dumb_invocation = new InvocationBuilder().toInvocation();
    IMethods mock_with_bogus_default_answer = mock(IMethods.class, new Returns(false));
    throw Reporter.delegatedMethodHasWrongReturnType(dumb_invocation.getMethod(), dumb_invocation.getMethod(), mock_with_bogus_default_answer, String.class);
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) Invocation(org.mockito.invocation.Invocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Example 55 with Invocation

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

the class ReporterTest method can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_delegate_method_dont_exists.

@Test(expected = MockitoException.class)
public void can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_delegate_method_dont_exists() throws Exception {
    Invocation dumb_invocation = new InvocationBuilder().toInvocation();
    IMethods mock_with_bogus_default_answer = mock(IMethods.class, new Returns(false));
    throw Reporter.delegatedMethodDoesNotExistOnDelegate(dumb_invocation.getMethod(), mock_with_bogus_default_answer, String.class);
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) Invocation(org.mockito.invocation.Invocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) IMethods(org.mockitousage.IMethods) 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