aboutsummaryrefslogtreecommitdiff
path: root/javatests/dagger/hilt/android/processor/internal
diff options
context:
space:
mode:
Diffstat (limited to 'javatests/dagger/hilt/android/processor/internal')
-rw-r--r--javatests/dagger/hilt/android/processor/internal/BUILD36
-rw-r--r--javatests/dagger/hilt/android/processor/internal/GeneratorsTest.java318
-rw-r--r--javatests/dagger/hilt/android/processor/internal/aggregateddeps/BUILD19
-rw-r--r--javatests/dagger/hilt/android/processor/internal/aggregateddeps/EarlyEntryPointProcessorTest.java116
-rw-r--r--javatests/dagger/hilt/android/processor/internal/customtestapplication/BUILD36
-rw-r--r--javatests/dagger/hilt/android/processor/internal/customtestapplication/CustomTestApplicationProcessorTest.java334
-rw-r--r--javatests/dagger/hilt/android/processor/internal/viewmodel/ViewModelGeneratorTest.kt72
7 files changed, 30 insertions, 901 deletions
diff --git a/javatests/dagger/hilt/android/processor/internal/BUILD b/javatests/dagger/hilt/android/processor/internal/BUILD
deleted file mode 100644
index 9a0a8f2a0..000000000
--- a/javatests/dagger/hilt/android/processor/internal/BUILD
+++ /dev/null
@@ -1,36 +0,0 @@
-# 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.
-# Description:
-# Tests for internal code for implementing Hilt processors.
-
-load("//java/dagger/testing/compile:macros.bzl", "compiler_test")
-
-package(default_visibility = ["//:src"])
-
-compiler_test(
- name = "GeneratorsTest",
- srcs = ["GeneratorsTest.java"],
- compiler_deps = [
- "//java/dagger/hilt/android:hilt_android_app",
- "//java/dagger/hilt/android:android_entry_point",
- "@androidsdk//:platforms/android-30/android.jar",
- "@maven//:androidx_annotation_annotation",
- ],
- deps = [
- "@google_bazel_common//third_party/java/compile_testing",
- "@google_bazel_common//third_party/java/junit",
- "@google_bazel_common//third_party/java/truth",
- "//javatests/dagger/hilt/android/processor:android_compilers",
- ],
-)
diff --git a/javatests/dagger/hilt/android/processor/internal/GeneratorsTest.java b/javatests/dagger/hilt/android/processor/internal/GeneratorsTest.java
deleted file mode 100644
index ecfd1f6aa..000000000
--- a/javatests/dagger/hilt/android/processor/internal/GeneratorsTest.java
+++ /dev/null
@@ -1,318 +0,0 @@
-/*
- * 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.processor.internal;
-
-import static com.google.testing.compile.CompilationSubject.assertThat;
-import static dagger.hilt.android.processor.AndroidCompilers.compiler;
-
-import com.google.testing.compile.Compilation;
-import com.google.testing.compile.JavaFileObjects;
-import javax.tools.JavaFileObject;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-@RunWith(JUnit4.class)
-public final class GeneratorsTest {
-
- @Test
- public void copyConstructorParametersCopiesExternalNullables() {
- JavaFileObject baseActivity =
- JavaFileObjects.forSourceLines(
- "test.BaseActivity",
- "package test;",
- "",
- "import androidx.fragment.app.FragmentActivity;",
- "",
- "public abstract class BaseActivity extends FragmentActivity {",
- " protected BaseActivity(",
- " @androidx.annotation.Nullable String supportNullable,",
- " @androidx.annotation.Nullable String androidxNullable,",
- " @javax.annotation.Nullable String javaxNullable) { }",
- "}");
- JavaFileObject myActivity =
- JavaFileObjects.forSourceLines(
- "test.MyActivity",
- "package test;",
- "",
- "import dagger.hilt.android.AndroidEntryPoint;",
- "",
- "@AndroidEntryPoint(BaseActivity.class)",
- "public class MyActivity extends Hilt_MyActivity {",
- " public MyActivity(",
- " String supportNullable,",
- " String androidxNullable,",
- " String javaxNullable) {",
- " super(supportNullable, androidxNullable, javaxNullable);",
- " }",
- "}");
- Compilation compilation = compiler().compile(baseActivity, myActivity);
- assertThat(compilation).succeeded();
- assertThat(compilation)
- .generatedSourceFile("test/Hilt_MyActivity")
- .containsElementsIn(
- JavaFileObjects.forSourceLines(
- "test.Hilt_MyActivity",
- "package test;",
- "",
- "import androidx.annotation.Nullable;",
- "",
- "@Generated(\"dagger.hilt.android.processor.internal.androidentrypoint.ActivityGenerator\")",
- "abstract class Hilt_MyActivity extends BaseActivity implements",
- " GeneratedComponentManagerHolder {",
- " Hilt_MyActivity(",
- " @Nullable String supportNullable,",
- " @Nullable String androidxNullable,",
- " @javax.annotation.Nullable String javaxNullable) {",
- " super(supportNullable, androidxNullable, javaxNullable);",
- " _initHiltInternal();",
- " }",
- "}"));
- }
-
- @Test
- public void copyConstructorParametersConvertsAndroidInternalNullableToExternal() {
- // Relies on View(Context, AttributeSet), which has android-internal
- // @android.annotation.Nullable on AttributeSet.
- JavaFileObject myView =
- JavaFileObjects.forSourceLines(
- "test.MyView",
- "package test;",
- "",
- "import android.content.Context;",
- "import android.util.AttributeSet;",
- "import android.view.View;",
- "import dagger.hilt.android.AndroidEntryPoint;",
- "",
- "@AndroidEntryPoint(View.class)",
- "public class MyView extends Hilt_MyView {",
- " public MyView(Context context, AttributeSet attrs) {",
- " super(context, attrs);",
- " }",
- "}");
- Compilation compilation = compiler().compile(myView);
- assertThat(compilation).succeeded();
- assertThat(compilation)
- .generatedSourceFile("test/Hilt_MyView")
- .containsElementsIn(
- JavaFileObjects.forSourceLines(
- "test.Hilt_MyView",
- "package test;",
- "",
- "@Generated(\"dagger.hilt.android.processor.internal.androidentrypoint.ViewGenerator\")",
- "abstract class Hilt_MyView extends View implements",
- "GeneratedComponentManagerHolder {",
- // The generated parameter names are copied from the base class. Since we only have
- // the jar and not the source for these base classes the parameter names are missing
- " Hilt_MyView(Context arg0, @Nullable AttributeSet arg1) {",
- " super(arg0, arg1);",
- " inject();",
- " }",
- "}"));
- }
-
- @Test
- public void copyTargetApiAnnotationActivity() {
- JavaFileObject myActivity =
- JavaFileObjects.forSourceLines(
- "test.MyActivity",
- "package test;",
- "",
- "import android.annotation.TargetApi;",
- "import androidx.fragment.app.FragmentActivity;",
- "import dagger.hilt.android.AndroidEntryPoint;",
- "",
- "@TargetApi(24)",
- "@AndroidEntryPoint(FragmentActivity.class)",
- "public class MyActivity extends Hilt_MyActivity {}");
- Compilation compilation = compiler().compile(myActivity);
- assertThat(compilation).succeeded();
- assertThat(compilation)
- .generatedSourceFile("test/Hilt_MyActivity")
- .containsElementsIn(
- JavaFileObjects.forSourceLines(
- "test.Hilt_MyActivity",
- " package test;",
- "",
- "@Generated(\"dagger.hilt.android.processor.internal.androidentrypoint.ActivityGenerator\")",
- "@TargetApi(24)",
- "abstract class Hilt_MyActivity extends FragmentActivity ",
- "implements GeneratedComponentManagerHolder {",
- "}"));
- }
-
- @Test
- public void copyTargetApiAnnotationOverView() {
- JavaFileObject myView =
- JavaFileObjects.forSourceLines(
- "test.MyView",
- "package test;",
- "",
- "import android.annotation.TargetApi;",
- "import android.widget.LinearLayout;",
- "import android.content.Context;",
- "import android.util.AttributeSet;",
- "import dagger.hilt.android.AndroidEntryPoint;",
- "",
- "@TargetApi(24)",
- "@AndroidEntryPoint(LinearLayout.class)",
- "public class MyView extends Hilt_MyView {",
- " public MyView(Context context, AttributeSet attributeSet){",
- " super(context, attributeSet);",
- " }",
- "",
- "}");
- Compilation compilation = compiler().compile(myView);
- assertThat(compilation).succeeded();
- assertThat(compilation)
- .generatedSourceFile("test/Hilt_MyView")
- .containsElementsIn(
- JavaFileObjects.forSourceLines(
- "test.Hilt_MyView",
- "",
- "package test;",
- "",
- "@Generated(\"dagger.hilt.android.processor.internal.androidentrypoint.ViewGenerator\")",
- "@TargetApi(24)",
- "abstract class Hilt_MyView extends LinearLayout implements"
- + " GeneratedComponentManagerHolder {",
- "}"));
- }
-
- @Test
- public void copyTargetApiAnnotationApplication() {
- JavaFileObject myApplication =
- JavaFileObjects.forSourceLines(
- "test.MyApplication",
- "package test;",
- "",
- "import android.annotation.TargetApi;",
- "import android.app.Application;",
- "import dagger.hilt.android.HiltAndroidApp;",
- "",
- "@TargetApi(24)",
- "@HiltAndroidApp(Application.class)",
- "public class MyApplication extends Hilt_MyApplication {}");
- Compilation compilation = compiler().compile(myApplication);
- assertThat(compilation).succeeded();
- assertThat(compilation)
- .generatedSourceFile("test/Hilt_MyApplication")
- .containsElementsIn(
- JavaFileObjects.forSourceLines(
- "test.Hilt_MyApplication",
- " package test;",
- "",
- "@Generated(\"dagger.hilt.android.processor.internal.androidentrypoint.ApplicationGenerator\")",
- "@TargetApi(24)",
- "abstract class Hilt_MyApplication extends Application implements"
- + " GeneratedComponentManagerHolder {}"));
- }
-
- @Test
- public void copyTargetApiAnnotationFragment() {
- JavaFileObject myApplication =
- JavaFileObjects.forSourceLines(
- "test.MyFragment",
- "package test;",
- "",
- "import android.annotation.TargetApi;",
- "import androidx.fragment.app.Fragment;",
- "import dagger.hilt.android.AndroidEntryPoint;",
- "",
- "@TargetApi(24)",
- "@AndroidEntryPoint(Fragment.class)",
- "public class MyFragment extends Hilt_MyFragment {}");
- Compilation compilation = compiler().compile(myApplication);
- assertThat(compilation).succeeded();
- assertThat(compilation)
- .generatedSourceFile("test/Hilt_MyFragment")
- .containsElementsIn(
- JavaFileObjects.forSourceLines(
- "test.Hilt_MyFragment",
- "package test;",
- "",
- "@Generated(\"dagger.hilt.android.processor.internal.androidentrypoint.FragmentGenerator\")",
- "@TargetApi(24)",
- "@SuppressWarnings(\"deprecation\")",
- "abstract class Hilt_MyFragment extends Fragment implements"
- + " GeneratedComponentManagerHolder {}"));
- }
-
- @Test
- public void copyTargetApiBroadcastRecieverGenerator() {
- JavaFileObject myBroadcastReceiver =
- JavaFileObjects.forSourceLines(
- "test.MyBroadcastReceiver",
- "package test;",
- "",
- "import android.content.BroadcastReceiver;",
- "import android.annotation.TargetApi;",
- "import dagger.hilt.android.AndroidEntryPoint;",
- "",
- "@TargetApi(24)",
- "@AndroidEntryPoint(BroadcastReceiver.class)",
- "public class MyBroadcastReceiver extends Hilt_MyBroadcastReceiver {}");
- Compilation compilation = compiler().compile(myBroadcastReceiver);
- assertThat(compilation).succeeded();
- assertThat(compilation)
- .generatedSourceFile("test/Hilt_MyBroadcastReceiver")
- .containsElementsIn(
- JavaFileObjects.forSourceLines(
- "test.Hilt_MyBroadcastReceiver",
- "package test;",
- "",
- "@Generated(\"dagger.hilt.android.processor.internal.androidentrypoint.BroadcastReceiverGenerator\")",
- "@TargetApi(24)",
- "abstract class Hilt_MyBroadcastReceiver extends BroadcastReceiver {}"));
- }
-
- @Test
- public void copyTargetApiServiceGenerator() {
- JavaFileObject myService =
- JavaFileObjects.forSourceLines(
- "test.MyService",
- "package test;",
- "",
- "import android.annotation.TargetApi;",
- "import android.content.Intent;",
- "import android.app.Service;",
- "import android.os.IBinder;",
- "import dagger.hilt.android.AndroidEntryPoint;",
- "",
- "@TargetApi(24)",
- "@AndroidEntryPoint(Service.class)",
- "public class MyService extends Hilt_MyService {",
- " @Override",
- " public IBinder onBind(Intent intent){",
- " return null;",
- " }",
- "}");
- Compilation compilation = compiler().compile(myService);
- assertThat(compilation).succeeded();
- assertThat(compilation)
- .generatedSourceFile("test/Hilt_MyService")
- .containsElementsIn(
- JavaFileObjects.forSourceLines(
- "test.Hilt_MyService",
- "package test;",
- "",
- "@Generated(\"dagger.hilt.android.processor.internal.androidentrypoint.ServiceGenerator\")",
- "@TargetApi(24)",
- "abstract class Hilt_MyService extends Service implements"
- + " GeneratedComponentManagerHolder{}"));
- }
-}
diff --git a/javatests/dagger/hilt/android/processor/internal/aggregateddeps/BUILD b/javatests/dagger/hilt/android/processor/internal/aggregateddeps/BUILD
index 654b573a0..bf2ed4c8a 100644
--- a/javatests/dagger/hilt/android/processor/internal/aggregateddeps/BUILD
+++ b/javatests/dagger/hilt/android/processor/internal/aggregateddeps/BUILD
@@ -40,25 +40,6 @@ compiler_test(
],
)
-compiler_test(
- name = "EarlyEntryPointProcessorTest",
- srcs = ["EarlyEntryPointProcessorTest.java"],
- compiler_deps = [
- "//java/dagger/hilt:entry_point",
- "//java/dagger/hilt:install_in",
- "//java/dagger/hilt/android:early_entry_point",
- "//java/dagger/hilt/android/components",
- "//java/dagger/hilt/android/testing:hilt_android_test",
- "@androidsdk//:platforms/android-30/android.jar",
- ],
- deps = [
- "@google_bazel_common//third_party/java/compile_testing",
- "@google_bazel_common//third_party/java/junit",
- "@google_bazel_common//third_party/java/truth",
- "//javatests/dagger/hilt/android/processor:android_compilers",
- ],
-)
-
java_library(
name = "InstallInModule",
srcs = ["InstallInModule.java"],
diff --git a/javatests/dagger/hilt/android/processor/internal/aggregateddeps/EarlyEntryPointProcessorTest.java b/javatests/dagger/hilt/android/processor/internal/aggregateddeps/EarlyEntryPointProcessorTest.java
deleted file mode 100644
index 3bf3a31de..000000000
--- a/javatests/dagger/hilt/android/processor/internal/aggregateddeps/EarlyEntryPointProcessorTest.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) 2021 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.processor.internal.aggregateddeps;
-
-import static com.google.testing.compile.CompilationSubject.assertThat;
-import static dagger.hilt.android.processor.AndroidCompilers.compiler;
-
-import com.google.testing.compile.Compilation;
-import com.google.testing.compile.JavaFileObjects;
-import javax.tools.JavaFileObject;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-@RunWith(JUnit4.class)
-public class EarlyEntryPointProcessorTest {
-
- @Test
- public void testUsedWithEntryPoint_fails() {
- JavaFileObject entryPoint =
- JavaFileObjects.forSourceLines(
- "test.UsedWithEntryPoint",
- "package test;",
- "",
- "import dagger.hilt.android.EarlyEntryPoint;",
- "import dagger.hilt.EntryPoint;",
- "import dagger.hilt.InstallIn;",
- "import dagger.hilt.components.SingletonComponent;",
- "",
- "@EarlyEntryPoint",
- "@EntryPoint",
- "@InstallIn(SingletonComponent.class)",
- "public interface UsedWithEntryPoint {}");
- Compilation compilation = compiler().compile(entryPoint);
-
- assertThat(compilation).failed();
- assertThat(compilation)
- .hadErrorContaining(
- "Only one of the following annotations can be used on test.UsedWithEntryPoint: "
- + "[dagger.hilt.EntryPoint, dagger.hilt.android.EarlyEntryPoint]")
- .inFile(entryPoint)
- .onLine(11);
- }
-
- @Test
- public void testNotSingletonComponent_fails() {
- JavaFileObject entryPoint =
- JavaFileObjects.forSourceLines(
- "test.NotSingletonComponent",
- "package test;",
- "",
- "import dagger.hilt.android.EarlyEntryPoint;",
- "import dagger.hilt.android.components.ActivityComponent;",
- "import dagger.hilt.EntryPoint;",
- "import dagger.hilt.InstallIn;",
- "",
- "@EarlyEntryPoint",
- "@InstallIn(ActivityComponent.class)",
- "public interface NotSingletonComponent {}");
-
- Compilation compilation = compiler().compile(entryPoint);
-
- assertThat(compilation).failed();
- assertThat(compilation)
- .hadErrorContaining(
- "@EarlyEntryPoint can only be installed into the SingletonComponent. "
- + "Found: [dagger.hilt.android.components.ActivityComponent]")
- .inFile(entryPoint)
- .onLine(10);
- }
-
- @Test
- public void testThatTestInstallInCannotOriginateFromTest() {
- JavaFileObject test =
- JavaFileObjects.forSourceLines(
- "test.MyTest",
- "package test;",
- "",
- "import dagger.hilt.EntryPoint;",
- "import dagger.hilt.InstallIn;",
- "import dagger.hilt.android.EarlyEntryPoint;",
- "import dagger.hilt.android.testing.HiltAndroidTest;",
- "import dagger.hilt.components.SingletonComponent;",
- "",
- "@HiltAndroidTest",
- "public class MyTest {",
- " @EarlyEntryPoint",
- " @InstallIn(SingletonComponent.class)",
- " interface NestedEarlyEntryPoint {}",
- "}");
- Compilation compilation = compiler().compile(test);
- assertThat(compilation).failed();
- assertThat(compilation).hadErrorCount(1);
- assertThat(compilation)
- .hadErrorContaining(
- "@EarlyEntryPoint-annotated entry point, test.MyTest.NestedEarlyEntryPoint, cannot "
- + "be nested in (or originate from) a @HiltAndroidTest-annotated class, "
- + "test.MyTest.")
- .inFile(test)
- .onLine(13);
- }
-}
diff --git a/javatests/dagger/hilt/android/processor/internal/customtestapplication/BUILD b/javatests/dagger/hilt/android/processor/internal/customtestapplication/BUILD
deleted file mode 100644
index 6fc39e435..000000000
--- a/javatests/dagger/hilt/android/processor/internal/customtestapplication/BUILD
+++ /dev/null
@@ -1,36 +0,0 @@
-# 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.
-# Description:
-# Tests for internal code for implementing Hilt processors.
-
-load("//java/dagger/testing/compile:macros.bzl", "compiler_test")
-
-package(default_visibility = ["//:src"])
-
-compiler_test(
- name = "CustomTestApplicationProcessorTest",
- srcs = ["CustomTestApplicationProcessorTest.java"],
- compiler_deps = [
- "//java/dagger/hilt/android/testing:custom_test_application",
- "//java/dagger/hilt/android/testing:hilt_android_test",
- "//java/dagger/hilt/android:hilt_android_app",
- "@androidsdk//:platforms/android-30/android.jar",
- ],
- deps = [
- "@google_bazel_common//third_party/java/compile_testing",
- "@google_bazel_common//third_party/java/junit",
- "@google_bazel_common//third_party/java/truth",
- "//javatests/dagger/hilt/android/processor:android_compilers",
- ],
-)
diff --git a/javatests/dagger/hilt/android/processor/internal/customtestapplication/CustomTestApplicationProcessorTest.java b/javatests/dagger/hilt/android/processor/internal/customtestapplication/CustomTestApplicationProcessorTest.java
deleted file mode 100644
index f0372ab5b..000000000
--- a/javatests/dagger/hilt/android/processor/internal/customtestapplication/CustomTestApplicationProcessorTest.java
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- * 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.processor.internal.customtestapplication;
-
-import static com.google.testing.compile.CompilationSubject.assertThat;
-import static dagger.hilt.android.processor.AndroidCompilers.compiler;
-
-import com.google.testing.compile.Compilation;
-import com.google.testing.compile.JavaFileObjects;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-@RunWith(JUnit4.class)
-public class CustomTestApplicationProcessorTest {
-
- @Test
- public void validBaseClass_succeeds() {
- Compilation compilation =
- compiler().compile(
- JavaFileObjects.forSourceLines(
- "test.HiltTest",
- "package test;",
- "",
- "import android.app.Application;",
- "import dagger.hilt.android.testing.CustomTestApplication;",
- "import dagger.hilt.android.testing.HiltAndroidTest;",
- "",
- "@CustomTestApplication(Application.class)",
- "@HiltAndroidTest",
- "public class HiltTest {}"));
-
- assertThat(compilation).succeeded();
- }
-
- @Test
- public void incorrectBaseType_fails() {
- Compilation compilation =
- compiler().compile(
- JavaFileObjects.forSourceLines(
- "test.Foo",
- "package test;",
- "",
- "public class Foo {}"),
- JavaFileObjects.forSourceLines(
- "test.HiltTest",
- "package test;",
- "",
- "import dagger.hilt.android.testing.CustomTestApplication;",
- "",
- "@CustomTestApplication(Foo.class)",
- "public class HiltTest {}"));
-
- assertThat(compilation).failed();
- assertThat(compilation)
- .hadErrorContaining(
- "@CustomTestApplication value should be an instance of android.app.Application. "
- + "Found: test.Foo");
- }
-
- @Test
- public void baseWithHiltAndroidApp_fails() {
- Compilation compilation =
- compiler().compile(
- JavaFileObjects.forSourceLines(
- "test.BaseApplication",
- "package test;",
- "",
- "import android.app.Application;",
- "import dagger.hilt.android.HiltAndroidApp;",
- "",
- "@HiltAndroidApp(Application.class)",
- "public class BaseApplication extends Hilt_BaseApplication {}"),
- JavaFileObjects.forSourceLines(
- "test.HiltTest",
- "package test;",
- "",
- "import dagger.hilt.android.testing.CustomTestApplication;",
- "",
- "@CustomTestApplication(BaseApplication.class)",
- "public class HiltTest {}"));
-
- assertThat(compilation).failed();
- assertThat(compilation)
- .hadErrorContaining(
- "@CustomTestApplication value cannot be annotated with @HiltAndroidApp. "
- + "Found: test.BaseApplication");
- }
-
- @Test
- public void superclassWithHiltAndroidApp_fails() {
- Compilation compilation =
- compiler().compile(
- JavaFileObjects.forSourceLines(
- "test.BaseApplication",
- "package test;",
- "",
- "import android.app.Application;",
- "import dagger.hilt.android.HiltAndroidApp;",
- "",
- "@HiltAndroidApp(Application.class)",
- "public class BaseApplication extends Hilt_BaseApplication {}"),
- JavaFileObjects.forSourceLines(
- "test.ParentApplication",
- "package test;",
- "",
- "public class ParentApplication extends BaseApplication {}"),
- JavaFileObjects.forSourceLines(
- "test.HiltTest",
- "package test;",
- "",
- "import dagger.hilt.android.testing.CustomTestApplication;",
- "",
- "@CustomTestApplication(ParentApplication.class)",
- "public class HiltTest {}"));
-
- assertThat(compilation).failed();
- assertThat(compilation)
- .hadErrorContaining(
- "@CustomTestApplication value cannot be annotated with @HiltAndroidApp. "
- + "Found: test.BaseApplication");
- }
-
- @Test
- public void withInjectField_fails() {
- Compilation compilation =
- compiler().compile(
- JavaFileObjects.forSourceLines(
- "test.BaseApplication",
- "package test;",
- "",
- "import android.app.Application;",
- "import javax.inject.Inject;",
- "",
- "public class BaseApplication extends Application {",
- " @Inject String str;",
- "}"),
- JavaFileObjects.forSourceLines(
- "test.HiltTest",
- "package test;",
- "",
- "import dagger.hilt.android.testing.CustomTestApplication;",
- "",
- "@CustomTestApplication(BaseApplication.class)",
- "public class HiltTest {}"));
-
- assertThat(compilation).failed();
- assertThat(compilation)
- .hadErrorContaining(
- "@CustomTestApplication does not support application classes (or super classes) with "
- + "@Inject fields. Found test.BaseApplication with @Inject fields [str]");
- }
-
- @Test
- public void withSuperclassInjectField_fails() {
- Compilation compilation =
- compiler().compile(
- JavaFileObjects.forSourceLines(
- "test.BaseApplication",
- "package test;",
- "",
- "import android.app.Application;",
- "import javax.inject.Inject;",
- "",
- "public class BaseApplication extends Application {",
- " @Inject String str;",
- "}"),
- JavaFileObjects.forSourceLines(
- "test.ParentApplication",
- "package test;",
- "",
- "public class ParentApplication extends BaseApplication {}"),
- JavaFileObjects.forSourceLines(
- "test.HiltTest",
- "package test;",
- "",
- "import dagger.hilt.android.testing.CustomTestApplication;",
- "",
- "@CustomTestApplication(ParentApplication.class)",
- "public class HiltTest {}"));
-
- assertThat(compilation).failed();
- assertThat(compilation)
- .hadErrorContaining(
- "@CustomTestApplication does not support application classes (or super classes) with "
- + "@Inject fields. Found test.BaseApplication with @Inject fields [str]");
- }
-
- @Test
- public void withInjectMethod_fails() {
- Compilation compilation =
- compiler().compile(
- JavaFileObjects.forSourceLines(
- "test.BaseApplication",
- "package test;",
- "",
- "import android.app.Application;",
- "import javax.inject.Inject;",
- "",
- "public class BaseApplication extends Application {",
- " @Inject String str() { return null; }",
- "}"),
- JavaFileObjects.forSourceLines(
- "test.HiltTest",
- "package test;",
- "",
- "import dagger.hilt.android.testing.CustomTestApplication;",
- "",
- "@CustomTestApplication(BaseApplication.class)",
- "public class HiltTest {}"));
-
- assertThat(compilation).failed();
- assertThat(compilation)
- .hadErrorContaining(
- "@CustomTestApplication does not support application classes (or super classes) with "
- + "@Inject methods. Found test.BaseApplication with @Inject methods [str()]");
- }
-
- @Test
- public void withSuperclassInjectMethod_fails() {
- Compilation compilation =
- compiler().compile(
- JavaFileObjects.forSourceLines(
- "test.BaseApplication",
- "package test;",
- "",
- "import android.app.Application;",
- "import javax.inject.Inject;",
- "",
- "public class BaseApplication extends Application {",
- " @Inject String str() { return null; }",
- "}"),
- JavaFileObjects.forSourceLines(
- "test.ParentApplication",
- "package test;",
- "",
- "public class ParentApplication extends BaseApplication {}"),
- JavaFileObjects.forSourceLines(
- "test.HiltTest",
- "package test;",
- "",
- "import dagger.hilt.android.testing.CustomTestApplication;",
- "",
- "@CustomTestApplication(ParentApplication.class)",
- "public class HiltTest {}"));
-
- assertThat(compilation).failed();
- assertThat(compilation)
- .hadErrorContaining(
- "@CustomTestApplication does not support application classes (or super classes) with "
- + "@Inject methods. Found test.BaseApplication with @Inject methods [str()]");
- }
-
- @Test
- public void withInjectConstructor_fails() {
- Compilation compilation =
- compiler().compile(
- JavaFileObjects.forSourceLines(
- "test.BaseApplication",
- "package test;",
- "",
- "import android.app.Application;",
- "import javax.inject.Inject;",
- "",
- "public class BaseApplication extends Application {",
- " @Inject BaseApplication() {}",
- "}"),
- JavaFileObjects.forSourceLines(
- "test.HiltTest",
- "package test;",
- "",
- "import dagger.hilt.android.testing.CustomTestApplication;",
- "",
- "@CustomTestApplication(BaseApplication.class)",
- "public class HiltTest {}"));
-
- assertThat(compilation).failed();
- assertThat(compilation)
- .hadErrorContaining(
- "@CustomTestApplication does not support application classes (or super classes) with "
- + "@Inject constructors. Found test.BaseApplication with @Inject constructors "
- + "[BaseApplication()]");
- }
-
- @Test
- public void withSuperclassInjectConstructor_fails() {
- Compilation compilation =
- compiler().compile(
- JavaFileObjects.forSourceLines(
- "test.BaseApplication",
- "package test;",
- "",
- "import android.app.Application;",
- "import javax.inject.Inject;",
- "",
- "public class BaseApplication extends Application {",
- " @Inject BaseApplication() {}",
- "}"),
- JavaFileObjects.forSourceLines(
- "test.ParentApplication",
- "package test;",
- "",
- "public class ParentApplication extends BaseApplication {}"),
- JavaFileObjects.forSourceLines(
- "test.HiltTest",
- "package test;",
- "",
- "import dagger.hilt.android.testing.CustomTestApplication;",
- "",
- "@CustomTestApplication(ParentApplication.class)",
- "public class HiltTest {}"));
-
- assertThat(compilation).failed();
- assertThat(compilation)
- .hadErrorContaining(
- "@CustomTestApplication does not support application classes (or super classes) with "
- + "@Inject constructors. Found test.BaseApplication with @Inject constructors "
- + "[BaseApplication()]");
- }
-}
diff --git a/javatests/dagger/hilt/android/processor/internal/viewmodel/ViewModelGeneratorTest.kt b/javatests/dagger/hilt/android/processor/internal/viewmodel/ViewModelGeneratorTest.kt
index df020ffa9..7c3e45fd7 100644
--- a/javatests/dagger/hilt/android/processor/internal/viewmodel/ViewModelGeneratorTest.kt
+++ b/javatests/dagger/hilt/android/processor/internal/viewmodel/ViewModelGeneratorTest.kt
@@ -45,7 +45,7 @@ class ViewModelGeneratorTest {
val expected = """
package dagger.hilt.android.test;
-
+
import androidx.lifecycle.ViewModel;
import dagger.Binds;
import dagger.Module;
@@ -60,7 +60,7 @@ class ViewModelGeneratorTest {
import dagger.multibindings.StringKey;
import java.lang.String;
import $GENERATED_TYPE
-
+
$GENERATED_ANNOTATION
@OriginatingElement(
topLevelClass = MyViewModel.class
@@ -68,25 +68,23 @@ class ViewModelGeneratorTest {
public final class MyViewModel_HiltModules {
private MyViewModel_HiltModules() {
}
-
+
@Module
@InstallIn(ViewModelComponent.class)
public static abstract class BindsModule {
- private BindsModule() {}
-
@Binds
@IntoMap
@StringKey("dagger.hilt.android.test.MyViewModel")
@HiltViewModelMap
public abstract ViewModel binds(MyViewModel vm);
}
-
+
@Module
@InstallIn(ActivityRetainedComponent.class)
public static final class KeyModule {
private KeyModule() {
}
-
+
@Provides
@IntoSet
@HiltViewModelMap.KeySet
@@ -125,7 +123,7 @@ class ViewModelGeneratorTest {
val expected = """
package dagger.hilt.android.test;
-
+
import androidx.lifecycle.ViewModel;
import dagger.Binds;
import dagger.Module;
@@ -140,7 +138,7 @@ class ViewModelGeneratorTest {
import dagger.multibindings.StringKey;
import java.lang.String;
import $GENERATED_TYPE
-
+
$GENERATED_ANNOTATION
@OriginatingElement(
topLevelClass = MyViewModel.class
@@ -148,25 +146,23 @@ class ViewModelGeneratorTest {
public final class MyViewModel_HiltModules {
private MyViewModel_HiltModules() {
}
-
+
@Module
@InstallIn(ViewModelComponent.class)
public static abstract class BindsModule {
- private BindsModule() {}
-
@Binds
@IntoMap
@StringKey("dagger.hilt.android.test.MyViewModel")
@HiltViewModelMap
public abstract ViewModel binds(MyViewModel vm);
}
-
+
@Module
@InstallIn(ActivityRetainedComponent.class)
public static final class KeyModule {
private KeyModule() {
}
-
+
@Provides
@IntoSet
@HiltViewModelMap.KeySet
@@ -212,7 +208,7 @@ class ViewModelGeneratorTest {
val expected = """
package dagger.hilt.android.test;
-
+
import androidx.lifecycle.ViewModel;
import dagger.Binds;
import dagger.Module;
@@ -227,7 +223,7 @@ class ViewModelGeneratorTest {
import dagger.multibindings.StringKey;
import java.lang.String;
import $GENERATED_TYPE
-
+
$GENERATED_ANNOTATION
@OriginatingElement(
topLevelClass = MyViewModel.class
@@ -235,25 +231,23 @@ class ViewModelGeneratorTest {
public final class MyViewModel_HiltModules {
private MyViewModel_HiltModules() {
}
-
+
@Module
@InstallIn(ViewModelComponent.class)
public static abstract class BindsModule {
- private BindsModule() {}
-
@Binds
@IntoMap
@StringKey("dagger.hilt.android.test.MyViewModel")
@HiltViewModelMap
public abstract ViewModel binds(MyViewModel vm);
}
-
+
@Module
@InstallIn(ActivityRetainedComponent.class)
public static final class KeyModule {
private KeyModule() {
}
-
+
@Provides
@IntoSet
@HiltViewModelMap.KeySet
@@ -300,7 +294,7 @@ class ViewModelGeneratorTest {
val expected = """
package dagger.hilt.android.test;
-
+
import androidx.lifecycle.ViewModel;
import dagger.Binds;
import dagger.Module;
@@ -315,7 +309,7 @@ class ViewModelGeneratorTest {
import dagger.multibindings.StringKey;
import java.lang.String;
import $GENERATED_TYPE;
-
+
$GENERATED_ANNOTATION
@OriginatingElement(
topLevelClass = MyViewModel.class
@@ -323,25 +317,23 @@ class ViewModelGeneratorTest {
public final class MyViewModel_HiltModules {
private MyViewModel_HiltModules() {
}
-
+
@Module
@InstallIn(ViewModelComponent.class)
public static abstract class BindsModule {
- private BindsModule() {}
-
@Binds
@IntoMap
@StringKey("dagger.hilt.android.test.MyViewModel")
@HiltViewModelMap
public abstract ViewModel binds(MyViewModel vm);
}
-
+
@Module
@InstallIn(ActivityRetainedComponent.class)
public static final class KeyModule {
private KeyModule() {
}
-
+
@Provides
@IntoSet
@HiltViewModelMap.KeySet
@@ -395,7 +387,7 @@ class ViewModelGeneratorTest {
val expected = """
package dagger.hilt.android.test;
-
+
import androidx.lifecycle.ViewModel;
import dagger.Binds;
import dagger.Module;
@@ -410,7 +402,7 @@ class ViewModelGeneratorTest {
import dagger.multibindings.StringKey;
import java.lang.String;
import $GENERATED_TYPE;
-
+
$GENERATED_ANNOTATION
@OriginatingElement(
topLevelClass = MyViewModel.class
@@ -418,25 +410,23 @@ class ViewModelGeneratorTest {
public final class MyViewModel_HiltModules {
private MyViewModel_HiltModules() {
}
-
+
@Module
@InstallIn(ViewModelComponent.class)
public static abstract class BindsModule {
- private BindsModule() {}
-
@Binds
@IntoMap
@StringKey("dagger.hilt.android.test.MyViewModel")
@HiltViewModelMap
public abstract ViewModel binds(MyViewModel vm);
}
-
+
@Module
@InstallIn(ActivityRetainedComponent.class)
public static final class KeyModule {
private KeyModule() {
}
-
+
@Provides
@IntoSet
@HiltViewModelMap.KeySet
@@ -476,7 +466,7 @@ class ViewModelGeneratorTest {
val expectedModule = """
package dagger.hilt.android.test;
-
+
import androidx.lifecycle.ViewModel;
import dagger.Binds;
import dagger.Module;
@@ -491,7 +481,7 @@ class ViewModelGeneratorTest {
import dagger.multibindings.StringKey;
import java.lang.String;
import $GENERATED_TYPE
-
+
$GENERATED_ANNOTATION
@OriginatingElement(
topLevelClass = Outer.class
@@ -499,25 +489,23 @@ class ViewModelGeneratorTest {
public final class Outer_InnerViewModel_HiltModules {
private Outer_InnerViewModel_HiltModules() {
}
-
+
@Module
@InstallIn(ViewModelComponent.class)
public static abstract class BindsModule {
- private BindsModule() {}
-
@Binds
@IntoMap
@StringKey("dagger.hilt.android.test.Outer${'$'}InnerViewModel")
@HiltViewModelMap
public abstract ViewModel binds(Outer.InnerViewModel vm);
}
-
+
@Module
@InstallIn(ActivityRetainedComponent.class)
public static final class KeyModule {
private KeyModule() {
}
-
+
@Provides
@IntoSet
@HiltViewModelMap.KeySet