use of org.mockitousage.IMethods in project mockito by mockito.
the class MocksSerializationForAnnotationTest method should_verify_even_if_some_methods_called_after_serialization.
@Test
public void should_verify_even_if_some_methods_called_after_serialization() throws Exception {
// when
imethodsMock.simpleMethod(1);
ByteArrayOutputStream serialized = serializeMock(imethodsMock);
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)
}
use of org.mockitousage.IMethods in project mockito by mockito.
the class MocksSerializationForAnnotationTest method should_allow_mock_and_string_value_to_be_serializable.
@Test
public void should_allow_mock_and_string_value_to_be_serializable() throws Exception {
// given
String value = "value";
when(imethodsMock.stringReturningMethod()).thenReturn(value);
// when
ByteArrayOutputStream serialized = serializeMock(imethodsMock);
// then
IMethods readObject = deserializeMock(serialized, IMethods.class);
assertEquals(value, readObject.stringReturningMethod());
}
use of org.mockitousage.IMethods in project mockito by mockito.
the class MocksSerializationTest method should_allow_mock_and_string_value_to_be_serializable.
@Test
public void should_allow_mock_and_string_value_to_be_serializable() throws Exception {
// given
IMethods mock = mock(IMethods.class, withSettings().serializable());
String value = "value";
when(mock.stringReturningMethod()).thenReturn(value);
// when
ByteArrayOutputStream serialized = serializeMock(mock);
// then
IMethods readObject = deserializeMock(serialized, IMethods.class);
assertEquals(value, readObject.stringReturningMethod());
}
use of org.mockitousage.IMethods in project mockito by mockito.
the class MocksSerializationTest method should_serialize_with_stubbing_callback.
@Test
public void should_serialize_with_stubbing_callback() throws Exception {
// given
IMethods mock = mock(IMethods.class, withSettings().serializable());
CustomAnswersMustImplementSerializableForSerializationToWork answer = new CustomAnswersMustImplementSerializableForSerializationToWork();
answer.string = "return value";
when(mock.objectArgMethod(anyString())).thenAnswer(answer);
// when
ByteArrayOutputStream serialized = serializeMock(mock);
// then
IMethods readObject = deserializeMock(serialized, IMethods.class);
assertEquals(answer.string, readObject.objectArgMethod(""));
}
use of org.mockitousage.IMethods in project mockito by mockito.
the class MocksSerializationTest method should_allow_mock_and_boolean_value_to_serializable.
@Test
public void should_allow_mock_and_boolean_value_to_serializable() throws Exception {
// given
IMethods mock = mock(IMethods.class, withSettings().serializable());
when(mock.booleanReturningMethod()).thenReturn(true);
// when
ByteArrayOutputStream serialized = serializeMock(mock);
// then
IMethods readObject = deserializeMock(serialized, IMethods.class);
assertTrue(readObject.booleanReturningMethod());
}
Aggregations