Search in sources :

Example 11 with IMethods

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

the class VerificationCollectorImplTest method should_collect_verification_failures.

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

Example 12 with IMethods

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

the class VerificationCollectorImplTest method should_continue_collecting_after_failing_verification.

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

Example 13 with IMethods

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

the class VerificationCollectorImplTest method should_only_collect_failures_ignore_succesful_verifications.

@Test
public void should_only_collect_failures_ignore_succesful_verifications() {
    VerificationCollector collector = MockitoJUnit.collector().assertLazily();
    IMethods methods = mock(IMethods.class);
    verify(methods, never()).simpleMethod();
    verify(methods).byteReturningMethod();
    this.assertAtLeastOneFailure(collector);
}
Also used : VerificationCollector(org.mockito.junit.VerificationCollector) IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Example 14 with IMethods

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

the class MocksSerializationForAnnotationTest method should_serialize_with_stubbing_callback.

@Test
public void should_serialize_with_stubbing_callback() throws Exception {
    // given
    CustomAnswersMustImplementSerializableForSerializationToWork answer = new CustomAnswersMustImplementSerializableForSerializationToWork();
    answer.string = "return value";
    when(imethodsMock.objectArgMethod(anyString())).thenAnswer(answer);
    // when
    ByteArrayOutputStream serialized = serializeMock(imethodsMock);
    // then
    IMethods readObject = deserializeMock(serialized, IMethods.class);
    assertEquals(answer.string, readObject.objectArgMethod(""));
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Example 15 with IMethods

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

the class MocksSerializationForAnnotationTest method should_remember_interactions_for_serialized_mock.

@Test
public void should_remember_interactions_for_serialized_mock() throws Exception {
    List<?> value = Collections.emptyList();
    when(imethodsMock.objectArgMethod(anyString())).thenReturn(value);
    imethodsMock.objectArgMethod("happened");
    // when
    ByteArrayOutputStream serialized = serializeMock(imethodsMock);
    // then
    IMethods readObject = deserializeMock(serialized, IMethods.class);
    verify(readObject, never()).objectArgMethod("never happened");
}
Also used : 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