use of org.mockito.internal.util.reflection.FieldInitializer.ParameterizedConstructorInstantiator 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.internal.util.reflection.FieldInitializer.ParameterizedConstructorInstantiator 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.internal.util.reflection.FieldInitializer.ParameterizedConstructorInstantiator in project mockito by mockito.
the class ParameterizedConstructorInstantiatorTest method should_instantiate_type_if_resolver_provide_matching_types.
@Test
public void should_instantiate_type_if_resolver_provide_matching_types() throws Exception {
Observer observer = mock(Observer.class);
Map map = mock(Map.class);
given(resolver.resolveTypeInstances(Matchers.<Class<?>[]>anyVararg())).willReturn(new Object[] { observer, map });
new ParameterizedConstructorInstantiator(this, field("withMultipleConstructor"), resolver).instantiate();
assertNotNull(withMultipleConstructor);
assertNotNull(withMultipleConstructor.observer);
assertNotNull(withMultipleConstructor.map);
}
use of org.mockito.internal.util.reflection.FieldInitializer.ParameterizedConstructorInstantiator 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.internal.util.reflection.FieldInitializer.ParameterizedConstructorInstantiator in project mockito by mockito.
the class ParameterizedConstructorInstantiatorTest method should_instantiate_type_with_vararg_constructor.
@Test
public void should_instantiate_type_with_vararg_constructor() throws Exception {
Observer[] vararg = new Observer[] {};
given(resolver.resolveTypeInstances(Matchers.<Class<?>[]>anyVararg())).willReturn(new Object[] { "", vararg });
new ParameterizedConstructorInstantiator(this, field("withVarargConstructor"), resolver).instantiate();
assertNotNull(withVarargConstructor);
}
Aggregations