Revision: 1196
Author: sberlin
Date: Sun Aug 1 09:15:50 2010
Log: minor cleanups of r1195 - put tests in existing OverrideModuleTest
class, bind with a binder that has the PrivateElement's source.
http://code.google.com/p/google-guice/source/detail?r=1196
Modified:
/trunk/src/com/google/inject/util/Modules.java
/trunk/test/com/google/inject/ModulesTest.java
/trunk/test/com/google/inject/OverrideModuleTest.java
=======================================
--- /trunk/src/com/google/inject/util/Modules.java Sun Aug 1 09:01:16 2010
+++ /trunk/src/com/google/inject/util/Modules.java Sun Aug 1 09:15:50 2010
@@ -183,9 +183,10 @@
@Override
public void configure() {
PrivateElements privateElements =
(PrivateElements)Iterables.getOnlyElement(Elements.getElements(baseModule));
-
override(Elements.getModule(privateElements.getElements())).with(overrides).configure(binder());
+ PrivateBinder binder =
binder().withSource(privateElements.getSource());
+
override(Elements.getModule(privateElements.getElements())).with(overrides).configure(binder);
for(Key exposed : privateElements.getExposedKeys()) {
-
binder().withSource(privateElements.getExposedSource(exposed)).expose(exposed);
+
binder.withSource(privateElements.getExposedSource(exposed)).expose(exposed);
}
}
};
=======================================
--- /trunk/test/com/google/inject/ModulesTest.java Sun Aug 1 09:01:16 2010
+++ /trunk/test/com/google/inject/ModulesTest.java Sun Aug 1 09:15:50 2010
@@ -16,9 +16,6 @@
package com.google.inject;
-import static com.google.inject.name.Names.named;
-
-import com.google.inject.name.Named;
import com.google.inject.util.Modules;
import java.util.Arrays;
import junit.framework.TestCase;
@@ -67,49 +64,4 @@
}
};
}
-
- private static final String RESULT = "RESULT";
- private static final String PRIVATE_INPUT = "PRIVATE_INPUT";
- private static final String OVERRIDDEN_INPUT = "FOO";
- private static final String OVERRIDDEN_RESULT = "Size: 3";
- private static final Key<String> RESULT_KEY = Key.get(String.class,
named(RESULT));
- private static final Key<String> INPUT_KEY = Key.get(String.class,
named(PRIVATE_INPUT));
-
-
- public void testExposedBindingOverride() throws Exception {
- Injector inj = Guice.createInjector(
- Modules.override(new ExampleModule()).with(
- new AbstractModule() {
- @Override protected void configure() {
- bind(RESULT_KEY).toInstance(OVERRIDDEN_RESULT);
- }
- }));
- assertEquals(inj.getInstance(RESULT_KEY), OVERRIDDEN_RESULT);
- }
-
- public void testPrivateBindingOverride() throws Exception {
- Injector inj = Guice.createInjector(
- Modules.override(new ExampleModule()).with(
- new AbstractModule() {
- @Override protected void configure() {
- bind(INPUT_KEY).toInstance(OVERRIDDEN_INPUT);
- }
- }));
- assertEquals(inj.getInstance(RESULT_KEY), OVERRIDDEN_RESULT);
- }
-
- public static class ExampleModule extends PrivateModule {
- @Provides @Exposed @Named(RESULT)
- public String provideResult(@Named(PRIVATE_INPUT) String input) {
- return "Size: " + input.length();
- }
-
- @Provides @Named(PRIVATE_INPUT)
- public String provideInput() {
- return "Hello World";
- }
-
- @Override protected void configure() {
- }
- }
-}
+}
=======================================
--- /trunk/test/com/google/inject/OverrideModuleTest.java Sat Jun 27
15:22:54 2009
+++ /trunk/test/com/google/inject/OverrideModuleTest.java Sun Aug 1
09:15:50 2010
@@ -19,6 +19,8 @@
import static com.google.inject.Asserts.assertContains;
import static com.google.inject.Guice.createInjector;
import static com.google.inject.name.Names.named;
+
+import com.google.inject.name.Named;
import com.google.inject.util.Modules;
import static java.lang.annotation.ElementType.TYPE;
import java.lang.annotation.Retention;
@@ -463,4 +465,48 @@
}
};
}
-}
+
+ private static final String RESULT = "RESULT";
+ private static final String PRIVATE_INPUT = "PRIVATE_INPUT";
+ private static final String OVERRIDDEN_INPUT = "FOO";
+ private static final String OVERRIDDEN_RESULT = "Size: 3";
+ private static final Key<String> RESULT_KEY = Key.get(String.class,
named(RESULT));
+ private static final Key<String> INPUT_KEY = Key.get(String.class,
named(PRIVATE_INPUT));
+
+ public void testExposedBindingOverride() throws Exception {
+ Injector inj = Guice.createInjector(
+ Modules.override(new ExampleModule()).with(
+ new AbstractModule() {
+ @Override protected void configure() {
+ bind(RESULT_KEY).toInstance(OVERRIDDEN_RESULT);
+ }
+ }));
+ assertEquals(inj.getInstance(RESULT_KEY), OVERRIDDEN_RESULT);
+ }
+
+ public void testPrivateBindingOverride() throws Exception {
+ Injector inj = Guice.createInjector(
+ Modules.override(new ExampleModule()).with(
+ new AbstractModule() {
+ @Override protected void configure() {
+ bind(INPUT_KEY).toInstance(OVERRIDDEN_INPUT);
+ }
+ }));
+ assertEquals(inj.getInstance(RESULT_KEY), OVERRIDDEN_RESULT);
+ }
+
+ public static class ExampleModule extends PrivateModule {
+ @Provides @Exposed @Named(RESULT)
+ public String provideResult(@Named(PRIVATE_INPUT) String input) {
+ return "Size: " + input.length();
+ }
+
+ @Provides @Named(PRIVATE_INPUT)
+ public String provideInput() {
+ return "Hello World";
+ }
+
+ @Override protected void configure() {
+ }
+ }
+}
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en.