Skip to content

Commit

Permalink
More meaningful unit test for injecting @Raw Config
Browse files Browse the repository at this point in the history
  • Loading branch information
elandau committed Nov 24, 2015
1 parent 2cae60b commit 0d0f315
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import java.util.Properties;

import javax.inject.Inject;
import javax.inject.Provider;

import junit.framework.Assert;

import org.junit.Test;
Expand Down Expand Up @@ -107,22 +110,30 @@ public void testLibrariesOverrideProperties() throws ConfigException {

@Test
public void testMockRemoteConfig() throws ConfigException {
final SettableConfig remote = new DefaultSettableConfig();
remote.setProperty("foo", "set");

Injector injector = Karyon.newBuilder()
.addModules(new ArchaiusKaryonModule(), new AbstractModule() {
@Override
protected void configure() {
bind(Key.get(Config.class, RemoteLayer.class)).toInstance(remote);
bind(Key.get(Config.class, RemoteLayer.class)).toProvider(new Provider<Config>() {
@Inject
@Raw
Config rawConfig;

@Override
public Config get() {
final SettableConfig remote = new DefaultSettableConfig();
remote.setProperty("foo", "foo-" + rawConfig.getString("application_loaded"));
return remote;
}
});
}
})
.start();

Foo foo = injector.getInstance(Foo.class);
Config config = injector.getInstance(Config.class);

assertThat(config.getString("foo"), equalTo("set"));
assertThat(config.getString("foo"), equalTo("foo-true"));
}

Properties singletonProperties(String key, String value) {
Expand Down

0 comments on commit 0d0f315

Please sign in to comment.