From b074e39fb485cc61ca0ed18ca2635fb24381c6eb Mon Sep 17 00:00:00 2001 From: erik Date: Thu, 15 Jul 2010 13:48:52 +0000 Subject: [PATCH] --- .../java/org/wamblee/cdi/CdiInjector.java | 2 +- .../org/wamblee/cdi/CdiInjectorFactory.java | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/support/cdi/src/main/java/org/wamblee/cdi/CdiInjector.java b/support/cdi/src/main/java/org/wamblee/cdi/CdiInjector.java index b0ce9071..ccf716c9 100644 --- a/support/cdi/src/main/java/org/wamblee/cdi/CdiInjector.java +++ b/support/cdi/src/main/java/org/wamblee/cdi/CdiInjector.java @@ -56,7 +56,7 @@ public class CdiInjector implements Injector { 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()); } diff --git a/support/cdi/src/main/java/org/wamblee/cdi/CdiInjectorFactory.java b/support/cdi/src/main/java/org/wamblee/cdi/CdiInjectorFactory.java index 2237648b..c41f2d98 100644 --- a/support/cdi/src/main/java/org/wamblee/cdi/CdiInjectorFactory.java +++ b/support/cdi/src/main/java/org/wamblee/cdi/CdiInjectorFactory.java @@ -35,9 +35,11 @@ public class CdiInjectorFactory implements InjectorFactory { .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()); @@ -47,22 +49,17 @@ public class CdiInjectorFactory implements InjectorFactory { * 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); } -- 2.31.1