Search in sources :

Example 51 with IMethods

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

the class StubbingWithAdditionalAnswersTest method will_execute_a_void_based_on_strongly_typed_three_parameter_function.

@Test
public void will_execute_a_void_based_on_strongly_typed_three_parameter_function() throws Exception {
    final IMethods target = mock(IMethods.class);
    given(iMethods.threeArgumentMethodWithStrings(anyInt(), anyString(), anyString())).will(answerVoid(new VoidAnswer3<Integer, String, String>() {

        public void answer(Integer i, String s1, String s2) {
            target.threeArgumentMethodWithStrings(i, s1, s2);
        }
    }));
    // invoke on iMethods
    iMethods.threeArgumentMethodWithStrings(1, "string1", "string2");
    // expect the answer to write correctly to "target"
    verify(target, times(1)).threeArgumentMethodWithStrings(1, "string1", "string2");
}
Also used : VoidAnswer3(org.mockito.stubbing.VoidAnswer3) IMethods(org.mockitousage.IMethods) BDDMockito.anyString(org.mockito.BDDMockito.anyString) Test(org.junit.Test)

Example 52 with IMethods

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

the class VerificationCollectorImplTest method should_not_throw_any_exceptions_when_verifications_are_succesful.

@Test
public void should_not_throw_any_exceptions_when_verifications_are_succesful() {
    VerificationCollector collector = MockitoJUnit.collector().assertLazily();
    IMethods methods = mock(IMethods.class);
    methods.simpleMethod();
    verify(methods).simpleMethod();
    collector.collectAndReport();
}
Also used : VerificationCollector(org.mockito.junit.VerificationCollector) IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Example 53 with IMethods

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

the class ModellingDescriptiveMessagesTest method shouldSayUnstubbedMethodWasInvokedHere.

@Test
public void shouldSayUnstubbedMethodWasInvokedHere() {
    mock = mock(IMethods.class, RETURNS_SMART_NULLS);
    IMethods m = mock.iMethodsReturningMethod();
    m.simpleMethod();
}
Also used : IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Example 54 with IMethods

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

the class MocksSerializationTest method should_verify_called_n_times_for_serialized_mock.

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

Example 55 with IMethods

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

the class MocksSerializationTest method should_serialize_method_calls_using_any_string_matcher.

@Test
public void should_serialize_method_calls_using_any_string_matcher() throws Exception {
    IMethods mock = mock(IMethods.class, withSettings().serializable());
    List<?> value = Collections.emptyList();
    when(mock.objectArgMethod(anyString())).thenReturn(value);
    // when
    ByteArrayOutputStream serialized = serializeMock(mock);
    // then
    IMethods readObject = deserializeMock(serialized, IMethods.class);
    assertEquals(value, readObject.objectArgMethod(""));
}
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