aboutsummaryrefslogtreecommitdiff
path: root/javatests/dagger/hilt/android/testing/testinstallin
diff options
context:
space:
mode:
Diffstat (limited to 'javatests/dagger/hilt/android/testing/testinstallin')
-rw-r--r--javatests/dagger/hilt/android/testing/testinstallin/BUILD107
-rw-r--r--javatests/dagger/hilt/android/testing/testinstallin/TestInstallInApp.java35
-rw-r--r--javatests/dagger/hilt/android/testing/testinstallin/TestInstallInAppTest.java47
-rw-r--r--javatests/dagger/hilt/android/testing/testinstallin/TestInstallInBarTest.java75
-rw-r--r--javatests/dagger/hilt/android/testing/testinstallin/TestInstallInFooTest.java57
-rw-r--r--javatests/dagger/hilt/android/testing/testinstallin/TestInstallInModules.java71
6 files changed, 0 insertions, 392 deletions
diff --git a/javatests/dagger/hilt/android/testing/testinstallin/BUILD b/javatests/dagger/hilt/android/testing/testinstallin/BUILD
deleted file mode 100644
index 63d0bca95..000000000
--- a/javatests/dagger/hilt/android/testing/testinstallin/BUILD
+++ /dev/null
@@ -1,107 +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.
-
-package(default_visibility = ["//:src"])
-
-android_local_test(
- name = "TestInstallInFooTest",
- srcs = ["TestInstallInFooTest.java"],
- manifest_values = {
- "minSdkVersion": "15",
- "targetSdkVersion": "27",
- },
- deps = [
- ":TestInstallInModules",
- "//:android_local_test_exports",
- "//:dagger_with_compiler",
- "@maven//:junit_junit",
-
- "@maven//:org_robolectric_robolectric",
- "@maven//:androidx_test_ext_junit",
- "@maven//:androidx_test_core",
-
- "@google_bazel_common//third_party/java/truth",
- "//java/dagger/hilt/android/testing:hilt_android_test",
- ],
-)
-
-android_local_test(
- name = "TestInstallInBarTest",
- srcs = ["TestInstallInBarTest.java"],
- manifest_values = {
- "minSdkVersion": "15",
- "targetSdkVersion": "27",
- },
- deps = [
- ":TestInstallInModules",
- "//:android_local_test_exports",
- "//:dagger_with_compiler",
- "@maven//:junit_junit",
-
- "@maven//:org_robolectric_robolectric",
- "@maven//:androidx_test_ext_junit",
- "@maven//:androidx_test_core",
-
- "@google_bazel_common//third_party/java/truth",
- "//java/dagger/hilt/android/testing:hilt_android_test",
- "//java/dagger/hilt/android/testing:uninstall_modules",
- "//java/dagger/hilt/testing:test_install_in",
- ],
-)
-
-android_local_test(
- name = "TestInstallInAppTest",
- srcs = ["TestInstallInAppTest.java"],
- manifest_values = {
- "minSdkVersion": "15",
- "targetSdkVersion": "27",
- },
- deps = [
- ":TestInstallInApp",
- ":TestInstallInModules",
- "//:android_local_test_exports",
- "@maven//:junit_junit",
-
- "@maven//:org_robolectric_robolectric",
- "@maven//:androidx_test_ext_junit",
- "@maven//:androidx_test_core",
-
- "@google_bazel_common//third_party/java/truth",
- ],
-)
-
-android_library(
- name = "TestInstallInApp",
- testonly = True,
- srcs = ["TestInstallInApp.java"],
- deps = [
- ":TestInstallInModules",
- "//:dagger_with_compiler",
- "//java/dagger/hilt/android:hilt_android_app",
- ],
-)
-
-android_library(
- name = "TestInstallInModules",
- testonly = True,
- srcs = ["TestInstallInModules.java"],
- deps = [
- "//:dagger_with_compiler",
- "//java/dagger/hilt:install_in",
- "//java/dagger/hilt/android/components",
- "//java/dagger/hilt/testing:test_install_in",
- ],
-)
diff --git a/javatests/dagger/hilt/android/testing/testinstallin/TestInstallInApp.java b/javatests/dagger/hilt/android/testing/testinstallin/TestInstallInApp.java
deleted file mode 100644
index 0ad35df5e..000000000
--- a/javatests/dagger/hilt/android/testing/testinstallin/TestInstallInApp.java
+++ /dev/null
@@ -1,35 +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.testing.testinstallin;
-
-import android.app.Application;
-import dagger.hilt.android.HiltAndroidApp;
-import dagger.hilt.android.testing.testinstallin.TestInstallInModules.Bar;
-import dagger.hilt.android.testing.testinstallin.TestInstallInModules.Foo;
-import javax.inject.Inject;
-
-/**
- * An application to test {@link dagger.hilt.testing.TestInstallIn} are ignored when using {@link
- * HiltAndroidApp}.
- *
- * <p>This class is used by {@link TestInstallInAppTest}.
- */
-@HiltAndroidApp(Application.class)
-public class TestInstallInApp extends Hilt_TestInstallInApp {
- @Inject Foo foo;
- @Inject Bar bar;
-}
diff --git a/javatests/dagger/hilt/android/testing/testinstallin/TestInstallInAppTest.java b/javatests/dagger/hilt/android/testing/testinstallin/TestInstallInAppTest.java
deleted file mode 100644
index beb198c89..000000000
--- a/javatests/dagger/hilt/android/testing/testinstallin/TestInstallInAppTest.java
+++ /dev/null
@@ -1,47 +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.testing.testinstallin;
-
-import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
-import static com.google.common.truth.Truth.assertThat;
-
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-import dagger.hilt.android.testing.testinstallin.TestInstallInModules.GlobalBarModule;
-import dagger.hilt.android.testing.testinstallin.TestInstallInModules.GlobalFooModule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-// Test that Foo and Bar use the global @InstallIn module
-@RunWith(AndroidJUnit4.class)
-@Config(application = TestInstallInApp.class)
-public final class TestInstallInAppTest {
-
- @Test
- public void testFoo() {
- assertThat(getMyApplication().foo.moduleClass).isEqualTo(GlobalFooModule.class);
- }
-
- @Test
- public void testBar() {
- assertThat(getMyApplication().bar.moduleClass).isEqualTo(GlobalBarModule.class);
- }
-
- private static TestInstallInApp getMyApplication() {
- return (TestInstallInApp) getApplicationContext();
- }
-}
diff --git a/javatests/dagger/hilt/android/testing/testinstallin/TestInstallInBarTest.java b/javatests/dagger/hilt/android/testing/testinstallin/TestInstallInBarTest.java
deleted file mode 100644
index 8cf9de7aa..000000000
--- a/javatests/dagger/hilt/android/testing/testinstallin/TestInstallInBarTest.java
+++ /dev/null
@@ -1,75 +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.testing.testinstallin;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-import dagger.Module;
-import dagger.Provides;
-import dagger.hilt.InstallIn;
-import dagger.hilt.android.testing.HiltAndroidRule;
-import dagger.hilt.android.testing.HiltAndroidTest;
-import dagger.hilt.android.testing.HiltTestApplication;
-import dagger.hilt.android.testing.UninstallModules;
-import dagger.hilt.android.testing.testinstallin.TestInstallInModules.Bar;
-import dagger.hilt.android.testing.testinstallin.TestInstallInModules.Foo;
-import dagger.hilt.android.testing.testinstallin.TestInstallInModules.GlobalBarModule;
-import dagger.hilt.android.testing.testinstallin.TestInstallInModules.GlobalFooTestModule;
-import dagger.hilt.components.SingletonComponent;
-import javax.inject.Inject;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-/**
- * Tests that Foo uses the global {@linkplain TestInstallIn} module and that Bar uses the local
- * {@linkplain InstallIn} module due to {@linkplain UninstallModules}.
- */
-@UninstallModules(GlobalBarModule.class)
-@HiltAndroidTest
-@RunWith(AndroidJUnit4.class)
-@Config(application = HiltTestApplication.class)
-public final class TestInstallInBarTest {
-
- @Rule public HiltAndroidRule hiltRule = new HiltAndroidRule(this);
-
- @Module
- @InstallIn(SingletonComponent.class)
- public interface LocalBarTestModule {
- @Provides
- static Bar provideBar() {
- return new Bar(LocalBarTestModule.class);
- }
- }
-
- @Inject Foo foo;
- @Inject Bar bar;
-
- @Test
- public void testFoo() {
- hiltRule.inject();
- assertThat(foo.moduleClass).isEqualTo(GlobalFooTestModule.class);
- }
-
- @Test
- public void testBar() {
- hiltRule.inject();
- assertThat(bar.moduleClass).isEqualTo(LocalBarTestModule.class);
- }
-}
diff --git a/javatests/dagger/hilt/android/testing/testinstallin/TestInstallInFooTest.java b/javatests/dagger/hilt/android/testing/testinstallin/TestInstallInFooTest.java
deleted file mode 100644
index 8a7815700..000000000
--- a/javatests/dagger/hilt/android/testing/testinstallin/TestInstallInFooTest.java
+++ /dev/null
@@ -1,57 +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.testing.testinstallin;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-import dagger.hilt.android.testing.HiltAndroidRule;
-import dagger.hilt.android.testing.HiltAndroidTest;
-import dagger.hilt.android.testing.HiltTestApplication;
-import dagger.hilt.android.testing.testinstallin.TestInstallInModules.Bar;
-import dagger.hilt.android.testing.testinstallin.TestInstallInModules.Foo;
-import dagger.hilt.android.testing.testinstallin.TestInstallInModules.GlobalBarModule;
-import dagger.hilt.android.testing.testinstallin.TestInstallInModules.GlobalFooTestModule;
-import javax.inject.Inject;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-// Test that Foo uses the global @TestInstallIn module and Bar uses the global @InstallIn module.
-@HiltAndroidTest
-@RunWith(AndroidJUnit4.class)
-@Config(application = HiltTestApplication.class)
-public final class TestInstallInFooTest {
-
- @Rule public HiltAndroidRule hiltRule = new HiltAndroidRule(this);
-
- @Inject Foo foo;
- @Inject Bar bar;
-
- @Test
- public void testFoo() {
- hiltRule.inject();
- assertThat(foo.moduleClass).isEqualTo(GlobalFooTestModule.class);
- }
-
- @Test
- public void testBar() {
- hiltRule.inject();
- assertThat(bar.moduleClass).isEqualTo(GlobalBarModule.class);
- }
-}
diff --git a/javatests/dagger/hilt/android/testing/testinstallin/TestInstallInModules.java b/javatests/dagger/hilt/android/testing/testinstallin/TestInstallInModules.java
deleted file mode 100644
index ab15d98d6..000000000
--- a/javatests/dagger/hilt/android/testing/testinstallin/TestInstallInModules.java
+++ /dev/null
@@ -1,71 +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.testing.testinstallin;
-
-import dagger.Module;
-import dagger.Provides;
-import dagger.hilt.InstallIn;
-import dagger.hilt.components.SingletonComponent;
-import dagger.hilt.testing.TestInstallIn;
-
-/** Modules and classes used in TestInstallInFooTest and TestInstallInBarTest. */
-final class TestInstallInModules {
- private TestInstallInModules() {}
-
- static class Foo {
- Class<?> moduleClass;
-
- Foo(Class<?> moduleClass) {
- this.moduleClass = moduleClass;
- }
- }
-
- static class Bar {
- Class<?> moduleClass;
-
- Bar(Class<?> moduleClass) {
- this.moduleClass = moduleClass;
- }
- }
-
- @Module
- @InstallIn(SingletonComponent.class)
- interface GlobalFooModule {
- @Provides
- static Foo provideFoo() {
- return new Foo(GlobalFooModule.class);
- }
- }
-
- @Module
- @InstallIn(SingletonComponent.class)
- interface GlobalBarModule {
- @Provides
- static Bar provideFoo() {
- return new Bar(GlobalBarModule.class);
- }
- }
-
- @Module
- @TestInstallIn(components = SingletonComponent.class, replaces = GlobalFooModule.class)
- interface GlobalFooTestModule {
- @Provides
- static Foo provideFoo() {
- return new Foo(GlobalFooTestModule.class);
- }
- }
-}