use of io.vertigo.core.component.Container in project vertigo by KleeGroup.
the class InjectorTest method testBFail.
@Test
public void testBFail() {
Assertions.assertThrows(DIException.class, () -> {
final B b = DIInjector.newInstance(B.class, new Container() {
@Override
public boolean contains(final String id) {
return false;
}
@Override
public <T> T resolve(final String id, final Class<T> componentClass) {
return null;
}
@Override
public Set<String> keySet() {
return Collections.emptySet();
}
});
nop(b);
});
}
use of io.vertigo.core.component.Container in project vertigo by KleeGroup.
the class ComponentLoader method createInstance.
/**
* Creates a component that use the injector but adds params support.
* @param clazz the clazz of the object to create
* @param container the container of the known components
* @param paramManagerOpt the optional ParamManager needed to use global params resolution
* @param params the local params
* @return the component created
*/
public static <T> T createInstance(final Class<T> clazz, final Container container, final Optional<ParamManager> paramManagerOpt, final Map<String, String> params) {
Assertion.checkNotNull(paramManagerOpt);
Assertion.checkNotNull(params);
// ---
final ComponentParamsContainer paramsContainer = new ComponentParamsContainer(paramManagerOpt, params);
final Container dualContainer = new ComponentDualContainer(container, paramsContainer);
// ---
final T component = DIInjector.newInstance(clazz, dualContainer);
Assertion.checkState(paramsContainer.getUnusedKeys().isEmpty(), "some params are not used :'{0}' in component '{1}'", paramsContainer.getUnusedKeys(), clazz);
return component;
}
use of io.vertigo.core.component.Container in project vertigo by KleeGroup.
the class InjectorTest method testA.
@Test
public void testA() {
final A a = DIInjector.newInstance(A.class, new Container() {
@Override
public boolean contains(final String id) {
return false;
}
@Override
public <T> T resolve(final String id, final Class<T> componentClass) {
return null;
}
@Override
public Set<String> keySet() {
return Collections.emptySet();
}
});
nop(a);
}