diff options
Diffstat (limited to 'testApi/src')
-rw-r--r-- | testApi/src/main/kotlin/testApi/utils/assertIsInstance.kt | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/testApi/src/main/kotlin/testApi/utils/assertIsInstance.kt b/testApi/src/main/kotlin/testApi/utils/assertIsInstance.kt new file mode 100644 index 00000000..0220799a --- /dev/null +++ b/testApi/src/main/kotlin/testApi/utils/assertIsInstance.kt @@ -0,0 +1,17 @@ +package testApi.utils + +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract + +@OptIn(ExperimentalContracts::class) +inline fun <reified T> assertIsInstance(obj: Any?): T { + contract { + returns() implies (obj is T) + } + + if (obj is T) { + return obj + } + + throw AssertionError("Expected instance of type ${T::class.qualifiedName} but found $obj") +}
\ No newline at end of file |