summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-05-26 04:09:01 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-05-26 04:09:01 +0000
commit3f0922c166db1b85de9ab9daa6df9cbd33f1e044 (patch)
treed68d6ef50d4eb76d112a86190772c678a2e5e41a /tests
parentc0816168ec24b1eea73543d2ee398f4cc30bee05 (diff)
parentd44175e9f54421e9d8b6a01512174f3afb76a73e (diff)
Merge "Add an eventuallyExpect call that returns null" into rvc-dev
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/src/com/android/testutils/TestableNetworkCallback.kt12
1 files changed, 11 insertions, 1 deletions
diff --git a/tests/lib/src/com/android/testutils/TestableNetworkCallback.kt b/tests/lib/src/com/android/testutils/TestableNetworkCallback.kt
index c9da2f2..b63e137 100644
--- a/tests/lib/src/com/android/testutils/TestableNetworkCallback.kt
+++ b/tests/lib/src/com/android/testutils/TestableNetworkCallback.kt
@@ -32,6 +32,7 @@ import com.android.testutils.RecorderCallback.CallbackEntry.Suspended
import com.android.testutils.RecorderCallback.CallbackEntry.Unavailable
import kotlin.reflect.KClass
import kotlin.test.assertEquals
+import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import kotlin.test.fail
@@ -194,7 +195,16 @@ open class TestableNetworkCallback private constructor(
timeoutMs: Long = defaultTimeoutMs,
from: Int = mark,
crossinline predicate: (T) -> Boolean = { true }
- ) = history.poll(timeoutMs, from) { it is T && predicate(it) } as T
+ ): T = eventuallyExpectOrNull(timeoutMs, from, predicate).also {
+ assertNotNull(it, "Callback ${T::class} not received within ${timeoutMs}ms")
+ } as T
+
+ // TODO (b/157405399) straighten and unify the method names
+ inline fun <reified T : CallbackEntry> eventuallyExpectOrNull(
+ timeoutMs: Long = defaultTimeoutMs,
+ from: Int = mark,
+ crossinline predicate: (T) -> Boolean = { true }
+ ) = history.poll(timeoutMs, from) { it is T && predicate(it) } as T?
fun expectCallbackThat(
timeoutMs: Long = defaultTimeoutMs,