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
This commit is contained in:
Chalard Jean
2022-02-07 11:05:14 +09:00
parent 88d7d17c7b
commit 1a21b9a9db

View File

@@ -41,6 +41,7 @@ import kotlin.test.fail
object NULL_NETWORK : Network(-1) object NULL_NETWORK : Network(-1)
object ANY_NETWORK : Network(-2) object ANY_NETWORK : Network(-2)
fun anyNetwork() = ANY_NETWORK
private val Int.capabilityName get() = NetworkCapabilities.capabilityNameOf(this) private val Int.capabilityName get() = NetworkCapabilities.capabilityNameOf(this)
@@ -385,7 +386,7 @@ open class TestableNetworkCallback private constructor(
val network = n ?: NULL_NETWORK val network = n ?: NULL_NETWORK
// TODO : remove this .java access if the tests ever use kotlin-reflect. At the time of // 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. // 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]") "Unexpected callback : $it, expected ${type.java} with Network[$network]")
} as T } as T