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