Added ObjectConfiguration as a holder for setter configuration (there will be more...
[utils] / system / general / src / test / java / org / wamblee / system / adapters / DefaultContainerTest.java
index 913e39700e04a0dda6a8a72869825ca5fe17b567..07143e3eeee14371cf7f5f31ff3e7aade2c288fc 100644 (file)
@@ -36,4 +36,38 @@ public class DefaultContainerTest extends AdapterTestCase {
         obj = scope.getRuntime("x4");
         assertTrue(obj instanceof X4);
     }
+    
+    public void testConstructorInjectionAndSetterInjection() {
+        ClassConfiguration x1Config = new ClassConfiguration(X1.class);
+        x1Config.getConstructorConfig().getParameters().setValue(0, "hello");
+        
+        X8 x8 = new X8(null); 
+        EVENT_TRACKER.clear();
+
+        DefaultContainer container = new DefaultContainer("top").addComponent(
+                "x1", x1Config).addComponent("x4", X4.class).addComponent("x8", x8);
+
+        Scope scope = container.start();
+        AssertionUtils.assertEquals(new String[] { "x1(hello)", "x4(x1)",
+                "x8.setX4(x4)"},
+                EVENT_TRACKER.getEvents(Thread.currentThread()).toArray());
+
+        Object obj1 = scope.getRuntime("x1");
+        assertTrue(obj1 instanceof X1);
+        Object obj4 = scope.getRuntime("x4");
+        assertTrue(obj4 instanceof X4);
+        Object obj8 = scope.getRuntime("x8");
+        assertSame(x8, obj8);
+        assertSame(obj4, x8.getX4());
+    }
+    
+    public void testWrongObjectType() { 
+        final DefaultContainer container = new DefaultContainer("top");
+        AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
+            @Override
+            public void run() throws Exception {
+                container.addComponent("x", "y", new ObjectConfiguration(Integer.class));   
+            }
+        }, IllegalArgumentException.class);
+    }
 }