001 /*****************************************************************************
002 * Copyright (C) PicoContainer Organization. All rights reserved. *
003 * ------------------------------------------------------------------------- *
004 * The software in this package is published under the terms of the BSD *
005 * style license a copy of which has been included with this distribution in *
006 * the LICENSE.txt file. *
007 * *
008 * Original code by *
009 *****************************************************************************/
010 package org.picocontainer.defaults.issues;
011
012 import junit.framework.TestCase;
013 import org.picocontainer.MutablePicoContainer;
014 import org.picocontainer.injectors.AbstractInjector;
015 import org.picocontainer.DefaultPicoContainer;
016
017 public final class Issue0191TestCase extends TestCase {
018
019 static int sharkCount = 0 ;
020 static int codCount = 0 ;
021
022 /*
023 This bug as descripbed in the bug report, cannot be reproduced. Needs work.
024 */
025 public void testTheBug()
026 {
027 MutablePicoContainer pico = new DefaultPicoContainer( ) ;
028 pico.addComponent(Shark.class);
029 pico.addComponent(Cod.class);
030 try {
031 pico.addComponent(Bowl.class);
032 Bowl bowl = pico.getComponent(Bowl.class);
033 fail("Should have barfed here with UnsatisfiableDependenciesException");
034 Fish[] fishes = bowl.getFishes( ) ;
035 for( int i = 0 ; i < fishes.length ; i++ )
036 System.out.println( "fish["+i+"]="+fishes[i] ) ;
037 } catch (AbstractInjector.UnsatisfiableDependenciesException e) {
038 // expected, well except that there is supposed to be a different bug here.
039 }
040 }
041
042
043 class Bowl
044 {
045 private final Fish[] fishes;
046 private final Cod[] cods;
047 public Bowl(Fish[] fishes, Cod[] cods)
048 {
049 this.fishes = fishes;
050 this.cods = cods;
051 }
052 public Fish[] getFishes()
053 {
054 return fishes;
055 }
056 public Cod[] getCods()
057 {
058 return cods;
059 }
060
061 }
062
063 public interface Fish
064 {
065 }
066
067 final class Cod implements Fish
068 {
069 final int instanceNum ;
070 public Cod( ) { instanceNum = codCount++ ; }
071
072 public String toString( ) {
073 return "Cod #" + instanceNum ;
074 }
075 }
076
077 final class Shark implements Fish
078 {
079 final int instanceNum ;
080 public Shark( ) { instanceNum = sharkCount++ ; }
081
082 public String toString( ) {
083 return "Shark #" + instanceNum ;
084 }
085 }
086
087 }