Search in sources :

Example 61 with IMethods

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

the class BasicStubbingTest method should_allow_stubbing_to_string.

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

Example 62 with IMethods

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

the class BasicStubbingTest method should_to_string_mock_name.

@Test
public void should_to_string_mock_name() {
    IMethods mock = mock(IMethods.class, "mockie");
    IMethods mockTwo = mock(IMethods.class);
    assertThat(mockTwo.toString()).contains("Mock for IMethods");
    assertEquals("mockie", "" + mock);
}
Also used : IMethods(org.mockitousage.IMethods) Test(org.junit.Test)

Example 63 with IMethods

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

the class StubbingWithDelegateTest method exception_should_be_propagated_from_delegate.

@Test
public void exception_should_be_propagated_from_delegate() throws Exception {
    final RuntimeException failure = new RuntimeException("angry-method");
    IMethods methods = mock(IMethods.class, delegatesTo(new MethodsImpl() {

        @Override
        public String simpleMethod() {
            throw failure;
        }
    }));
    try {
        // delegate throws an exception
        methods.simpleMethod();
        fail();
    } catch (RuntimeException e) {
        assertThat(e).isEqualTo(failure);
    }
}
Also used : IMethods(org.mockitousage.IMethods) MethodsImpl(org.mockitousage.MethodsImpl) Test(org.junit.Test)

Example 64 with IMethods

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

the class BasicVerificationTest method shouldDetectWhenOverloadedMethodCalled.

@Test
public void shouldDetectWhenOverloadedMethodCalled() throws Exception {
    IMethods mockThree = mock(IMethods.class);
    mockThree.varargs((Object[]) new Object[] {});
    try {
        verify(mockThree).varargs((String[]) new String[] {});
        fail();
    } catch (WantedButNotInvoked e) {
    }
}
Also used : IMethods(org.mockitousage.IMethods) WantedButNotInvoked(org.mockito.exceptions.verification.WantedButNotInvoked) 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