MCPcopy Create free account
hub / github.com/google/guice / testIsScopedNegative

Method testIsScopedNegative

core/test/com/google/inject/ScopesTest.java:817–876  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

815 }
816
817 public void testIsScopedNegative() {
818 final Key<String> a = Key.get(String.class, named("A"));
819 final Key<String> b = Key.get(String.class, named("B"));
820 final Key<String> c = Key.get(String.class, named("C"));
821 final Key<String> d = Key.get(String.class, named("D"));
822 final Key<String> e = Key.get(String.class, named("E"));
823 final Key<String> f = Key.get(String.class, named("F"));
824 final Key<String> g = Key.get(String.class, named("G"));
825 final Key<String> h = Key.get(String.class, named("H"));
826
827 Module customBindings =
828 new AbstractModule() {
829 @Override
830 protected void configure() {
831 bind(a).to(b);
832 bind(b).to(c);
833 bind(c).toProvider(Providers.of("c")).in(Scopes.NO_SCOPE);
834 bind(d).toProvider(Providers.of("d")).in(Singleton.class);
835 install(
836 new PrivateModule() {
837 @Override
838 protected void configure() {
839 bind(f).toProvider(Providers.of("f")).in(Singleton.class);
840 expose(f);
841 }
842 });
843 bind(g).toInstance("g");
844 bind(h).toProvider(Providers.of("h")).asEagerSingleton();
845 }
846
847 @Provides
848 @Named("E")
849 @Singleton
850 String provideE() {
851 return "e";
852 }
853 };
854
855 @SuppressWarnings("unchecked") // we know the module contains only bindings
856 List<Element> moduleBindings = Elements.getElements(customBindings);
857 ImmutableMap<Key<?>, Binding<?>> map = indexBindings(moduleBindings);
858 assertFalse(isCustomScoped(map.get(a)));
859 assertFalse(isCustomScoped(map.get(b)));
860 assertFalse(isCustomScoped(map.get(c)));
861 assertFalse(isCustomScoped(map.get(d)));
862 assertFalse(isCustomScoped(map.get(e)));
863 assertFalse(isCustomScoped(map.get(f)));
864 assertFalse(isCustomScoped(map.get(g)));
865 assertFalse(isCustomScoped(map.get(h)));
866
867 Injector injector = Guice.createInjector(customBindings);
868 assertFalse(isCustomScoped(injector.getBinding(a)));
869 assertFalse(isCustomScoped(injector.getBinding(b)));
870 assertFalse(isCustomScoped(injector.getBinding(c)));
871 assertFalse(isCustomScoped(injector.getBinding(d)));
872 assertFalse(isCustomScoped(injector.getBinding(e)));
873 assertFalse(isCustomScoped(injector.getBinding(f)));
874 assertFalse(isCustomScoped(injector.getBinding(g)));

Callers

nothing calls this directly

Calls 8

getMethod · 0.95
getElementsMethod · 0.95
indexBindingsMethod · 0.95
isCustomScopedMethod · 0.95
createInjectorMethod · 0.95
getBindingMethod · 0.95
namedMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected