KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > defaults > issues > Issue0191TestCase


1 package org.picocontainer.defaults.issues;
2
3 import junit.framework.TestCase;
4 import org.picocontainer.MutablePicoContainer;
5 import org.picocontainer.defaults.DefaultPicoContainer;
6 import org.picocontainer.defaults.UnsatisfiableDependenciesException;
7
8 public class Issue0191TestCase extends TestCase {
9
10     static int sharkCount = 0 ;
11     static int codCount = 0 ;
12
13     /*
14       This bug as descripbed in the bug report, cannot be reproduced. Needs work.
15     */

16     public void testTheBug()
17     {
18         MutablePicoContainer pico = new DefaultPicoContainer( ) ;
19         pico.registerComponentImplementation(Shark.class);
20         pico.registerComponentImplementation(Cod.class);
21         try {
22             pico.registerComponentImplementation(Bowl.class);
23             Bowl bowl = (Bowl) pico.getComponentInstance(Bowl.class);
24             fail("Should have barfed here with UnsatisfiableDependenciesException");
25             Fish[] fishes = bowl.getFishes( ) ;
26             for( int i = 0 ; i < fishes.length ; i++ )
27                 System.out.println( "fish["+i+"]="+fishes[i] ) ;
28         } catch (UnsatisfiableDependenciesException e) {
29             // expected, well except that there is supposed to be a different bug here.
30
}
31     }
32
33
34      class Bowl
35     {
36         private final Fish[] fishes;
37         private final Cod[] cods;
38         public Bowl(Fish[] fishes, Cod[] cods)
39         {
40             this.fishes = fishes;
41             this.cods = cods;
42         }
43         public Fish[] getFishes()
44         {
45             return fishes;
46         }
47         public Cod[] getCods()
48         {
49             return cods;
50         }
51
52     }
53
54     public interface Fish
55     {
56     }
57
58     class Cod implements Fish
59     {
60         int instanceNum ;
61         public Cod( ) { instanceNum = codCount++ ; } ;
62         public String JavaDoc toString( ) {
63             return "Cod #" + instanceNum ;
64         }
65     }
66
67     class Shark implements Fish
68     {
69         int instanceNum ;
70         public Shark( ) { instanceNum = sharkCount++ ; } ;
71         public String JavaDoc toString( ) {
72             return "Shark #" + instanceNum ;
73         }
74     }
75
76 }
77
Popular Tags