Search in sources :

Example 1 with IMethods

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

the class MocksCreationTest method shouldSpecifyMockNameViaSettings.

@Test
public void shouldSpecifyMockNameViaSettings() {
    //given
    IMethods mock = mock(IMethods.class, withSettings().name("great mockie"));
    //when
    String name = mock.toString();
    //then
    assertThat(name).contains("great mockie");
}
Also used : IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Example 2 with IMethods

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

the class MocksSerializationForAnnotationTest method should_all_mock_and_serializable_value_to_be_serialized.

@Test
public void should_all_mock_and_serializable_value_to_be_serialized() throws Exception {
    // given
    List<?> value = Collections.emptyList();
    when(imethodsMock.objectReturningMethodNoArgs()).thenReturn(value);
    // when
    ByteArrayOutputStream serialized = serializeMock(imethodsMock);
    // then
    IMethods readObject = deserializeMock(serialized, IMethods.class);
    assertEquals(value, readObject.objectReturningMethodNoArgs());
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Example 3 with IMethods

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

the class MocksSerializationTest method should_remember_interactions_for_serialized_mock.

@Test
public void should_remember_interactions_for_serialized_mock() throws Exception {
    IMethods mock = mock(IMethods.class, withSettings().serializable());
    List<?> value = Collections.emptyList();
    when(mock.objectArgMethod(anyString())).thenReturn(value);
    mock.objectArgMethod("happened");
    // when
    ByteArrayOutputStream serialized = serializeMock(mock);
    // then
    IMethods readObject = deserializeMock(serialized, IMethods.class);
    verify(readObject, never()).objectArgMethod("never happened");
}
Also used : IMethods(org.mockitousage.IMethods) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 4 with IMethods

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

the class MocksSerializationTest method should_verify_even_if_some_methods_called_after_serialization.

@Test
public void should_verify_even_if_some_methods_called_after_serialization() throws Exception {
    //given
    IMethods mock = mock(IMethods.class, withSettings().serializable());
    // when
    mock.simpleMethod(1);
    ByteArrayOutputStream serialized = serializeMock(mock);
    IMethods readObject = deserializeMock(serialized, IMethods.class);
    readObject.simpleMethod(1);
    // then
    verify(readObject, times(2)).simpleMethod(1);
//this test is working because it seems that java serialization mechanism replaces all instances
//of serialized object in the object graph (if there are any)
}
Also used : IMethods(org.mockitousage.IMethods) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 5 with IMethods

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

the class MocksSerializationTest method should_serialize_method_call_with_parameters_that_are_serializable.

@Test
public void should_serialize_method_call_with_parameters_that_are_serializable() throws Exception {
    IMethods mock = mock(IMethods.class, withSettings().serializable());
    List<?> value = Collections.emptyList();
    when(mock.objectArgMethod(value)).thenReturn(value);
    // when
    ByteArrayOutputStream serialized = serializeMock(mock);
    // then
    IMethods readObject = deserializeMock(serialized, IMethods.class);
    assertEquals(value, readObject.objectArgMethod(value));
}
Also used : IMethods(org.mockitousage.IMethods) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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