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