Search in sources :

Example 41 with InvocationBuilder

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

the class ReturnsTest method should_allow_correct_type_of_return_value.

@Test
public void should_allow_correct_type_of_return_value() throws Throwable {
    new Returns("one").validateFor(new InvocationBuilder().simpleMethod().toInvocation());
    new Returns(false).validateFor(new InvocationBuilder().method("booleanReturningMethod").toInvocation());
    new Returns(TRUE).validateFor(new InvocationBuilder().method("booleanObjectReturningMethod").toInvocation());
    new Returns(1).validateFor(new InvocationBuilder().method("integerReturningMethod").toInvocation());
    new Returns(1L).validateFor(new InvocationBuilder().method("longReturningMethod").toInvocation());
    new Returns(1L).validateFor(new InvocationBuilder().method("longObjectReturningMethod").toInvocation());
    new Returns(null).validateFor(new InvocationBuilder().method("objectReturningMethodNoArgs").toInvocation());
    new Returns(1).validateFor(new InvocationBuilder().method("objectReturningMethodNoArgs").toInvocation());
}
Also used : InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 42 with InvocationBuilder

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

the class ThrowsExceptionTest method should_pass_RuntimeExceptions.

@Test
public void should_pass_RuntimeExceptions() throws Throwable {
    new ThrowsException(new Error()).validateFor(new InvocationBuilder().method("canThrowException").toInvocation());
    new ThrowsException(new RuntimeException()).validateFor(new InvocationBuilder().method("canThrowException").toInvocation());
}
Also used : InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 43 with InvocationBuilder

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

the class NoMoreInteractionsTest method noMoreInteractionsInOrderExceptionMessageShouldDescribeMock.

@Test
public void noMoreInteractionsInOrderExceptionMessageShouldDescribeMock() {
    //given
    NoMoreInteractions n = new NoMoreInteractions();
    IMethods mock = mock(IMethods.class, "a mock");
    Invocation i = new InvocationBuilder().mock(mock).toInvocation();
    try {
        //when
        n.verifyInOrder(new VerificationDataInOrderImpl(context, asList(i), null));
        //then
        fail();
    } catch (VerificationInOrderFailure e) {
        Assertions.assertThat(e.toString()).contains(mock.toString());
    }
}
Also used : Invocation(org.mockito.invocation.Invocation) IMethods(org.mockitousage.IMethods) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) VerificationDataInOrderImpl(org.mockito.internal.verification.api.VerificationDataInOrderImpl) VerificationInOrderFailure(org.mockito.exceptions.verification.VerificationInOrderFailure) Test(org.junit.Test)

Example 44 with InvocationBuilder

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

the class NoMoreInteractionsTest method shouldVerifyInOrder.

@Test
public void shouldVerifyInOrder() {
    //given
    NoMoreInteractions n = new NoMoreInteractions();
    Invocation i = new InvocationBuilder().toInvocation();
    assertFalse(context.isVerified(i));
    try {
        //when
        n.verifyInOrder(new VerificationDataInOrderImpl(context, asList(i), null));
        //then
        fail();
    } catch (VerificationInOrderFailure e) {
    }
}
Also used : Invocation(org.mockito.invocation.Invocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) VerificationDataInOrderImpl(org.mockito.internal.verification.api.VerificationDataInOrderImpl) VerificationInOrderFailure(org.mockito.exceptions.verification.VerificationInOrderFailure) Test(org.junit.Test)

Example 45 with InvocationBuilder

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

the class NoMoreInteractionsTest method noMoreInteractionsExceptionMessageShouldDescribeMock.

@Test
public void noMoreInteractionsExceptionMessageShouldDescribeMock() {
    //given
    NoMoreInteractions n = new NoMoreInteractions();
    IMethods mock = mock(IMethods.class, "a mock");
    InvocationMatcher i = new InvocationBuilder().mock(mock).toInvocationMatcher();
    InvocationContainerImpl invocations = new InvocationContainerImpl(new MockSettingsImpl());
    invocations.setInvocationForPotentialStubbing(i);
    try {
        //when
        n.verify(new VerificationDataImpl(invocations, null));
        //then
        fail();
    } catch (NoInteractionsWanted e) {
        Assertions.assertThat(e.toString()).contains(mock.toString());
    }
}
Also used : InvocationContainerImpl(org.mockito.internal.stubbing.InvocationContainerImpl) MockSettingsImpl(org.mockito.internal.creation.MockSettingsImpl) NoInteractionsWanted(org.mockito.exceptions.verification.NoInteractionsWanted) InvocationMatcher(org.mockito.internal.invocation.InvocationMatcher) IMethods(org.mockitousage.IMethods) 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