Search in sources :

Example 56 with IMethods

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

the class MocksSerializationTest method should_verify_call_order_for_serialized_mock.

@Test
public void should_verify_call_order_for_serialized_mock() throws Exception {
    IMethods mock = mock(IMethods.class, withSettings().serializable());
    IMethods mock2 = mock(IMethods.class, withSettings().serializable());
    mock.arrayReturningMethod();
    mock2.arrayReturningMethod();
    // when
    ByteArrayOutputStream serialized = serializeMock(mock);
    ByteArrayOutputStream serialized2 = serializeMock(mock2);
    // then
    IMethods readObject = deserializeMock(serialized, IMethods.class);
    IMethods readObject2 = deserializeMock(serialized2, IMethods.class);
    InOrder inOrder = inOrder(readObject, readObject2);
    inOrder.verify(readObject).arrayReturningMethod();
    inOrder.verify(readObject2).arrayReturningMethod();
}
Also used : InOrder(org.mockito.InOrder) IMethods(org.mockitousage.IMethods) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 57 with IMethods

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

the class MocksSerializationTest method should_stub_even_if_some_methods_called_after_serialization.

@Test
public void should_stub_even_if_some_methods_called_after_serialization() throws Exception {
    //given
    IMethods mock = mock(IMethods.class, withSettings().serializable());
    // when
    when(mock.simpleMethod(1)).thenReturn("foo");
    ByteArrayOutputStream serialized = serializeMock(mock);
    IMethods readObject = deserializeMock(serialized, IMethods.class);
    when(readObject.simpleMethod(2)).thenReturn("bar");
    // then
    assertEquals("foo", readObject.simpleMethod(1));
    assertEquals("bar", readObject.simpleMethod(2));
}
Also used : IMethods(org.mockitousage.IMethods) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 58 with IMethods

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

the class MocksSerializationTest 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
    IMethods mock = mock(IMethods.class, withSettings().serializable());
    List<?> value = Collections.emptyList();
    when(mock.objectReturningMethodNoArgs()).thenReturn(value);
    // when
    ByteArrayOutputStream serialized = serializeMock(mock);
    // then
    IMethods readObject = deserializeMock(serialized, IMethods.class);
    assertEquals(value, readObject.objectReturningMethodNoArgs());
}
Also used : IMethods(org.mockitousage.IMethods) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 59 with IMethods

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

the class ResetTest method shouldRemoveStubbingToString.

@Test
public void shouldRemoveStubbingToString() throws Exception {
    IMethods mockTwo = mock(IMethods.class);
    when(mockTwo.toString()).thenReturn("test");
    reset(mockTwo);
    assertThat(mockTwo.toString()).contains("Mock for IMethods");
}
Also used : IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Example 60 with IMethods

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

the class CompareMatcherTest method compareNullArgument.

/**
     * Should not throw an {@link NullPointerException}
     *
     * @see Bug-ID https://github.com/mockito/mockito/issues/457
     */
@Test
public void compareNullArgument() {
    final IMethods mock = mock(IMethods.class);
    when(mock.forInteger(leq(5))).thenReturn("");
    // a default value must be returned
    assertThat(mock.forInteger(null)).isNull();
}
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