summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/demomode/DemoModeControllerTest.kt2
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardQuickAffordanceLocalUserSelectionManagerTest.kt17
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepositoryTest.kt10
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardLongPressInteractorTest.kt7
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt44
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/broadcast/FakeBroadcastDispatcher.kt19
6 files changed, 48 insertions, 51 deletions
diff --git a/packages/SystemUI/tests/src/com/android/systemui/demomode/DemoModeControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/demomode/DemoModeControllerTest.kt
index 75eec72a949c..68ea7ebb3358 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/demomode/DemoModeControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/demomode/DemoModeControllerTest.kt
@@ -94,7 +94,7 @@ class DemoModeControllerTest : SysuiTestCase() {
intent.putExtra("command", command)
args.forEach { arg -> intent.putExtra(arg.key, arg.value) }
- fakeBroadcastDispatcher.registeredReceivers.forEach { it.onReceive(context, intent) }
+ fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly(context, intent)
}
companion object {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardQuickAffordanceLocalUserSelectionManagerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardQuickAffordanceLocalUserSelectionManagerTest.kt
index b2528c5b9832..edaff44cf543 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardQuickAffordanceLocalUserSelectionManagerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/quickaffordance/KeyguardQuickAffordanceLocalUserSelectionManagerTest.kt
@@ -25,6 +25,7 @@ import androidx.test.filters.SmallTest
import com.android.systemui.R
import com.android.systemui.RoboPilotTest
import com.android.systemui.SysuiTestCase
+import com.android.systemui.backup.BackupHelper
import com.android.systemui.settings.FakeUserTracker
import com.android.systemui.settings.UserFileManager
import com.android.systemui.util.FakeSharedPreferences
@@ -360,7 +361,10 @@ class KeyguardQuickAffordanceLocalUserSelectionManagerTest : SysuiTestCase() {
}
clearInvocations(userFileManager)
- fakeBroadcastDispatcher.registeredReceivers.firstOrNull()?.onReceive(context, Intent())
+ fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly(
+ context,
+ Intent(BackupHelper.ACTION_RESTORE_FINISHED),
+ )
verify(userFileManager, atLeastOnce()).getSharedPreferences(anyString(), anyInt(), anyInt())
job.cancel()
@@ -374,12 +378,13 @@ class KeyguardQuickAffordanceLocalUserSelectionManagerTest : SysuiTestCase() {
arrayOf("leftTest:testShortcut1", "rightTest:testShortcut2")
)
- assertThat(underTest.getSelections()).isEqualTo(
- mapOf(
- "leftTest" to listOf("testShortcut1"),
- "rightTest" to listOf("testShortcut2"),
+ assertThat(underTest.getSelections())
+ .isEqualTo(
+ mapOf(
+ "leftTest" to listOf("testShortcut1"),
+ "rightTest" to listOf("testShortcut2"),
+ )
)
- )
}
private fun assertSelections(
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepositoryTest.kt
index b925aeb10262..f9070b37ca48 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepositoryTest.kt
@@ -461,12 +461,10 @@ class BiometricSettingsRepositoryTest : SysuiTestCase() {
}
private fun broadcastDPMStateChange() {
- fakeBroadcastDispatcher.registeredReceivers.forEach { receiver ->
- receiver.onReceive(
- context,
- Intent(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED)
- )
- }
+ fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly(
+ context,
+ Intent(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED),
+ )
}
companion object {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardLongPressInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardLongPressInteractorTest.kt
index f63be610fd11..e9c22f9d551d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardLongPressInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardLongPressInteractorTest.kt
@@ -194,9 +194,10 @@ class KeyguardLongPressInteractorTest : SysuiTestCase() {
underTest.onLongPress()
assertThat(isMenuVisible).isTrue()
- fakeBroadcastDispatcher.registeredReceivers.forEach { broadcastReceiver ->
- broadcastReceiver.onReceive(context, Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS))
- }
+ fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly(
+ context,
+ Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS),
+ )
assertThat(isMenuVisible).isFalse()
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt
index 3fbbeda8f74d..89dce6151de9 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/UserInteractorTest.kt
@@ -633,13 +633,11 @@ class UserInteractorTest : SysuiTestCase() {
userRepository.setSelectedUserInfo(userInfos[1])
runCurrent()
- fakeBroadcastDispatcher.registeredReceivers.forEach {
- it.onReceive(
- context,
- Intent(Intent.ACTION_USER_SWITCHED)
- .putExtra(Intent.EXTRA_USER_HANDLE, userInfos[1].id),
- )
- }
+ fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly(
+ context,
+ Intent(Intent.ACTION_USER_SWITCHED)
+ .putExtra(Intent.EXTRA_USER_HANDLE, userInfos[1].id),
+ )
runCurrent()
verify(callback1, atLeastOnce()).onUserStateChanged()
@@ -656,12 +654,10 @@ class UserInteractorTest : SysuiTestCase() {
userRepository.setSelectedUserInfo(userInfos[0])
val refreshUsersCallCount = userRepository.refreshUsersCallCount
- fakeBroadcastDispatcher.registeredReceivers.forEach {
- it.onReceive(
- context,
- Intent(Intent.ACTION_USER_INFO_CHANGED),
- )
- }
+ fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly(
+ context,
+ Intent(Intent.ACTION_USER_INFO_CHANGED),
+ )
runCurrent()
@@ -676,13 +672,11 @@ class UserInteractorTest : SysuiTestCase() {
userRepository.setSelectedUserInfo(userInfos[0])
val refreshUsersCallCount = userRepository.refreshUsersCallCount
- fakeBroadcastDispatcher.registeredReceivers.forEach {
- it.onReceive(
- context,
- Intent(Intent.ACTION_USER_UNLOCKED)
- .putExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_SYSTEM),
- )
- }
+ fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly(
+ context,
+ Intent(Intent.ACTION_USER_UNLOCKED)
+ .putExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_SYSTEM),
+ )
runCurrent()
assertThat(userRepository.refreshUsersCallCount).isEqualTo(refreshUsersCallCount + 1)
@@ -696,12 +690,10 @@ class UserInteractorTest : SysuiTestCase() {
userRepository.setSelectedUserInfo(userInfos[0])
val refreshUsersCallCount = userRepository.refreshUsersCallCount
- fakeBroadcastDispatcher.registeredReceivers.forEach {
- it.onReceive(
- context,
- Intent(Intent.ACTION_USER_UNLOCKED).putExtra(Intent.EXTRA_USER_HANDLE, 1337),
- )
- }
+ fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly(
+ context,
+ Intent(Intent.ACTION_USER_UNLOCKED).putExtra(Intent.EXTRA_USER_HANDLE, 1337),
+ )
assertThat(userRepository.refreshUsersCallCount).isEqualTo(refreshUsersCallCount)
}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/broadcast/FakeBroadcastDispatcher.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/broadcast/FakeBroadcastDispatcher.kt
index f19e19113b30..21a5eb7022b0 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/broadcast/FakeBroadcastDispatcher.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/broadcast/FakeBroadcastDispatcher.kt
@@ -36,9 +36,9 @@ import java.util.concurrent.Executor
* A fake instance of [BroadcastDispatcher] for tests.
*
* Important: The *real* broadcast dispatcher will only send intents to receivers if the intent
- * matches the [IntentFilter] that the [BroadcastReceiver] was registered with. This fake class does
- * *not* do that matching by default. Use [sendIntentToMatchingReceiversOnly] to get the same
- * matching behavior as the real broadcast dispatcher.
+ * matches the [IntentFilter] that the [BroadcastReceiver] was registered with. This fake class
+ * exposes [sendIntentToMatchingReceiversOnly] to get the same matching behavior as the real
+ * broadcast dispatcher.
*/
class FakeBroadcastDispatcher(
context: SysuiTestableContext,
@@ -63,9 +63,6 @@ class FakeBroadcastDispatcher(
private val receivers: MutableSet<InternalReceiver> = ConcurrentHashMap.newKeySet()
- val registeredReceivers: Set<BroadcastReceiver>
- get() = receivers.map { it.receiver }.toSet()
-
override fun registerReceiverWithHandler(
receiver: BroadcastReceiver,
filter: IntentFilter,
@@ -115,11 +112,15 @@ class FakeBroadcastDispatcher(
}
}
+ val numReceiversRegistered: Int
+ get() = receivers.size
+
fun cleanUpReceivers(testName: String) {
- registeredReceivers.forEach {
- Log.i(testName, "Receiver not unregistered from dispatcher: $it")
+ receivers.forEach {
+ val receiver = it.receiver
+ Log.i(testName, "Receiver not unregistered from dispatcher: $receiver")
if (shouldFailOnLeakedReceiver) {
- throw IllegalStateException("Receiver not unregistered from dispatcher: $it")
+ throw IllegalStateException("Receiver not unregistered from dispatcher: $receiver")
}
}
receivers.clear()