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");
}
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());
}
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");
}
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)
}
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));
}
Aggregations