/** * Install bindings for scope. */ private void installBindingForScope() { //it's always possible to get access to the scope that contains an injected object. installBoundProvider(Scope.class, null, new InternalProviderImpl<>(this), false); }
private <T> InternalProviderImpl<T> createInternalProvider(Scope scope, Class<?> factoryKeyClass, boolean isProviderClass, boolean isCreatingInstancesInScope, boolean isCreatingSingletonInScope, boolean isProvidingInstancesInScope) { if (isCreatingInstancesInScope) { return new ScopedProviderImpl<>(scope, factoryKeyClass, isProviderClass, isCreatingSingletonInScope, isProvidingInstancesInScope); } else { return new InternalProviderImpl<>(factoryKeyClass, isProviderClass, isCreatingSingletonInScope, isProvidingInstancesInScope); } }
@Test(expected = IllegalArgumentException.class) public void testCreateInternalProviderImpl_shouldFail_whenProviderInstanceIsNull() { //GIVEN //WHEN new InternalProviderImpl((Provider<String>) null, false); //THEN fail("Should throw an exception"); }
@Test(expected = IllegalArgumentException.class) public void testCreateInternalProviderImpl_shouldFail_whenProviderFactoryClassIsNull() { //GIVEN //WHEN new InternalProviderImpl((Class) null, true, false, false); //THEN fail("Should throw an exception"); }
@Test(expected = IllegalArgumentException.class) public void testCreateInternalProviderImpl_shouldFail_whenProviderFactoryIsNull() { //GIVEN //WHEN new InternalProviderImpl((Factory<Provider<String>>) null, true); //THEN fail("Should throw an exception"); }
@Test(expected = IllegalArgumentException.class) public void testCreateInternalProviderImpl_shouldFail_whenFactoryIsNull() { //GIVEN //WHEN new InternalProviderImpl((Factory<String>) null, false); //THEN fail("Should throw an exception"); }
@Test(expected = IllegalArgumentException.class) public void testCreateInternalProviderImpl_shouldFail_whenFactoryClassIsNull() { //GIVEN //WHEN new InternalProviderImpl((Class) null, false, false, false); //THEN fail("Should throw an exception"); }
@Test(expected = IllegalArgumentException.class) public void testCreateInternalProviderImpl_shouldFail_whenInstanceIsNull() { //GIVEN //WHEN new InternalProviderImpl((String) null); //THEN fail("Should throw an exception"); }
} else { final InternalProviderImpl<T> newProvider = new InternalProviderImpl<>(factory, false);
false); case INSTANCE: return new InternalProviderImpl<>(binding.getInstance()); case PROVIDER_INSTANCE: return new InternalProviderImpl<>(binding.getProviderInstance(), binding.isProvidingSingletonInScope()); case PROVIDER_CLASS: return createInternalProvider(this,
/** * Install bindings for scope. */ private void installBindingForScope() { //it's always possible to get access to the scope that contains an injected object. installBoundProvider(Scope.class, null, new InternalProviderImpl<>(this), false); }
public ScopeImpl(Object name) { super(name); //it's always possible to get access to the scope that conitains an injected object. installBoundProvider(Scope.class, null, new InternalProviderImpl<>(this)); }
private <T> InternalProviderImpl<T> createInternalProvider(Scope scope, Class<?> factoryKeyClass, boolean isProviderClass, boolean isScoped) { if (isScoped) { return new ScopedProviderImpl<>(scope, factoryKeyClass, isProviderClass); } else { return new InternalProviderImpl<>(factoryKeyClass, isProviderClass); } }
private <T> InternalProviderImpl<T> createInternalProvider(Scope scope, Class<?> factoryKeyClass, boolean isProviderClass, boolean isCreatingInstancesInScope, boolean isCreatingSingletonInScope, boolean isProvidingInstancesInScope) { if (isCreatingInstancesInScope) { return new ScopedProviderImpl<>(scope, factoryKeyClass, isProviderClass, isCreatingSingletonInScope, isProvidingInstancesInScope); } else { return new InternalProviderImpl<>(factoryKeyClass, isProviderClass, isCreatingSingletonInScope, isProvidingInstancesInScope); } }
/*VisibleForTesting*/ <T> InternalProviderImpl<T> toProvider(Binding<T> binding) { if (binding == null) { throw new IllegalStateException("null binding are not allowed. Should not happen unless getBindingSet is overridden."); } Configuration.instance.checkIllegalBinding(binding); switch (binding.getMode()) { case SIMPLE: return createInternalProvider(this, binding.getKey(), false, binding.isScoped()); case CLASS: return createInternalProvider(this, binding.getImplementationClass(), false, binding.isScoped()); case INSTANCE: return new InternalProviderImpl<>(binding.getInstance()); case PROVIDER_INSTANCE: // to ensure providers do not have to deal with concurrency, we wrap them in a thread safe provider // We do not need to pass the scope here because the provider won't use any scope to create the instance return new InternalProviderImpl<>(binding.getProviderInstance()); case PROVIDER_CLASS: return createInternalProvider(this, binding.getProviderClass(), true, binding.isScoped()); //JACOCO:OFF default: throw new IllegalStateException(format("mode is not handled: %s. This should not happen.", binding.getMode())); //JACOCO:ON } }
} else { final InternalProviderImpl<T> newProvider = new InternalProviderImpl<>(factory, false);
} else { final InternalProviderImpl<T> newProvider = new InternalProviderImpl<>(factory, false);
false); case INSTANCE: return new InternalProviderImpl<>(binding.getInstance()); case PROVIDER_INSTANCE: return new InternalProviderImpl<>(binding.getProviderInstance(), binding.isProvidingSingletonInScope()); case PROVIDER_CLASS: return createInternalProvider(this,