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;
011
012import org.junit.Test;
013
014/**
015 * Uncomment all the tests in this class (as well as the obvious places in
016 * ConstructorInjectionComponentAdapter) in order to run with generics support
017 * Requires JDK 1.5 with generics enabled.
018 * 
019 * @author Aslak Hellesøy
020 */
021public class GenericsTestCase {
022    @Test public void testDummy() {
023
024    }
025
026    /*
027    private MutablePicoContainer pico;
028    private Shark shark;
029    private Cod cod;
030    private Bowl bowl;
031
032    protected void setUp() throws Exception {
033        pico = new DefaultPicoContainer();
034
035        shark = new Shark();
036        cod = new Cod();
037
038        pico.addAdapter("shark", shark);
039        pico.addAdapter(cod);
040        pico.addAdapter(Bowl.class);
041
042        bowl = (Bowl) pico.getComponent(Bowl.class);
043    }
044
045    public static interface Fish {
046    }
047
048    public static class Cod implements Fish{
049    }
050
051    public static class Shark implements Fish{
052    }
053
054    public static class Bowl {
055        private final Collection<Fish> fishes;
056        private final Set<Cod> cods;
057        private final Map<String, Fish> stringFishMap;
058        private final Map<Object, Shark> objectSharkMap;
059
060        public Bowl(Collection<Fish> fishes, Set<Cod> cods, Map<String,Fish> stringFishMap, Map<Object,Shark> objectSharkMap) {
061            this.fishes = fishes;
062            this.cods = cods;
063            this.stringFishMap = stringFishMap;
064            this.objectSharkMap = objectSharkMap;
065        }
066
067        public Collection<Fish> getFishes() {
068            return fishes;
069        }
070
071        public Set<Cod> getCods() {
072            return cods;
073        }
074
075        public Map<String,Fish> getStringFishMap() {
076            return stringFishMap;
077        }
078
079        public Map<Object, Shark> getObjectSharkMap() {
080            return objectSharkMap;
081        }
082    }
083
084    @Test public void testShouldCreateBowlWithFishCollection() {
085        Collection<Fish> fishes = bowl.getFishes();
086        assertEquals(2, fishes.size());
087        assertTrue(fishes.contains(shark));
088        assertTrue(fishes.contains(cod));
089
090        Set<Cod> cods = bowl.getCods();
091        assertEquals(1, cods.size());
092        assertTrue(cods.contains(cod));
093    }
094
095    @Test public void testShouldFilterMapByKeyType() {
096        Map<String, Fish> fishMap = bowl.getStringFishMap();
097        assertEquals(1, fishMap.size());
098        assertSame(shark, fishMap.get("shark"));
099    }
100
101    @Test public void testShouldFilterMapByValueType() {
102        Map<Object, Shark> fishMap = bowl.getObjectSharkMap();
103        assertEquals(1, fishMap.size());
104        assertSame(shark, fishMap.get("shark"));
105    }
106
107    public static class UngenericCollectionBowl {
108        public UngenericCollectionBowl(Collection fish) {
109        }
110    }
111
112    @Test public void testShouldNotInstantiateCollectionForUngenericCollectionParameters() {
113        pico.addAdapter(UngenericCollectionBowl.class);
114        try {
115            pico.getComponent(UngenericCollectionBowl.class);
116            fail();
117        } catch (UnsatisfiableDependenciesException e) {
118            // expected
119        }
120    }
121
122    public static class UngenericMapBowl {
123        public UngenericMapBowl(Map fish) {
124        }
125    }
126
127    @Test public void testShouldNotInstantiateMapForUngenericMapParameters() {
128        pico.addAdapter(UngenericMapBowl.class);
129        try {
130            pico.getComponent(UngenericMapBowl.class);
131            fail();
132        } catch (UnsatisfiableDependenciesException e) {
133            // expected
134        }
135    }
136
137    public static class AnotherGenericCollectionBowl {
138        private final Collection<String> strings;
139
140        public AnotherGenericCollectionBowl(Collection<String> strings) {
141            this.strings = strings;
142        }
143
144        public Collection<String> getStrings() {
145            return strings;
146        }
147    }
148
149    @Test public void testShouldInstantiateAmptyCollectionForAnotherGenericCollection() {
150        pico.addAdapter(AnotherGenericCollectionBowl.class);
151        AnotherGenericCollectionBowl anotherGenericCollectionBowl = (AnotherGenericCollectionBowl) pico.getComponent(AnotherGenericCollectionBowl.class);
152        assertEquals(0, anotherGenericCollectionBowl.getStrings().size());
153    }
154*/
155}