aboutsummaryrefslogtreecommitdiff
path: root/java/dagger/hilt/android/internal/testing/TestComponentDataSupplier.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/dagger/hilt/android/internal/testing/TestComponentDataSupplier.java')
-rw-r--r--java/dagger/hilt/android/internal/testing/TestComponentDataSupplier.java47
1 files changed, 4 insertions, 43 deletions
diff --git a/java/dagger/hilt/android/internal/testing/TestComponentDataSupplier.java b/java/dagger/hilt/android/internal/testing/TestComponentDataSupplier.java
index b6f8b0b45..e39073f9a 100644
--- a/java/dagger/hilt/android/internal/testing/TestComponentDataSupplier.java
+++ b/java/dagger/hilt/android/internal/testing/TestComponentDataSupplier.java
@@ -16,50 +16,11 @@
package dagger.hilt.android.internal.testing;
-import java.lang.reflect.InvocationTargetException;
+import java.util.Map;
-/** Stores the {@link TestComponentData} for a Hilt test class. */
+/** Stores the {@link TestComponentData} for all Hilt test classes. */
public abstract class TestComponentDataSupplier {
- /** Returns a {@link TestComponentData}. */
- protected abstract TestComponentData get();
-
- static TestComponentData get(Class<?> testClass) {
- String generatedClassName = getEnclosedClassName(testClass) + "_TestComponentDataSupplier";
- try {
- return Class.forName(generatedClassName)
- .asSubclass(TestComponentDataSupplier.class)
- .getDeclaredConstructor()
- .newInstance()
- .get();
- } catch (ClassNotFoundException
- | NoSuchMethodException
- | IllegalAccessException
- | InstantiationException
- | InvocationTargetException e) {
- throw new RuntimeException(
- String.format(
- "Hilt test, %s, is missing generated file: %s. Check that the test class is "
- + " annotated with @HiltAndroidTest and that the processor is running over your"
- + " test.",
- testClass.getSimpleName(),
- generatedClassName),
- e);
- }
- }
-
- private static String getEnclosedClassName(Class<?> testClass) {
- StringBuilder sb = new StringBuilder();
- Class<?> currClass = testClass;
- while (currClass != null) {
- Class<?> enclosingClass = currClass.getEnclosingClass();
- if (enclosingClass != null) {
- sb.insert(0, "_" + currClass.getSimpleName());
- } else {
- sb.insert(0, currClass.getCanonicalName());
- }
- currClass = enclosingClass;
- }
- return sb.toString();
- }
+ /** Returns a map of {@link TestComponentData} keyed by test class. */
+ protected abstract Map<Class<?>, TestComponentData> get();
}