ScopeImpl extends ScopeNode { <T> InternalProvider<? extends T> lookupProvider( Class<T> clazz, String bindingName) { if (clazz == null) { throw new IllegalArgumentException("TP can't get an instance of a null class."); } InternalProvider<? extends T> scopedProvider = getScopedProvider(clazz, bindingName); if (scopedProvider != null) { return scopedProvider; } for (Scope parentScope : parentScopes) { ScopeImpl parentScopeImpl = (ScopeImpl) parentScope; InternalProvider<? extends T> parentScopedProvider = parentScopeImpl.getScopedProvider(clazz, bindingName); if (parentScopedProvider != null) { return parentScopedProvider; } } if (bindingName != null) { throw new RuntimeException( format( "No binding was defined for class %s and name %s " + "in scope %s and its parents %s", clazz.getName(), bindingName, getName(), getParentScopesNames())); } InternalProvider<? extends T> unScopedProviderInPool = getUnUnScopedProvider(clazz, null); if (unScopedProviderInPool != null) { return unScopedProviderInPool; } Factory<T> factory = FactoryLocator.getFactory(clazz); if (factory.hasScopeAnnotation()) { Scope targetScope = factory.getTargetScope(this); InternalScopedProvider<? extends T> newProvider = new InternalScopedProvider<>(targetScope, factory); ScopeImpl targetScopeImpl = (ScopeImpl) targetScope; return targetScopeImpl.installScopedProvider(clazz, null, newProvider, false); } else { final InternalProvider<T> newProvider = new InternalProvider<>(factory); return installUnScopedProvider(clazz, null, newProvider); } } ScopeImpl(Object name); @Override T getInstance(Class<T> clazz); @Override T getInstance(Class<T> clazz, String name); @Override Provider<T> getProvider(Class<T> clazz); @Override Provider<T> getProvider(Class<T> clazz, String name); @Override Lazy<T> getLazy(Class<T> clazz); @Override Lazy<T> getLazy(Class<T> clazz, String name); @Override synchronized Scope installTestModules(Module... modules); @Override Scope installModules(Module... modules); @Override void inject(Object obj); @Override String toString(); @Override Scope openSubScope(Object subScopeName); @Override Scope openSubScope(Object subScopeName, ScopeConfig scopeConfig); @Override void release();  }
@Test(expected = RuntimeException.class) public void testLookup_shouldFail_whenNotFindingABindingForANamedProvider() { new ScopeImpl("").lookupProvider(Foo.class, "Bar"); fail("Should throw an exception"); }