ValueOfConfigurationKeyOrNull implements Function<String, String> { @Override public String apply(String configurationKey) { checkNotNull(configurationKey, "configurationKey"); try { return injector.getInstance(Key.get(String.class, named(configurationKey))); } catch (ConfigurationException e) { return null; } } @Inject private  ValueOfConfigurationKeyOrNull(Injector injector); @Override String apply(String configurationKey);  }
@Test public void testNotThere() { assertEquals(Guice.createInjector().getInstance(ValueOfConfigurationKeyOrNull.class).apply("foo"), null); }
@Test public void testThere() { assertEquals(Guice.createInjector(new AbstractModule() { @Override protected void configure() { bindConstant().annotatedWith(Names.named("foo")).to("bar"); } }).getInstance(ValueOfConfigurationKeyOrNull.class).apply("foo"), "bar"); }
@Test public void testEmptyIsThere() { assertEquals(Guice.createInjector(new AbstractModule() { @Override protected void configure() { bindConstant().annotatedWith(Names.named("foo")).to(""); } }).getInstance(ValueOfConfigurationKeyOrNull.class).apply("foo"), ""); }