assertEquals("a", optionalJxP.get().get());
}
}
public void testDifferentBindingsFail_defaults() {
Module module = new AbstractModule() {
@Override protected void configure() {
OptionalBinder.newOptionalBinder(binder(), String.class).setDefault().toInstance("a");
OptionalBinder.newOptionalBinder(binder(), String.class).setDefault().toInstance("b");
}
};
try {
Guice.createInjector(module);
fail();
} catch (CreationException ce) {
assertEquals(ce.getMessage(), 1, ce.getErrorMessages().size());
assertContains(ce.getMessage(),
"1) A binding to java.lang.String annotated with @"
+ Default.class.getName() + " was already configured at "
+ module.getClass().getName() + ".configure(",
"at " + module.getClass().getName() + ".configure(");
}
}