KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > tests > jfun > yan > ManualContainerTestCase


1 /*
2  * Created on Mar 20, 2005
3  *
4  * Author Ben Yu
5  * ZBS
6  */

7 package tests.jfun.yan;
8 import jfun.yan.*;
9 import jfun.yan.containers.*;
10 import junit.framework.TestCase;
11 import junit.framework.TestSuite;
12 import tests.jfun.yan.testmodel.*;
13
14 /**
15  * Zephyr Business Solution
16  *
17  * @author Ben Yu
18  *
19  */

20 public class ManualContainerTestCase extends TestCase {
21   public static void main(String JavaDoc[] args){
22     tests.jfun.yan.Utils.runTest(suite());
23   }
24   private static TestSuite suite(){
25     return new TestSuite(ManualContainerTestCase.class);
26   }
27   public void testGoodManualWiringWithDirectConfiguration(){
28     final Container yan = new ManualContainer();
29     yan.registerComponent("target", Components.ctor(DependsOnTouchable.class)
30         .withArgument(0, Components.ctor(SimpleTouchable.class)));
31     final DependsOnTouchable dt = (DependsOnTouchable)yan.getInstance("target");
32     assertTrue(dt.getTouchable() instanceof SimpleTouchable);
33   }
34   public void testGoodManualWiringWithReference(){
35     final Container yan = new ManualContainer();
36     yan.registerComponent("target", Components.ctor(DependsOnTouchable.class)
37         .withArgument(0, Components.useKey("touchable")));
38     yan.registerConstructor("touchable", SimpleTouchable.class);
39     final DependsOnTouchable dt = (DependsOnTouchable)yan.getInstance("target");
40     assertTrue(dt.getTouchable() instanceof SimpleTouchable);
41   }
42   public void testBadManualWiring(){
43       final Container yan = new ManualContainer();
44       yan.registerComponent("target", Components.ctor(DependsOnTouchable.class));
45       yan.registerConstructor(Touchable.class, SimpleTouchable.class);
46       try{
47         yan.getInstance("target");
48         fail("should have failed with IrresolveableArgumentException");
49       }
50       catch(IrresolveableArgumentException e){
51         assertEquals("target", e.getComponentKey());
52         assertEquals(0, e.getOrdinalPosition());
53         assertEquals(Touchable.class, e.getParameterType());
54       }
55       try{
56         yan.verify();
57         fail("should have failed with IrresolveableArgumentException");
58       }
59       catch(IrresolveableArgumentException e){
60         assertEquals("target", e.getComponentKey());
61         assertEquals(0, e.getOrdinalPosition());
62         assertEquals(Touchable.class, e.getParameterType());
63       }
64   }
65 }
66
Popular Tags