-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If all reasonable sources are filtered via skipSource, then show the …
…source as "unknown source" instead of InjectorShell.build (which should be an internal detail). PiperOrigin-RevId: 358853443
- Loading branch information
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.google.inject.spi; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.google.inject.Guice; | ||
import com.google.inject.Module; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
/** Tests sources are set correctly in elements. */ | ||
@RunWith(JUnit4.class) | ||
public final class SourcesTest { | ||
|
||
@Test | ||
public void entirelyFilteredSourceShowsAsUnknown() { | ||
ElementSource source = | ||
(ElementSource) | ||
Guice.createInjector( | ||
new AbstractModule() { | ||
@Override | ||
protected void configure() { | ||
binder().skipSources(getClass()).bind(String.class).toInstance("Foo"); | ||
} | ||
}) | ||
.getBinding(String.class) | ||
.getSource(); | ||
assertThat(source.getDeclaringSource()).isEqualTo("[unknown source]"); | ||
} | ||
|
||
@Test | ||
public void unfilteredShowsCorrectly() { | ||
Module m = | ||
new AbstractModule() { | ||
@Override | ||
protected void configure() { | ||
binder().bind(String.class).toInstance("Foo"); | ||
} | ||
}; | ||
ElementSource source = | ||
(ElementSource) Guice.createInjector(m).getBinding(String.class).getSource(); | ||
StackTraceElement ste = (StackTraceElement) source.getDeclaringSource(); | ||
assertThat(ste.getClassName()).isEqualTo(m.getClass().getName()); | ||
assertThat(ste.getMethodName()).isEqualTo("configure"); | ||
} | ||
} |