Search in sources :

Example 31 with MockitoException

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

the class FieldInitializer method initialize.

/**
     * Initialize field if not initialized and return the actual instance.
     *
     * @return Actual field instance.
     */
public FieldInitializationReport initialize() {
    final AccessibilityChanger changer = new AccessibilityChanger();
    changer.enableAccess(field);
    try {
        return acquireFieldInstance();
    } catch (IllegalAccessException e) {
        throw new MockitoException("Problems initializing field '" + field.getName() + "' of type '" + field.getType().getSimpleName() + "'", e);
    } finally {
        changer.safelyDisableAccess(field);
    }
}
Also used : MockitoException(org.mockito.exceptions.base.MockitoException)

Example 32 with MockitoException

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

the class ParameterizedConstructorInstantiatorTest method should_fail_if_no_parameterized_constructor_found___excluding_inner_and_others_kind_of_types.

@Test
public void should_fail_if_no_parameterized_constructor_found___excluding_inner_and_others_kind_of_types() throws Exception {
    try {
        new ParameterizedConstructorInstantiator(this, field("withNoArgConstructor"), resolver).instantiate();
        fail();
    } catch (MockitoException me) {
        assertThat(me.getMessage()).contains("no parameterized constructor").contains("withNoArgConstructor").contains("NoArgConstructor");
    }
}
Also used : ParameterizedConstructorInstantiator(org.mockito.internal.util.reflection.FieldInitializer.ParameterizedConstructorInstantiator) MockitoException(org.mockito.exceptions.base.MockitoException) Test(org.junit.Test)

Example 33 with MockitoException

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

the class InvocationContainerImplStubbingTest method should_validate_throwable.

@Test
public void should_validate_throwable() throws Throwable {
    try {
        invocationContainerImpl.addAnswer(new ThrowsException(null));
        fail();
    } catch (MockitoException e) {
    }
}
Also used : ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) MockitoException(org.mockito.exceptions.base.MockitoException) Test(org.junit.Test)

Example 34 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 35 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)

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