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);
}
}
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");
}
}
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) {
}
}
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) {
}
}
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");
}
}
Aggregations