summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
author Elliot Sisteron <elliotsisteron@google.com> 2023-07-27 16:59:14 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-07-27 16:59:14 +0000
commit75aed2a34e77a1e3db24a93e14ee4ffe325ee94c (patch)
tree3a1fbc703c8fb2e8f03dd103b9fa0058d4d7904c /tests
parent6a44ac49cdbed20bbf3269286dcc4343103dfaea (diff)
parent27d51efebc146907aadff51afa99241f8c6f69e8 (diff)
Merge "Add more context to the notifications failures." into udc-mainline-prod
Diffstat (limited to 'tests')
-rw-r--r--tests/utils/safetycenter/java/com/android/safetycenter/testing/TestNotificationListener.kt26
1 files changed, 16 insertions, 10 deletions
diff --git a/tests/utils/safetycenter/java/com/android/safetycenter/testing/TestNotificationListener.kt b/tests/utils/safetycenter/java/com/android/safetycenter/testing/TestNotificationListener.kt
index 37af98e1b..f02c90712 100644
--- a/tests/utils/safetycenter/java/com/android/safetycenter/testing/TestNotificationListener.kt
+++ b/tests/utils/safetycenter/java/com/android/safetycenter/testing/TestNotificationListener.kt
@@ -85,7 +85,7 @@ class TestNotificationListener : NotificationListenerService() {
}
companion object {
- private const val TAG = "TestNotificationListene"
+ private const val TAG = "SafetyCenterTestNotif"
private val connected = ConditionVariable(false)
private val disconnected = ConditionVariable(true)
@@ -125,7 +125,10 @@ class TestNotificationListener : NotificationListenerService() {
count: Int,
timeout: Duration = TIMEOUT_LONG
): List<StatusBarNotificationWithChannel> {
- return waitForNotificationsToSatisfy(timeout, description = "$count notifications") {
+ return waitForNotificationsToSatisfy(
+ timeout = timeout,
+ description = "$count notifications"
+ ) {
it.size == count
}
}
@@ -155,7 +158,7 @@ class TestNotificationListener : NotificationListenerService() {
): List<StatusBarNotificationWithChannel> {
val charsList = characteristics.toList()
return waitForNotificationsToSatisfy(
- timeout,
+ timeout = timeout,
description = "notification(s) matching characteristics $charsList"
) {
NotificationCharacteristics.areMatching(it, charsList)
@@ -180,10 +183,6 @@ class TestNotificationListener : NotificationListenerService() {
description: String,
predicate: (List<StatusBarNotificationWithChannel>) -> Boolean
): List<StatusBarNotificationWithChannel> {
- fun formatError(notifs: List<StatusBarNotificationWithChannel>): String {
- return "Expected: $description, but the actual notifications were: $notifs"
- }
-
// First we wait at most timeout for the active notifications to satisfy the given
// predicate or otherwise we throw:
val satisfyingNotifications =
@@ -192,7 +191,11 @@ class TestNotificationListener : NotificationListenerService() {
waitForNotificationsToSatisfyAsync(predicate)
}
} catch (e: TimeoutCancellationException) {
- throw AssertionError(formatError(getSafetyCenterNotifications()), e)
+ throw AssertionError(
+ "Expected: $description, but notifications were " +
+ "${getSafetyCenterNotifications()} after waiting for $timeout",
+ e
+ )
}
// Assuming the predicate was satisfied, now we ensure it is not violated for the
@@ -203,7 +206,10 @@ class TestNotificationListener : NotificationListenerService() {
}
if (nonSatisfyingNotifications != null) {
// In this case the negated-predicate was satisfied before forAtLeast had elapsed
- throw AssertionError(formatError(nonSatisfyingNotifications))
+ throw AssertionError(
+ "Expected: $description to settle, but notifications changed to " +
+ "$nonSatisfyingNotifications within $forAtLeast"
+ )
}
return satisfyingNotifications
@@ -276,7 +282,7 @@ class TestNotificationListener : NotificationListenerService() {
fun cancelAndWait(key: String, timeout: Duration = TIMEOUT_LONG) {
getInstanceOrThrow().cancelNotification(key)
waitForNotificationsToSatisfy(
- timeout,
+ timeout = timeout,
description = "no notification with the key $key"
) { notifications ->
notifications.none { it.statusBarNotification.key == key }