Skip to content

Commit

Permalink
Add a test to verify that failure in scanning one key doesn't effect …
Browse files Browse the repository at this point in the history
…other bindings that depends on the key.

PiperOrigin-RevId: 359786415
  • Loading branch information
java-team-github-bot authored and Guice Team committed Feb 26, 2021
1 parent 4204006 commit 9dc98cb
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,31 @@ public void failingScanner() {
.isEqualTo(source.toString());
}

@Test
public void sannerFailureDoesNotPropagateDownstream() {
Module module =
new AbstractModule() {
@TestProvides
@Named("foo")
String provideFoo() {
return "FOO";
}

@Provides
@Named("bar")
String providesBar(@Named("foo") String foo) {
return "uses " + foo;
}
};

CreationException exception =
assertThrows(
CreationException.class,
() -> Guice.createInjector(module, scannerModule(new FailingScanner())));
// Verify that failure in binding @Named("foo") doesn't effect bindings that depends on it.
assertThat(exception.getErrorMessages()).hasSize(1);
}

public static class FailingScanner extends ModuleAnnotatedMethodScanner {
@Override
public Set<? extends Class<? extends Annotation>> annotationClasses() {
Expand Down

0 comments on commit 9dc98cb

Please sign in to comment.