summaryrefslogtreecommitdiff
path: root/java/tests
diff options
context:
space:
mode:
author Mark Renouf <mrenouf@google.com> 2023-08-30 14:59:06 -0400
committer Mark Renouf <mrenouf@google.com> 2023-09-14 10:48:06 -0400
commita7382f3265d0bb76532b561059e56bafa855542e (patch)
tree31e2fa46d7b74779fe6c1046dc5e25ab8f5a1118 /java/tests
parent4fe01c7ca647194636c592949516677e68fc4a80 (diff)
Switches to HiltTestApplication in tests.
This allows testing with @HiltAndroidTest, @TestInstallIn, etc. Usage to follow in a CL series. Bug: 296633726 Bug: 300157408 Flag: EXEMPT Change-Id: I13fbf29005e11ea7375d77d11da4bc1bfa68b666
Diffstat (limited to 'java/tests')
-rw-r--r--java/tests/Android.bp1
-rw-r--r--java/tests/AndroidManifest.xml2
-rw-r--r--java/tests/src/com/android/intentresolver/ChooserWrapperActivity.java2
-rw-r--r--java/tests/src/com/android/intentresolver/TestApplication.kt26
-rw-r--r--java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java9
-rw-r--r--java/tests/src/com/android/intentresolver/UnbundledChooserActivityWorkProfileTest.java9
6 files changed, 19 insertions, 30 deletions
diff --git a/java/tests/Android.bp b/java/tests/Android.bp
index e4d24eb5..974b8a47 100644
--- a/java/tests/Android.bp
+++ b/java/tests/Android.bp
@@ -44,6 +44,7 @@ android_test {
"androidx.lifecycle_lifecycle-common-java8",
"androidx.lifecycle_lifecycle-extensions",
"androidx.lifecycle_lifecycle-runtime-testing",
+ "hilt_android_testing",
"IntentResolver-core",
"junit",
"kotlinx_coroutines_test",
diff --git a/java/tests/AndroidManifest.xml b/java/tests/AndroidManifest.xml
index ae6a2205..35dc2ee6 100644
--- a/java/tests/AndroidManifest.xml
+++ b/java/tests/AndroidManifest.xml
@@ -23,7 +23,7 @@
<uses-permission android:name="android.permission.WRITE_DEVICE_CONFIG"/>
<uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
- <application android:name="com.android.intentresolver.TestApplication">
+ <application android:name="dagger.hilt.android.testing.HiltTestApplication">
<uses-library android:name="android.test.runner" />
<activity android:name="com.android.intentresolver.ChooserWrapperActivity" />
<activity android:name="com.android.intentresolver.ResolverWrapperActivity" />
diff --git a/java/tests/src/com/android/intentresolver/ChooserWrapperActivity.java b/java/tests/src/com/android/intentresolver/ChooserWrapperActivity.java
index 6dbf9b3f..d488e02b 100644
--- a/java/tests/src/com/android/intentresolver/ChooserWrapperActivity.java
+++ b/java/tests/src/com/android/intentresolver/ChooserWrapperActivity.java
@@ -263,7 +263,7 @@ public class ChooserWrapperActivity extends ChooserActivity implements IChooserW
@Override
public Context createContextAsUser(UserHandle user, int flags) {
// return the current context as a work profile doesn't really exist in these tests
- return getApplicationContext();
+ return this;
}
@Override
diff --git a/java/tests/src/com/android/intentresolver/TestApplication.kt b/java/tests/src/com/android/intentresolver/TestApplication.kt
deleted file mode 100644
index b57fd4d9..00000000
--- a/java/tests/src/com/android/intentresolver/TestApplication.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * 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 com.android.intentresolver
-
-import android.content.Context
-import android.os.UserHandle
-
-class TestApplication : MainApplication() {
-
- // return the current context as a work profile doesn't really exist in these tests
- override fun createContextAsUser(user: UserHandle, flags: Int): Context = this
-}
diff --git a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java
index 2838f00b..0b3cb20a 100644
--- a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java
+++ b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java
@@ -146,6 +146,9 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Function;
+import dagger.hilt.android.testing.HiltAndroidRule;
+import dagger.hilt.android.testing.HiltAndroidTest;
+
/**
* Instrumentation tests for ChooserActivity.
* <p>
@@ -153,6 +156,7 @@ import java.util.function.Function;
* <p>
*/
@RunWith(Parameterized.class)
+@HiltAndroidTest
public class UnbundledChooserActivityTest {
private static final UserHandle PERSONAL_USER_HANDLE = InstrumentationRegistry
@@ -187,7 +191,10 @@ public class UnbundledChooserActivityTest {
cleanOverrideData();
}
- @Rule
+ @Rule(order = 0)
+ public HiltAndroidRule mHiltAndroidRule = new HiltAndroidRule(this);
+
+ @Rule(order = 1)
public ActivityTestRule<ChooserWrapperActivity> mActivityRule =
new ActivityTestRule<>(ChooserWrapperActivity.class, false, false);
diff --git a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityWorkProfileTest.java b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityWorkProfileTest.java
index 92bccb7d..f0e88564 100644
--- a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityWorkProfileTest.java
+++ b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityWorkProfileTest.java
@@ -64,15 +64,22 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;
+import dagger.hilt.android.testing.HiltAndroidRule;
+import dagger.hilt.android.testing.HiltAndroidTest;
+
@DeviceFilter.MediumType
@RunWith(Parameterized.class)
+@HiltAndroidTest
public class UnbundledChooserActivityWorkProfileTest {
private static final UserHandle PERSONAL_USER_HANDLE = InstrumentationRegistry
.getInstrumentation().getTargetContext().getUser();
private static final UserHandle WORK_USER_HANDLE = UserHandle.of(10);
- @Rule
+ @Rule(order = 0)
+ public HiltAndroidRule mHiltAndroidRule = new HiltAndroidRule(this);
+
+ @Rule(order = 1)
public ActivityTestRule<ChooserWrapperActivity> mActivityRule =
new ActivityTestRule<>(ChooserWrapperActivity.class, false,
false);