Let testable callbacks use Network directly
In retrospect it's surprising we didn't have this already but
the need didn't arise.
Bug: 139268426
Test: NetworkStackTests
Change-Id: If0616c60bac301c7d983d94474cd4264bf7df214
(cherry picked from commit 85a253dccab12e9c6b5b83ee5bec264a2c9ec173)
diff --git a/tests/lib/src/com/android/testutils/TestableNetworkCallback.kt b/tests/lib/src/com/android/testutils/TestableNetworkCallback.kt
index bbb279e..cfdff51 100644
--- a/tests/lib/src/com/android/testutils/TestableNetworkCallback.kt
+++ b/tests/lib/src/com/android/testutils/TestableNetworkCallback.kt
@@ -228,7 +228,7 @@
) {
expectCallback<Available>(net, tmt)
if (suspended) {
- expectCallback<CallbackEntry.Suspended>(net, tmt)
+ expectCallback<Suspended>(net, tmt)
}
expectCapabilitiesThat(net, tmt) { validated == it.hasCapability(NET_CAPABILITY_VALIDATED) }
expectCallback<LinkPropertiesChanged>(net, tmt)
@@ -278,16 +278,23 @@
@JvmOverloads
open fun <T : CallbackEntry> expectCallback(
type: KClass<T>,
- n: HasNetwork?,
+ n: Network?,
timeoutMs: Long = defaultTimeoutMs
) = pollForNextCallback(timeoutMs).also {
- val network = n?.network ?: NULL_NETWORK
+ val network = n ?: NULL_NETWORK
// TODO : remove this .java access if the tests ever use kotlin-reflect. At the time of
// this writing this would be the only use of this library in the tests.
assertTrue(type.java.isInstance(it) && it.network == network,
"Unexpected callback : $it, expected ${type.java} with Network[$network]")
} as T
+ @JvmOverloads
+ open fun <T : CallbackEntry> expectCallback(
+ type: KClass<T>,
+ n: HasNetwork?,
+ timeoutMs: Long = defaultTimeoutMs
+ ) = expectCallback(type, n?.network, timeoutMs)
+
fun expectAvailableCallbacks(
n: HasNetwork,
suspended: Boolean,