Search in sources :

Example 26 with InvocationBuilder

use of org.mockito.internal.invocation.InvocationBuilder 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)

Example 27 with InvocationBuilder

use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.

the class ScenarioPrinterTest method shouldPrintInvocations.

@Test
public void shouldPrintInvocations() {
    //given
    Invocation verified = new InvocationBuilder().simpleMethod().verified().toInvocation();
    Invocation unverified = new InvocationBuilder().differentMethod().toInvocation();
    //when
    String out = sp.print((List) asList(verified, unverified));
    //then
    assertThat(out).contains("1. -> at").contains("2. [?]-> at");
}
Also used : Invocation(org.mockito.invocation.Invocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 28 with InvocationBuilder

use of org.mockito.internal.invocation.InvocationBuilder in project mockito by mockito.

the class StubbingArgMismatchesTest method multiple_matching_invocations_per_stub_plus_some_other_invocation.

@Test
public void multiple_matching_invocations_per_stub_plus_some_other_invocation() throws Exception {
    //given
    Invocation stubbing = new InvocationBuilder().args("a").location("-> at A.java").toInvocation();
    mismatches.add(new InvocationBuilder().args("x").location("-> at X.java").toInvocation(), stubbing);
    mismatches.add(new InvocationBuilder().args("y").location("-> at Y.java").toInvocation(), stubbing);
    mismatches.add(new InvocationBuilder().method("differentMethod").args("n").location("-> at N.java").toInvocation(), new InvocationBuilder().method("differentMethod").args("m").location("-> at M.java").toInvocation());
    //when
    mismatches.format("MyTest.myTestMethod", logger);
    //then
    assertEquals("[MockitoHint] MyTest.myTestMethod (see javadoc for MockitoHint):\n" + "[MockitoHint] 1. Unused... -> at A.java\n" + "[MockitoHint]  ...args ok? -> at X.java\n" + "[MockitoHint]  ...args ok? -> at Y.java\n" + "[MockitoHint] 2. Unused... -> at M.java\n" + "[MockitoHint]  ...args ok? -> at N.java\n", logger.getLoggedInfo());
}
Also used : Invocation(org.mockito.invocation.Invocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 29 with InvocationBuilder

use of org.mockito.internal.invocation.InvocationBuilder 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 30 with InvocationBuilder

use of org.mockito.internal.invocation.InvocationBuilder 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));
}
Also used : Invocation(org.mockito.invocation.Invocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Aggregations

InvocationBuilder (org.mockito.internal.invocation.InvocationBuilder)46 Test (org.junit.Test)45 Invocation (org.mockito.invocation.Invocation)28 InvocationMatcher (org.mockito.internal.invocation.InvocationMatcher)12 Returns (org.mockito.internal.stubbing.answers.Returns)5 VerificationDataInOrderImpl (org.mockito.internal.verification.api.VerificationDataInOrderImpl)5 MockitoException (org.mockito.exceptions.base.MockitoException)4 MockSettingsImpl (org.mockito.internal.creation.MockSettingsImpl)4 IMethods (org.mockitousage.IMethods)4 WrongTypeOfReturnValue (org.mockito.exceptions.misusing.WrongTypeOfReturnValue)3 VerificationInOrderFailure (org.mockito.exceptions.verification.VerificationInOrderFailure)3 CharacterCodingException (java.nio.charset.CharacterCodingException)2 StubbedInvocationMatcher (org.mockito.internal.stubbing.StubbedInvocationMatcher)2 ThrowsException (org.mockito.internal.stubbing.answers.ThrowsException)2 ReturnsEmptyValues (org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues)2 InOrderContextImpl (org.mockito.internal.verification.InOrderContextImpl)2 InOrderContext (org.mockito.internal.verification.api.InOrderContext)2 MatchableInvocation (org.mockito.invocation.MatchableInvocation)2 IOException (java.io.IOException)1 Before (org.junit.Before)1