Modified:
branches/1.0/build.xml
branches/1.0/src/atunit/guice/GuiceContainer.java
branches/1.0/test/atunit/guice/GuiceContainerTests.java
Log:
merged fixes from trunk revisions 33 and 35, bumped version to 1.0.1
Modified: branches/1.0/build.xml
==============================================================================
--- branches/1.0/build.xml (original)
+++ branches/1.0/build.xml Mon Mar 24 08:33:20 2008
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="atunit" default="dist">
- <property name="version" value="1.0"/>
+ <property name="version" value="1.0.1"/>
<property name="ant.build.javac.source" value="1.5"/>
@@ -101,7 +101,13 @@
</jar>
</target>
- <target name="dist" depends="clean,jar,docs"/>
+ <target name="dist" depends="clean,jar">
+ <zip destfile="${build.dir}/${ant.project.name}-${version}.zip">
+ <zipfileset dir="${build.dir}" includes="*.jar"/>
+ <zipfileset file="COPYING"/>
+ <zipfileset dir="${doc.dir}" prefix="doc/"/>
+ </zip>
+ </target>
<target name="test" depends="compile" description="execute unit tests">
<delete dir="${build.dir}/testoutput"/>
Modified: branches/1.0/src/atunit/guice/GuiceContainer.java
==============================================================================
--- branches/1.0/src/atunit/guice/GuiceContainer.java (original)
+++ branches/1.0/src/atunit/guice/GuiceContainer.java Mon Mar 24
08:33:20 2008
@@ -17,6 +17,7 @@
package atunit.guice;
import java.lang.reflect.Field;
+import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Map;
@@ -26,7 +27,9 @@
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
+import com.google.inject.Key;
import com.google.inject.Module;
+import com.google.inject.TypeLiteral;
import atunit.core.Container;
@@ -58,17 +61,18 @@
protected void configure() {
// map field values by type
- Multimap<Class, Field> fieldsByType = Multimaps.newHashMultimap();
+ Multimap<Type, Field> fieldsByType = Multimaps.newHashMultimap();
for ( Field field : fields.keySet() ) {
- fieldsByType.put(field.getType(), field);
+ fieldsByType.put(field.getGenericType(), field);
}
// for any types that don't have duplicates, bind instances.
- for ( Class type : fieldsByType.keySet() ) {
+ for ( Type type : fieldsByType.keySet() ) {
Collection<Field> fields = fieldsByType.get(type);
if ( fields.size() == 1 ) {
Field field = Iterables.getOnlyElement(fields);
- bind(type).toInstance(this.fields.get(field));
+ TypeLiteral literal = TypeLiteral.get(type);
+ bind(literal).toInstance(this.fields.get(field));
}
}
}
Modified: branches/1.0/test/atunit/guice/GuiceContainerTests.java
==============================================================================
--- branches/1.0/test/atunit/guice/GuiceContainerTests.java (original)
+++ branches/1.0/test/atunit/guice/GuiceContainerTests.java Mon Mar 24
08:33:20 2008
@@ -3,6 +3,8 @@
import static org.junit.Assert.*;
import java.lang.reflect.Field;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import org.junit.Before;
@@ -10,6 +12,7 @@
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
+import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.inject.Inject;
@@ -58,6 +61,17 @@
// this should have our value
assertEquals(3, df.field3.intValue());
}
+
+ @Test
+ public void tGenericFieldType() throws Exception {
+ GuiceContainer container = new GuiceContainer();
+ Map<Field,Object> fieldValues = Maps.newHashMap();
+ List<String> stringList = Lists.newLinkedList();
+ fieldValues.put(
GenericFieldType.class.getDeclaredField("stringList"), stringList);
+ GenericFieldType gft =
(GenericFieldType)container.createTest(GenericFieldType.class, fieldValues);
+
+ assertSame(stringList, gft.stringList);
+ }
public static class Inheritance extends ExampleGuiceTest {}
@@ -65,5 +79,9 @@
@Inject public String field1;
@Inject public String field2;
@Inject public Integer field3;
+ }
+
+ protected static class GenericFieldType {
+ @Inject public List<String> stringList;
}
}