Search in sources :

Example 41 with IMethods

use of org.mockitousage.IMethods in project mockito by mockito.

the class MocksCreationTest method shouldCombineMockNameAndSmartNulls.

@Test
public void shouldCombineMockNameAndSmartNulls() {
    //given
    IMethods mock = mock(IMethods.class, withSettings().defaultAnswer(RETURNS_SMART_NULLS).name("great mockie"));
    //when
    IMethods smartNull = mock.iMethodsReturningMethod();
    String name = mock.toString();
    //then
    assertThat(name).contains("great mockie");
    //and
    try {
        smartNull.simpleMethod();
        fail();
    } catch (SmartNullPointerException e) {
    }
}
Also used : IMethods(org.mockitousage.IMethods) SmartNullPointerException(org.mockito.exceptions.verification.SmartNullPointerException) Test(org.junit.Test)

Example 42 with IMethods

use of org.mockitousage.IMethods in project mockito by mockito.

the class MocksCreationTest method shouldCombineMockNameAndExtraInterfaces.

@Test
public void shouldCombineMockNameAndExtraInterfaces() {
    //given
    IMethods mock = mock(IMethods.class, withSettings().extraInterfaces(List.class).name("great mockie"));
    //when
    String name = mock.toString();
    //then
    assertThat(name).contains("great mockie");
    //and
    assertTrue(mock instanceof List);
}
Also used : List(java.util.List) LinkedList(java.util.LinkedList) IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Example 43 with IMethods

use of org.mockitousage.IMethods 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 IMethods

use of org.mockitousage.IMethods 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)

Example 45 with IMethods

use of org.mockitousage.IMethods in project mockito by mockito.

the class StubbingMocksThatAreConfiguredToReturnMocksTest method shouldAllowStubbingMocksConfiguredWithRETURNS_MOCKSWithDoApi.

@Test
public void shouldAllowStubbingMocksConfiguredWithRETURNS_MOCKSWithDoApi() {
    IMethods mock = mock(IMethods.class, RETURNS_MOCKS);
    doReturn(null).when(mock).objectReturningMethodNoArgs();
}
Also used : IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)64 IMethods (org.mockitousage.IMethods)64 ByteArrayOutputStream (java.io.ByteArrayOutputStream)22 BDDMockito.anyString (org.mockito.BDDMockito.anyString)8 VerificationCollector (org.mockito.junit.VerificationCollector)5 InvocationBuilder (org.mockito.internal.invocation.InvocationBuilder)4 Invocation (org.mockito.invocation.Invocation)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 InOrder (org.mockito.InOrder)2 SmartNullPointerException (org.mockito.exceptions.verification.SmartNullPointerException)2 Returns (org.mockito.internal.stubbing.answers.Returns)2 VoidAnswer3 (org.mockito.stubbing.VoidAnswer3)2 VoidAnswer4 (org.mockito.stubbing.VoidAnswer4)2 VoidAnswer5 (org.mockito.stubbing.VoidAnswer5)2 MethodsImpl (org.mockitousage.MethodsImpl)2 CharacterCodingException (java.nio.charset.CharacterCodingException)1 Ignore (org.junit.Ignore)1 MockitoAssertionError (org.mockito.exceptions.base.MockitoAssertionError)1