Injects ColorContrastSection classes
Bug: 331594637
Flag: NA
Test: manually verified contrast flow still works
Change-Id: I5b7d7202b43e78d1888dee5dadc534af4002941e
diff --git a/tests/common/Android.bp b/tests/common/Android.bp
index 06c3834..40b0a27 100644
--- a/tests/common/Android.bp
+++ b/tests/common/Android.bp
@@ -23,6 +23,7 @@
android_library {
name: "ThemePickerTestLib",
+ defaults: ["ThemePicker_defaults"],
srcs: [
"src/**/*.java",
"src/**/*.kt",
diff --git a/tests/module/Android.bp b/tests/module/Android.bp
new file mode 100644
index 0000000..c174699
--- /dev/null
+++ b/tests/module/Android.bp
@@ -0,0 +1,30 @@
+// Copyright (C) 2024 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 {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_library {
+ name: "ThemePickerTestModule",
+ srcs: ["src/com/android/customization/TestModule.kt"],
+ static_libs: [
+ "ThemePickerTestLib",
+ "hilt_android",
+ "hilt_android_testing",
+ ],
+
+ platform_apis: true,
+}
diff --git a/tests/module/AndroidManifest.xml b/tests/module/AndroidManifest.xml
new file mode 100644
index 0000000..67ae9de
--- /dev/null
+++ b/tests/module/AndroidManifest.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2024 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.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.wallpaper">
+
+ <application />
+</manifest>
diff --git a/tests/robotests/Android.bp b/tests/robotests/Android.bp
index 1377e22..5c0f388 100644
--- a/tests/robotests/Android.bp
+++ b/tests/robotests/Android.bp
@@ -7,7 +7,10 @@
name: "ThemePickerShell",
defaults: ["ThemePicker_defaults"],
platform_apis: true,
- static_libs: ["ThemePickerTestLib"],
+ static_libs: [
+ "ThemePickerTestLib",
+ "ThemePickerTestModule",
+ ],
}
android_robolectric_test {
@@ -29,6 +32,8 @@
"ThemePickerApplicationLib",
"mockito-robolectric-prebuilt",
"mockito-kotlin2",
+ "hilt_android",
+ "hilt_android_testing",
],
libs: [
diff --git a/tests/robotests/config/robolectric.properties b/tests/robotests/config/robolectric.properties
index fab7251..62f25a7 100644
--- a/tests/robotests/config/robolectric.properties
+++ b/tests/robotests/config/robolectric.properties
@@ -1 +1,2 @@
sdk=NEWEST_SDK
+application = dagger.hilt.android.testing.HiltTestApplication
diff --git a/tests/robotests/src/com/android/customization/model/picker/settings/data/repository/ColorContrastSectionRepositoryTest.kt b/tests/robotests/src/com/android/customization/model/picker/settings/data/repository/ColorContrastSectionRepositoryTest.kt
index f6a3a22..54b7c6e 100644
--- a/tests/robotests/src/com/android/customization/model/picker/settings/data/repository/ColorContrastSectionRepositoryTest.kt
+++ b/tests/robotests/src/com/android/customization/model/picker/settings/data/repository/ColorContrastSectionRepositoryTest.kt
@@ -20,28 +20,30 @@
import com.android.customization.picker.settings.data.repository.ColorContrastSectionRepository
import com.android.wallpaper.testing.FakeUiModeManager
import com.google.common.truth.Truth.assertThat
+import dagger.hilt.android.testing.HiltAndroidRule
+import dagger.hilt.android.testing.HiltAndroidTest
+import javax.inject.Inject
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
-import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.runBlockingTest
-import org.junit.After
import org.junit.Before
+import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
+@HiltAndroidTest
@SmallTest
@RunWith(RobolectricTestRunner::class)
class ColorContrastSectionRepositoryTest {
- private val uiModeManager = FakeUiModeManager()
- private lateinit var underTest: ColorContrastSectionRepository
+ @get:Rule var hiltRule = HiltAndroidRule(this)
- private lateinit var bgDispatcher: TestCoroutineDispatcher
+ @Inject lateinit var uiModeManager: FakeUiModeManager
+ @Inject lateinit var underTest: ColorContrastSectionRepository
@Before
fun setUp() {
- bgDispatcher = TestCoroutineDispatcher()
- underTest = ColorContrastSectionRepository(uiModeManager, bgDispatcher)
+ hiltRule.inject()
}
@Test
@@ -65,10 +67,4 @@
assertThat(collectedValues).containsExactlyElementsIn(nextContrastValues)
job.cancel()
}
-
- @OptIn(ExperimentalCoroutinesApi::class)
- @After
- fun tearDown() {
- bgDispatcher.cleanupTestCoroutines()
- }
}
diff --git a/tests/robotests/src/com/android/customization/model/picker/settings/domain/interactor/ColorContrastSectionInteractorTest.kt b/tests/robotests/src/com/android/customization/model/picker/settings/domain/interactor/ColorContrastSectionInteractorTest.kt
index 9936928..2319eed 100644
--- a/tests/robotests/src/com/android/customization/model/picker/settings/domain/interactor/ColorContrastSectionInteractorTest.kt
+++ b/tests/robotests/src/com/android/customization/model/picker/settings/domain/interactor/ColorContrastSectionInteractorTest.kt
@@ -17,27 +17,37 @@
package com.android.customization.model.picker.settings.domain.interactor
import androidx.test.filters.SmallTest
-import com.android.customization.picker.settings.data.repository.ColorContrastSectionRepository
import com.android.customization.picker.settings.domain.interactor.ColorContrastSectionInteractor
import com.android.wallpaper.testing.FakeUiModeManager
+import dagger.hilt.android.testing.HiltAndroidRule
+import dagger.hilt.android.testing.HiltAndroidTest
+import javax.inject.Inject
import kotlinx.coroutines.flow.first
-import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.runBlockingTest
import org.junit.Assert.assertEquals
+import org.junit.Before
+import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@SmallTest
+@HiltAndroidTest
@RunWith(RobolectricTestRunner::class)
class ColorContrastSectionInteractorTest {
+ @get:Rule var hiltRule = HiltAndroidRule(this)
+
+ @Inject lateinit var uiModeManager: FakeUiModeManager
+ @Inject lateinit var interactor: ColorContrastSectionInteractor
+
+ @Before
+ fun setUp() {
+ hiltRule.inject()
+ }
+
@Test
fun contrastEmitCorrectValuesFromRepository() = runBlockingTest {
- val bgDispatcher = TestCoroutineDispatcher()
- val uiModeManager = FakeUiModeManager()
- val repository = ColorContrastSectionRepository(uiModeManager, bgDispatcher)
val expectedContrast = 1.5f
- val interactor = ColorContrastSectionInteractor(repository)
uiModeManager.setContrast(expectedContrast)
val result = interactor.contrast.first()
diff --git a/tests/robotests/src/com/android/customization/model/picker/settings/ui/viewmodel/ColorContrastSectionViewModelTest.kt b/tests/robotests/src/com/android/customization/model/picker/settings/ui/viewmodel/ColorContrastSectionViewModelTest.kt
index 0910697..c06f8a3 100644
--- a/tests/robotests/src/com/android/customization/model/picker/settings/ui/viewmodel/ColorContrastSectionViewModelTest.kt
+++ b/tests/robotests/src/com/android/customization/model/picker/settings/ui/viewmodel/ColorContrastSectionViewModelTest.kt
@@ -16,37 +16,39 @@
package com.android.customization.model.picker.settings.ui.viewmodel
-import com.android.customization.picker.settings.data.repository.ColorContrastSectionRepository
-import com.android.customization.picker.settings.domain.interactor.ColorContrastSectionInteractor
import com.android.customization.picker.settings.ui.viewmodel.ColorContrastSectionDataViewModel
import com.android.customization.picker.settings.ui.viewmodel.ColorContrastSectionViewModel
import com.android.themepicker.R
import com.android.wallpaper.picker.common.icon.ui.viewmodel.Icon
import com.android.wallpaper.picker.common.text.ui.viewmodel.Text
import com.android.wallpaper.testing.FakeUiModeManager
+import dagger.hilt.android.testing.HiltAndroidRule
+import dagger.hilt.android.testing.HiltAndroidTest
+import javax.inject.Inject
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.first
-import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.runBlockingTest
import org.junit.Assert.assertEquals
import org.junit.Before
+import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
+@HiltAndroidTest
@RunWith(RobolectricTestRunner::class)
class ColorContrastSectionViewModelTest {
- private val uiModeManager = FakeUiModeManager()
- private val bgDispatcher = TestCoroutineDispatcher()
+ @get:Rule var hiltRule = HiltAndroidRule(this)
private lateinit var viewModel: ColorContrastSectionViewModel
+ @Inject lateinit var uiModeManager: FakeUiModeManager
+ @Inject lateinit var viewModelFactory: ColorContrastSectionViewModel.Factory
+
@Before
fun setUp() {
- val repository = ColorContrastSectionRepository(uiModeManager, bgDispatcher)
- val factory =
- ColorContrastSectionViewModel.Factory(ColorContrastSectionInteractor(repository))
- viewModel = factory.create(ColorContrastSectionViewModel::class.java)
+ hiltRule.inject()
+ viewModel = viewModelFactory.create(ColorContrastSectionViewModel::class.java)
}
@Test