Search in sources :

Example 6 with IMethods

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

the class MocksSerializationTest method should_be_serialize_and_have_extra_interfaces.

@Test
public void should_be_serialize_and_have_extra_interfaces() throws Exception {
    //when
    IMethods mock = mock(IMethods.class, withSettings().serializable().extraInterfaces(List.class));
    IMethods mockTwo = mock(IMethods.class, withSettings().extraInterfaces(List.class).serializable());
    //then
    Assertions.assertThat((Object) serializeAndBack((List) mock)).isInstanceOf(List.class).isInstanceOf(IMethods.class);
    Assertions.assertThat((Object) serializeAndBack((List) mockTwo)).isInstanceOf(List.class).isInstanceOf(IMethods.class);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Example 7 with IMethods

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

the class MocksSerializationTest method should_allow_mock_to_be_serializable.

@Test
public void should_allow_mock_to_be_serializable() throws Exception {
    // given
    IMethods mock = mock(IMethods.class, withSettings().serializable());
    // when-serialize then-deserialize
    serializeAndBack(mock);
}
Also used : IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Example 8 with IMethods

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

the class ResetTest method shouldNotAffectMockName.

@Test
public void shouldNotAffectMockName() {
    IMethods mock = mock(IMethods.class, "mockie");
    IMethods mockTwo = mock(IMethods.class);
    reset(mock);
    assertThat(mockTwo.toString()).contains("Mock for IMethods");
    assertEquals("mockie", "" + mock);
}
Also used : IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Example 9 with IMethods

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

the class ArgumentCaptorDontCapturePreviouslyVerifiedTest method previous_verified_invocation_should_still_capture_args.

@Test
public void previous_verified_invocation_should_still_capture_args() {
    IMethods mock = mock(IMethods.class);
    mock.oneArg("first");
    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
    verify(mock, times(1)).oneArg(argument.capture());
    assertThat(argument.getAllValues()).hasSize(1);
    // additional interactions
    mock.oneArg("second");
    argument = ArgumentCaptor.forClass(String.class);
    verify(mock, times(2)).oneArg(argument.capture());
    assertThat(argument.getAllValues()).hasSize(2);
}
Also used : IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Example 10 with IMethods

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

the class VerificationCollectorImplTest method should_collect_multiple_verification_failures.

@Test
public void should_collect_multiple_verification_failures() {
    VerificationCollector collector = MockitoJUnit.collector().assertLazily();
    IMethods methods = mock(IMethods.class);
    verify(methods).simpleMethod();
    verify(methods).byteReturningMethod();
    try {
        collector.collectAndReport();
        fail();
    } catch (MockitoAssertionError error) {
        assertThat(error).hasMessageContaining("1. Wanted but not invoked:");
        assertThat(error).hasMessageContaining("2. Wanted but not invoked:");
    }
}
Also used : VerificationCollector(org.mockito.junit.VerificationCollector) MockitoAssertionError(org.mockito.exceptions.base.MockitoAssertionError) 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