Search in sources :

Example 36 with MockitoException

use of org.mockito.exceptions.base.MockitoException in project mockito by mockito.

the class InvocationContainerImplStubbingTest method should_validate_throwable_for_void_method.

@Test
public void should_validate_throwable_for_void_method() throws Throwable {
    invocationContainerImpl.addAnswerForVoidMethod(new ThrowsException(new Exception()));
    try {
        invocationContainerImpl.setMethodForStubbing(new InvocationMatcher(simpleMethod));
        fail();
    } catch (MockitoException e) {
    }
}
Also used : ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) MockitoException(org.mockito.exceptions.base.MockitoException) InvocationMatcher(org.mockito.internal.invocation.InvocationMatcher) ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) MockitoException(org.mockito.exceptions.base.MockitoException) Test(org.junit.Test)

Example 37 with MockitoException

use of org.mockito.exceptions.base.MockitoException in project mockito by mockito.

the class ReturnsArgumentAtTest method should_fail_if_index_is_not_in_range_for_example_with_no_arg_invocation.

@Test
public void should_fail_if_index_is_not_in_range_for_example_with_no_arg_invocation() throws Throwable {
    try {
        new ReturnsArgumentAt(ReturnsArgumentAt.LAST_ARGUMENT).validateFor(new InvocationBuilder().simpleMethod().toInvocation());
        fail();
    } catch (MockitoException e) {
        assertThat(e.getMessage()).containsIgnoringCase("invalid argument index").containsIgnoringCase("iMethods.simpleMethod").containsIgnoringCase("no arguments").containsIgnoringCase("last parameter wanted");
    }
}
Also used : MockitoException(org.mockito.exceptions.base.MockitoException) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 38 with MockitoException

use of org.mockito.exceptions.base.MockitoException in project mockito by mockito.

the class MockitoRunnerBreaksWhenNoTestMethodsTest method ensure_the_test_runner_breaks.

@Test
public void ensure_the_test_runner_breaks() throws Exception {
    JUnitCore runner = new JUnitCore();
    //        runner.addListener(new TextListener(System.out));
    runner.addListener(new TextListener(DevNull.out));
    Result result = runner.run(TestClassWithoutTestMethod.class);
    assertEquals(1, result.getFailureCount());
    assertTrue(result.getFailures().get(0).getException() instanceof MockitoException);
    assertFalse(result.wasSuccessful());
}
Also used : JUnitCore(org.junit.runner.JUnitCore) MockitoException(org.mockito.exceptions.base.MockitoException) TextListener(org.junit.internal.TextListener) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 39 with MockitoException

use of org.mockito.exceptions.base.MockitoException in project mockito by mockito.

the class StackTraceFilteringTest method shouldFilterStackTraceWhenThrowingExceptionFromMockHandler.

@Test
public void shouldFilterStackTraceWhenThrowingExceptionFromMockHandler() {
    try {
        when(mock.oneArg(true)).thenThrow(new Exception());
        fail();
    } catch (MockitoException expected) {
        Assertions.assertThat(expected).has(firstMethodInStackTrace("shouldFilterStackTraceWhenThrowingExceptionFromMockHandler"));
    }
}
Also used : MockitoException(org.mockito.exceptions.base.MockitoException) MockitoException(org.mockito.exceptions.base.MockitoException) Test(org.junit.Test)

Example 40 with MockitoException

use of org.mockito.exceptions.base.MockitoException in project mockito by mockito.

the class StackTraceFilteringTest method shouldFilterStacktraceWhenInOrderVerifies.

@Test
public void shouldFilterStacktraceWhenInOrderVerifies() {
    try {
        InOrder inOrder = inOrder(mock);
        inOrder.verify(null);
        fail();
    } catch (MockitoException expected) {
        Assertions.assertThat(expected).has(firstMethodInStackTrace("shouldFilterStacktraceWhenInOrderVerifies"));
    }
}
Also used : InOrder(org.mockito.InOrder) MockitoException(org.mockito.exceptions.base.MockitoException) Test(org.junit.Test)

Aggregations

MockitoException (org.mockito.exceptions.base.MockitoException)51 Test (org.junit.Test)29 UnsupportedTerminal (jline.UnsupportedTerminal)12 ConsoleReader (jline.console.ConsoleReader)12 GeogigCLI (org.locationtech.geogig.cli.GeogigCLI)12 Field (java.lang.reflect.Field)4 InvocationBuilder (org.mockito.internal.invocation.InvocationBuilder)3 ThrowsException (org.mockito.internal.stubbing.answers.ThrowsException)3 ParameterizedConstructorInstantiator (org.mockito.internal.util.reflection.FieldInitializer.ParameterizedConstructorInstantiator)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URL (java.net.URL)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 InOrder (org.mockito.InOrder)2 Spy (org.mockito.Spy)2 Instantiator (org.mockito.internal.creation.instance.Instantiator)2 MockHandlerImpl (org.mockito.internal.handler.MockHandlerImpl)2 InvocationMatcher (org.mockito.internal.invocation.InvocationMatcher)2 FieldInitializationReport (org.mockito.internal.util.reflection.FieldInitializationReport)2