(no commit message)
authorErik Brakkee <erik@brakkee.org>
Thu, 15 Jul 2010 13:48:52 +0000 (13:48 +0000)
committerErik Brakkee <erik@brakkee.org>
Thu, 15 Jul 2010 13:48:52 +0000 (13:48 +0000)
support/cdi/src/main/java/org/wamblee/cdi/CdiInjector.java
support/cdi/src/main/java/org/wamblee/cdi/CdiInjectorFactory.java

index b0ce90713cb3988ae6f236fb34955b743a3d26a8..ccf716c97d988de7ce0c2bcec3ba844bacf45831 100644 (file)
@@ -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());
             }
index 2237648b0b5b58f91521976886558970eec643a5..c41f2d9863b7040a1b2497bdeb1e1d529095e518 100644 (file)
@@ -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);
     }