Skip to content

Commit

Permalink
Add a test for an optional binder linking to a jit binding due to a `…
Browse files Browse the repository at this point in the history
…getProvider` call.

PiperOrigin-RevId: 720198330
  • Loading branch information
lukesandberg authored and Guice Team committed Jan 27, 2025
1 parent b673643 commit a376396
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions core/test/com/google/inject/internal/OptionalBinderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,25 @@ public void testCompareEqualsAgainstOtherAnnotation() {
assertFalse(other1.equals(other2));
}

static final class JitInjectable {
@Inject
JitInjectable() {}
}

public void testOptionalBinderAndProviderLookup() {
Optional<JitInjectable> optional =
Guice.createInjector(
new AbstractModule() {
@Override
protected void configure() {
OptionalBinder.newOptionalBinder(binder(), JitInjectable.class);
getProvider(JitInjectable.class);
}
})
.getInstance(new Key<Optional<JitInjectable>>() {});
assertThat(optional).isPresent();
}

/**
* Returns the short name for a module instance. Used to get the name of the anoymous class that
* can change depending on the order the module intance is created.
Expand Down

0 comments on commit a376396

Please sign in to comment.