1 package org.picocontainer.defaults;2 3 import junit.framework.TestCase;4 5 /**6 * Uncomment all the tests in this class (as well as the obvious places in7 * ConstructorInjectionComponentAdapter) in order to run with generics support8 * Requires JDK 1.5 with generics enabled.9 * 10 * @author Aslak Hellesøy11 * @version $Revision: 1272 $12 */13 public class GenericsTestCase extends TestCase {14 public void testDummy() {15 16 }17 18 /*19 private MutablePicoContainer pico;20 private Shark shark;21 private Cod cod;22 private Bowl bowl;23 24 protected void setUp() throws Exception {25 pico = new DefaultPicoContainer();26 27 shark = new Shark();28 cod = new Cod();29 30 pico.registerComponentInstance("shark", shark);31 pico.registerComponentInstance(cod);32 pico.registerComponentImplementation(Bowl.class);33 34 bowl = (Bowl) pico.getComponentInstance(Bowl.class);35 }36 37 public static interface Fish {38 }39 40 public static class Cod implements Fish{41 }42 43 public static class Shark implements Fish{44 }45 46 public static class Bowl {47 private final Collection<Fish> fishes;48 private final Set<Cod> cods;49 private final Map<String, Fish> stringFishMap;50 private final Map<Object, Shark> objectSharkMap;51 52 public Bowl(Collection<Fish> fishes, Set<Cod> cods, Map<String,Fish> stringFishMap, Map<Object,Shark> objectSharkMap) {53 this.fishes = fishes;54 this.cods = cods;55 this.stringFishMap = stringFishMap;56 this.objectSharkMap = objectSharkMap;57 }58 59 public Collection<Fish> getFishes() {60 return fishes;61 }62 63 public Set<Cod> getCods() {64 return cods;65 }66 67 public Map<String,Fish> getStringFishMap() {68 return stringFishMap;69 }70 71 public Map<Object, Shark> getObjectSharkMap() {72 return objectSharkMap;73 }74 }75 76 public void testShouldCreateBowlWithFishCollection() {77 Collection<Fish> fishes = bowl.getFishes();78 assertEquals(2, fishes.size());79 assertTrue(fishes.contains(shark));80 assertTrue(fishes.contains(cod));81 82 Set<Cod> cods = bowl.getCods();83 assertEquals(1, cods.size());84 assertTrue(cods.contains(cod));85 }86 87 public void testShouldFilterMapByKeyType() {88 Map<String, Fish> fishMap = bowl.getStringFishMap();89 assertEquals(1, fishMap.size());90 assertSame(shark, fishMap.get("shark"));91 }92 93 public void testShouldFilterMapByValueType() {94 Map<Object, Shark> fishMap = bowl.getObjectSharkMap();95 assertEquals(1, fishMap.size());96 assertSame(shark, fishMap.get("shark"));97 }98 99 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 // expected111 }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 // expected126 }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 }