Search in sources :

Example 1 with SmartNullPointerException

use of org.mockito.exceptions.verification.SmartNullPointerException in project mockito by mockito.

the class SmartNullsStubbingTest method shouldSmartNPEPointToUnstubbedCall.

@Test
public void shouldSmartNPEPointToUnstubbedCall() throws Exception {
    IMethods methods = unstubbedMethodInvokedHere(mock);
    try {
        methods.simpleMethod();
        fail();
    } catch (SmartNullPointerException e) {
        assertThat(e).hasMessageContaining("unstubbedMethodInvokedHere(");
    }
}
Also used : IMethods(org.mockitousage.IMethods) SmartNullPointerException(org.mockito.exceptions.verification.SmartNullPointerException) Test(org.junit.Test)

Example 2 with SmartNullPointerException

use of org.mockito.exceptions.verification.SmartNullPointerException in project mockito by mockito.

the class MocksCreationTest method shouldCombineMockNameAndSmartNulls.

@Test
public void shouldCombineMockNameAndSmartNulls() {
    //given
    IMethods mock = mock(IMethods.class, withSettings().defaultAnswer(RETURNS_SMART_NULLS).name("great mockie"));
    //when
    IMethods smartNull = mock.iMethodsReturningMethod();
    String name = mock.toString();
    //then
    assertThat(name).contains("great mockie");
    //and
    try {
        smartNull.simpleMethod();
        fail();
    } catch (SmartNullPointerException e) {
    }
}
Also used : IMethods(org.mockitousage.IMethods) SmartNullPointerException(org.mockito.exceptions.verification.SmartNullPointerException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 SmartNullPointerException (org.mockito.exceptions.verification.SmartNullPointerException)2 IMethods (org.mockitousage.IMethods)2