001 package org.picocontainer.defaults.issues;
002
003 import junit.framework.TestCase;
004 import org.picocontainer.MutablePicoContainer;
005 import org.picocontainer.defaults.DefaultPicoContainer;
006 import org.picocontainer.defaults.UnsatisfiableDependenciesException;
007
008 public class Issue0191TestCase extends TestCase {
009
010 static int sharkCount = 0 ;
011 static int codCount = 0 ;
012
013 /*
014 This bug as descripbed in the bug report, cannot be reproduced. Needs work.
015 */
016 public void testTheBug()
017 {
018 MutablePicoContainer pico = new DefaultPicoContainer( ) ;
019 pico.registerComponentImplementation(Shark.class);
020 pico.registerComponentImplementation(Cod.class);
021 try {
022 pico.registerComponentImplementation(Bowl.class);
023 Bowl bowl = (Bowl) pico.getComponentInstance(Bowl.class);
024 fail("Should have barfed here with UnsatisfiableDependenciesException");
025 Fish[] fishes = bowl.getFishes( ) ;
026 for( int i = 0 ; i < fishes.length ; i++ )
027 System.out.println( "fish["+i+"]="+fishes[i] ) ;
028 } catch (UnsatisfiableDependenciesException e) {
029 // expected, well except that there is supposed to be a different bug here.
030 }
031 }
032
033
034 class Bowl
035 {
036 private final Fish[] fishes;
037 private final Cod[] cods;
038 public Bowl(Fish[] fishes, Cod[] cods)
039 {
040 this.fishes = fishes;
041 this.cods = cods;
042 }
043 public Fish[] getFishes()
044 {
045 return fishes;
046 }
047 public Cod[] getCods()
048 {
049 return cods;
050 }
051
052 }
053
054 public interface Fish
055 {
056 }
057
058 class Cod implements Fish
059 {
060 int instanceNum ;
061 public Cod( ) { instanceNum = codCount++ ; } ;
062 public String toString( ) {
063 return "Cod #" + instanceNum ;
064 }
065 }
066
067 class Shark implements Fish
068 {
069 int instanceNum ;
070 public Shark( ) { instanceNum = sharkCount++ ; } ;
071 public String toString( ) {
072 return "Shark #" + instanceNum ;
073 }
074 }
075
076 }