public void inject(Object aComponent) {
if (aComponent != null) {
if (!clazz.isInstance(aComponent)) {
- throw new RuntimeException("Object '" + aComponent +
+ throw new IllegalArgumentException("Object '" + aComponent +
"' is of type " + aComponent.getClass().getName() +
" but expected " + clazz.getName());
}
.getLogger(CdiInjectorFactory.class.getName());
private BeanManager beanManager;
-
+
/**
- * Constructs the factory using the default bean manager.
+ * Constructs the factory using a default bean manager.
+ *
+ * @throws IllegalArgumentException If bean manager is null.
*/
public CdiInjectorFactory() {
this(BeanManagerLookup.lookup());
* Constructs the factory using an explicit bean manager.
*
* @param aBeanManager
+ * @throws IllegalArgumentException If bean manager is null.
*/
public CdiInjectorFactory(BeanManager aBeanManager) {
+ if ( aBeanManager == null ) {
+ throw new IllegalArgumentException("Bean manager is null");
+ }
beanManager = aBeanManager;
}
@Override
public Injector create(Class aClass) {
- if (beanManager == null) {
- // Typically for unit test.
- return new Injector() {
- @Override
- public void inject(Object aComponent) {
- // Empty.
- }
- };
- }
return new CdiInjector(beanManager, aClass);
}