Add support for unknown Network to expectCallback
This patch allows not passing a network to expectCallback
to allow receiving a callback when the network isn't known.
This is supported in other expect* methods but somehow was
missed in this one.
Test: Ikev2VpnRunnerTest, which uses this ability
Change-Id: Ifd20dd8789ff8b277bac3a73ddd23e2fe9febbca
diff --git a/staticlibs/testutils/devicetests/com/android/testutils/TestableNetworkCallback.kt b/staticlibs/testutils/devicetests/com/android/testutils/TestableNetworkCallback.kt
index c2b5a5c..66c6eb9 100644
--- a/staticlibs/testutils/devicetests/com/android/testutils/TestableNetworkCallback.kt
+++ b/staticlibs/testutils/devicetests/com/android/testutils/TestableNetworkCallback.kt
@@ -41,6 +41,7 @@
object NULL_NETWORK : Network(-1)
object ANY_NETWORK : Network(-2)
+fun anyNetwork() = ANY_NETWORK
private val Int.capabilityName get() = NetworkCapabilities.capabilityNameOf(this)
@@ -385,7 +386,7 @@
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,
+ assertTrue(type.java.isInstance(it) && (ANY_NETWORK === n || it.network == network),
"Unexpected callback : $it, expected ${type.java} with Network[$network]")
} as T