/* * Copyright (C) 2020 The Dagger Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package dagger.hilt.android.internal.testing; import dagger.hilt.internal.Preconditions; import java.util.Map; import java.util.Set; /** Contains the data needed to create a test's component. */ public final class TestComponentData { private final ComponentSupplier componentSupplier; private final TestInjector testInjector; private final Set> daggerRequiredModules; private final Set> hiltRequiredModules; private final boolean waitForBindValue; public TestComponentData( boolean waitForBindValue, TestInjector testInjector, Set> daggerRequiredModules, Set> hiltRequiredModules, ComponentSupplier componentSupplier) { Preconditions.checkState( daggerRequiredModules.containsAll(hiltRequiredModules), "Hilt required modules should be subset of Dagger required modules."); this.componentSupplier = componentSupplier; this.testInjector = testInjector; this.daggerRequiredModules = daggerRequiredModules; this.waitForBindValue = waitForBindValue; this.hiltRequiredModules = hiltRequiredModules; } /** Returns the {@link ComponentSupplier}. */ public ComponentSupplier componentSupplier() { return componentSupplier; } /** Returns the {@link TestInjector}. */ public TestInjector testInjector() { return testInjector; } /** Returns the set of modules that Dagger cannot create instances of itself */ public Set> daggerRequiredModules() { return daggerRequiredModules; } /** * Returns a subset of {@link #daggerRequiredModules} that filters out the modules Hilt can * instantiate itself. */ public Set> hiltRequiredModules() { return hiltRequiredModules; } /** Returns true if creation of the component needs to wait for bind() to be called. */ public boolean waitForBindValue() { return waitForBindValue; } /** Returns the component using the given registered modules. */ public interface ComponentSupplier { Object get(Map, ?> registeredModules, Object testInstance, Boolean autoAddModule); } }