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