Search in sources :

Example 11 with MockitoException

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

the class InvocationContainerImplStubbingTest method should_finish_stubbing_when_wrong_throwable_is_set.

@Test
public void should_finish_stubbing_when_wrong_throwable_is_set() throws Exception {
    state.stubbingStarted();
    try {
        invocationContainerImpl.addAnswer(new ThrowsException(new Exception()));
        fail();
    } catch (MockitoException e) {
        state.validateState();
    }
}
Also used : ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) MockitoException(org.mockito.exceptions.base.MockitoException) ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) MockitoException(org.mockito.exceptions.base.MockitoException) Test(org.junit.Test)

Example 12 with MockitoException

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

the class CallsRealMethodsTest method should_fail_when_calling_real_method_on_interface.

@Test
public void should_fail_when_calling_real_method_on_interface() throws Throwable {
    //given
    Invocation invocationOnInterface = new InvocationBuilder().method("simpleMethod").toInvocation();
    try {
        //when
        new CallsRealMethods().validateFor(invocationOnInterface);
        //then
        Assertions.fail("can not invoke interface");
    } catch (MockitoException expected) {
    }
}
Also used : Invocation(org.mockito.invocation.Invocation) MockitoException(org.mockito.exceptions.base.MockitoException) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 13 with MockitoException

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

the class ParameterizedConstructorInstantiatorTest method should_fail_if_an_argument_instance_type_do_not_match_wanted_type.

@Test
public void should_fail_if_an_argument_instance_type_do_not_match_wanted_type() throws Exception {
    Observer observer = mock(Observer.class);
    Set<?> wrongArg = mock(Set.class);
    given(resolver.resolveTypeInstances(Matchers.<Class<?>[]>anyVararg())).willReturn(new Object[] { observer, wrongArg });
    try {
        new ParameterizedConstructorInstantiator(this, field("withMultipleConstructor"), resolver).instantiate();
        fail();
    } catch (MockitoException e) {
        assertThat(e.getMessage()).contains("argResolver").contains("incorrect types");
    }
}
Also used : ParameterizedConstructorInstantiator(org.mockito.internal.util.reflection.FieldInitializer.ParameterizedConstructorInstantiator) MockitoException(org.mockito.exceptions.base.MockitoException) Observer(java.util.Observer) Test(org.junit.Test)

Example 14 with MockitoException

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

the class ParameterizedConstructorInstantiatorTest method should_report_failure_if_constructor_throws_exception.

@Test
public void should_report_failure_if_constructor_throws_exception() throws Exception {
    given(resolver.resolveTypeInstances(Matchers.<Class<?>[]>anyVararg())).willReturn(new Object[] { null });
    try {
        new ParameterizedConstructorInstantiator(this, field("withThrowingConstructor"), resolver).instantiate();
        fail();
    } catch (MockitoException e) {
        assertThat(e.getMessage()).contains("constructor").contains("raised an exception");
    }
}
Also used : ParameterizedConstructorInstantiator(org.mockito.internal.util.reflection.FieldInitializer.ParameterizedConstructorInstantiator) MockitoException(org.mockito.exceptions.base.MockitoException) Test(org.junit.Test)

Example 15 with MockitoException

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

the class MocksCreationTest method shouldScreamWhenSpyCreatedWithWrongType.

@Test
public void shouldScreamWhenSpyCreatedWithWrongType() {
    //given
    List list = new LinkedList();
    try {
        //when
        mock(List.class, withSettings().spiedInstance(list));
        fail();
    //then
    } catch (MockitoException e) {
    }
}
Also used : MockitoException(org.mockito.exceptions.base.MockitoException) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) 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