Search in sources :

Example 31 with IMethods

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

the class ReporterTest method can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_delegate_method_dont_exists.

@Test(expected = MockitoException.class)
public void can_use_print_mock_name_even_when_mock_bogus_default_answer_and_when_reporting_delegate_method_dont_exists() throws Exception {
    Invocation dumb_invocation = new InvocationBuilder().toInvocation();
    IMethods mock_with_bogus_default_answer = mock(IMethods.class, new Returns(false));
    throw Reporter.delegatedMethodDoesNotExistOnDelegate(dumb_invocation.getMethod(), mock_with_bogus_default_answer, String.class);
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) Invocation(org.mockito.invocation.Invocation) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Example 32 with IMethods

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

the class ClassPathLoaderTest method shouldReadConfigurationClassFromClassPath.

@Test
public void shouldReadConfigurationClassFromClassPath() {
    ConfigurationAccess.getConfig().overrideDefaultAnswer(new Answer<Object>() {

        public Object answer(InvocationOnMock invocation) {
            return "foo";
        }
    });
    IMethods mock = mock(IMethods.class);
    assertEquals("foo", mock.simpleMethod());
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Example 33 with IMethods

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

the class MocksSerializationForAnnotationTest method should_verify_called_n_times_for_serialized_mock.

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

Example 34 with IMethods

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

the class MocksSerializationForAnnotationTest method should_serialize_method_calls_using_any_string_matcher.

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

Example 35 with IMethods

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

the class MocksSerializationForAnnotationTest method should_verify_call_order_for_serialized_mock.

@Test
public void should_verify_call_order_for_serialized_mock() throws Exception {
    imethodsMock.arrayReturningMethod();
    imethodsMock2.arrayReturningMethod();
    // when
    ByteArrayOutputStream serialized = serializeMock(imethodsMock);
    ByteArrayOutputStream serialized2 = serializeMock(imethodsMock2);
    // 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) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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