Added:
trunk/lib/build/jarjar/
trunk/lib/build/jarjar/jarjar-1.0rc6.jar (contents, props changed)
trunk/lib/core/google-collections/
trunk/lib/core/google-collections/google-collect-snapshot-20071022.jar
(contents, props changed)
trunk/lib/core/google-collections/javadoc-snapshot-20071022.zip
(contents, props changed)
trunk/lib/core/google-collections/src-snapshot-20071022.zip
(contents, props changed)
Modified:
trunk/.classpath
trunk/build.xml
trunk/src/atunit/guice/GuiceContainer.java
trunk/test/atunit/guice/GuiceContainerTests.java
Log:
Issue 4: don't bind indistinguishable mock/stub fields.
Modified: trunk/.classpath
==============================================================================
--- trunk/.classpath (original)
+++ trunk/.classpath Mon Nov 19 18:59:41 2007
@@ -17,6 +17,12 @@
<classpathentry kind="lib" path="lib/spring/spring-core.jar" sourcepath="lib/spring/spring-src.zip"/>
<classpathentry kind="lib" path="lib/spring/log4j-1.2.14.jar"/>
<classpathentry kind="lib" path="lib/spring/commons-logging.jar"/>
+ <classpathentry kind="lib"
path="lib/core/google-collections/google-collect-snapshot-20071022.jar" sourcepath="lib/core/google-collections/src-snapshot-20071022.zip">
+ <attributes>
+ <attribute name="javadoc_location" value="jar:platform:/resource/atunit/lib/core/google-collections/javadoc-snapshot-20071022.zip!/"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="lib" path="lib/build/jarjar/jarjar-1.0rc6.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: trunk/build.xml
==============================================================================
--- trunk/build.xml (original)
+++ trunk/build.xml Mon Nov 19 18:59:41 2007
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="atunit" default="dist">
- <property name="version" value="0.7"/>
+ <property name="version" value="0.8"/>
<property name="ant.build.javac.source" value="1.5"/>
@@ -25,7 +25,7 @@
</path>
- <taskdef resource="svntask.properties" classpathref="build.classpath"/>
+ <taskdef resource="svntask.properties" classpathref="build.classpath"/>
<target name="compile" description="compile source">
<mkdir dir="${build.dir}/classes"/>
@@ -84,7 +84,11 @@
</target>
<target name="jar" depends="compile,test" description="package into jars">
- <jar destfile="${build.dir}/${ant.project.name}-${version}.jar" basedir="${build.dir}/classes"/>
+ <taskdef name="jarjar"
classname="com.tonicsystems.jarjar.JarJarTask" classpathref="build.classpath"/>
+ <jarjar destfile="${build.dir}/${ant.project.name}-${version}.jar" basedir="${build.dir}/classes">
+ <zipfileset src="${lib.dir}/core/google-collections/google-collect-snapshot-20071022.jar"/>
+ <rule pattern="com.google.common.**" result="atunit.lib.@0"/>
+ </jarjar>
</target>
<target name="dist" depends="clean,jar,docs"/>
Added: trunk/lib/build/jarjar/jarjar-1.0rc6.jar
==============================================================================
Binary file. No diff available.
Added: trunk/lib/core/google-collections/google-collect-snapshot-20071022.jar
==============================================================================
Binary file. No diff available.
Added: trunk/lib/core/google-collections/javadoc-snapshot-20071022.zip
==============================================================================
Binary file. No diff available.
Added: trunk/lib/core/google-collections/src-snapshot-20071022.zip
==============================================================================
Binary file. No diff available.
Modified: trunk/src/atunit/guice/GuiceContainer.java
==============================================================================
--- trunk/src/atunit/guice/GuiceContainer.java (original)
+++ trunk/src/atunit/guice/GuiceContainer.java Mon Nov 19 18:59:41 2007
@@ -16,13 +16,23 @@
package atunit.guice;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Map;
+import java.util.Set;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.Sets;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
+import com.google.inject.binder.AnnotatedBindingBuilder;
+import com.google.inject.binder.LinkedBindingBuilder;
import atunit.core.Container;
@@ -52,12 +62,22 @@
@Override
@SuppressWarnings("unchecked")
protected void configure() {
+
+ // map field values by type
+ Multimap<Class, Field> fieldsByType = Multimaps.newHashMultimap();
for ( Field field : fields.keySet() ) {
- Class fieldType = field.getType();
- bind(fieldType).toInstance(fields.get(field));
+ fieldsByType.put(field.getType(), field);
+ }
+
+ // for any types that don't have duplicates, bind instances.
+ for ( Class 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));
+ }
}
}
-
}
-
+
}
Modified: trunk/test/atunit/guice/GuiceContainerTests.java
==============================================================================
--- trunk/test/atunit/guice/GuiceContainerTests.java (original)
+++ trunk/test/atunit/guice/GuiceContainerTests.java Mon Nov 19
18:59:41 2007
@@ -1,18 +1,29 @@
package atunit.guice;
+import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import java.lang.reflect.Field;
+import java.util.Map;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
+import org.junit.runner.RunWith;
+
+import com.google.common.collect.Maps;
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+import atunit.AtUnit;
+import atunit.Container;
import atunit.example.ExampleGuiceTest;
public class GuiceContainerTests {
-JUnitCore junit;
+ JUnitCore junit;
@Before
public void setUp() {
@@ -25,5 +36,31 @@
Result result = junit.run(ExampleGuiceTest.class);
assertTrue(result.wasSuccessful());
assertEquals(2, result.getRunCount());
+ }
+
+
+ @Test
+ public void tDuplicateFields() throws Exception {
+ GuiceContainer container = new GuiceContainer();
+ Map<Field, Object> fieldValues = Maps.newHashMap();
+ fieldValues.put(
DuplicateFields.class.getDeclaredField("field1"), "field 1" );
+ fieldValues.put(
DuplicateFields.class.getDeclaredField("field2"), "field 2" );
+ fieldValues.put( DuplicateFields.class.getDeclaredField("field3"),
new Integer(3));
+
+ DuplicateFields df =
(DuplicateFields)container.createTest(DuplicateFields.class, fieldValues);
+
+
+ // Guice should have had to fill these in all by itself, because
+ // GuiceContainer should have ignored the undifferentiated fields
+ assertFalse("field 1".equals(df.field1));
+ assertFalse("field 2".equals(df.field2));
+
+ // this should have our value
+ assertEquals(3, df.field3.intValue());
+ }
+ protected static class DuplicateFields {
+ @Inject public String field1;
+ @Inject public String field2;
+ @Inject public Integer field3;
}
}