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 *****************************************************************************/
010package org.picocontainer.defaults.issues;
011
012import static org.junit.Assert.fail;
013
014import org.junit.Test;
015import org.picocontainer.DefaultPicoContainer;
016import org.picocontainer.MutablePicoContainer;
017import org.picocontainer.injectors.AbstractInjector;
018
019public final class Issue0191TestCase {
020
021    static int sharkCount = 0 ;
022    static int codCount = 0 ;
023
024    /*
025      This bug as descripbed in the bug report, cannot be reproduced. Needs work.
026    */
027    @Test public void testTheBug()
028    {
029        MutablePicoContainer pico = new DefaultPicoContainer( ) ;
030        pico.addComponent(Shark.class);
031        pico.addComponent(Cod.class);
032        try {
033            pico.addComponent(Bowl.class);
034            Bowl bowl = pico.getComponent(Bowl.class);
035            fail("Should have barfed here with UnsatisfiableDependenciesException");
036            Fish[] fishes = bowl.getFishes( ) ;
037            for( int i = 0 ; i < fishes.length ; i++ )
038                System.out.println( "fish["+i+"]="+fishes[i] ) ;
039        } catch (AbstractInjector.UnsatisfiableDependenciesException e) {
040            // expected, well except that there is supposed to be a different bug here.
041        }
042    }
043
044
045     class Bowl
046    {
047        private final Fish[] fishes;
048        private final Cod[] cods;
049        public Bowl(Fish[] fishes, Cod[] cods)
050        {
051            this.fishes = fishes;
052            this.cods = cods;
053        }
054        public Fish[] getFishes()
055        {
056            return fishes;
057        }
058        public Cod[] getCods()
059        {
060            return cods;
061        }
062
063    }
064
065    public interface Fish
066    {
067    }
068
069    final class Cod implements Fish
070    {
071        final int instanceNum ;
072        public Cod( ) { instanceNum = codCount++ ; }
073
074        public String toString( ) {
075            return "Cod #" + instanceNum ;
076        }
077    }
078
079    final class Shark implements Fish
080    {
081        final int instanceNum ;
082        public Shark( ) { instanceNum = sharkCount++ ; }
083
084        public String toString( ) {
085            return "Shark #" + instanceNum ;
086        }
087    }
088
089}