Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elandau committed May 22, 2015
1 parent ed27059 commit 57c2d17
Showing 1 changed file with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.inject.Key;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.multibindings.Multibinder;
import com.google.inject.name.Names;
import com.google.inject.util.Modules;
import com.netflix.archaius.Config;
Expand Down Expand Up @@ -129,16 +130,18 @@ public void test() throws ConfigException {
props.setProperty("env", "prod");

Injector injector = Guice.createInjector(
Modules.override(new ArchaiusModule())
.with(new TestArchaiusOverrideModule() {
@Provides
@Singleton
@RuntimeLayer
public Properties getOverrideProperties() {
return props;
}
})
);
new ArchaiusModule(),
new AbstractModule() {
@Override
protected void configure() {
Multibinder.newSetBinder(binder(), ConfigSeeder.class, RuntimeLayer.class).addBinding().toInstance(new ConfigSeeder() {
@Override
public Config get(Config rootConfig) throws Exception {
return MapConfig.from(props);
}
});
}
});

Config config = injector.getInstance(Config.class);
Assert.assertEquals("prod", config.getString("env"));
Expand All @@ -165,22 +168,20 @@ public void testNamedInjection() throws ConfigException {
props.setProperty("env", "prod");

Injector injector = Guice.createInjector(
Modules.override(new ArchaiusModule())
.with(new TestArchaiusOverrideModule() {
@Provides
@Singleton
@RuntimeLayer
public Properties getOverrideProperties() {
return props;
}
})
,
new AbstractModule() {
protected void configure() {
bind(Named.class).annotatedWith(Names.named("name1")).to(Named1.class);
bind(Named.class).annotatedWith(Names.named("name2")).to(Named2.class);
new ArchaiusModule(),
new AbstractModule() {
@Override
protected void configure() {
Multibinder.newSetBinder(binder(), ConfigSeeder.class, RuntimeLayer.class).addBinding().toInstance(new ConfigSeeder() {
@Override
public Config get(Config rootConfig) throws Exception {
return MapConfig.from(props);
}
});
bind(Named.class).annotatedWith(Names.named("name1")).to(Named1.class);
bind(Named.class).annotatedWith(Names.named("name2")).to(Named2.class);
}
}
}
);

MyService service = injector.getInstance(MyService.class);
Expand Down

0 comments on commit 57c2d17

Please sign in to comment.