From 1440f7475e4a7d3ae9e6e756b3a58572a57e9521 Mon Sep 17 00:00:00 2001 From: Erik Brakkee 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