aboutsummaryrefslogtreecommitdiff
path: root/testApi
diff options
context:
space:
mode:
Diffstat (limited to 'testApi')
-rw-r--r--testApi/src/main/kotlin/testApi/utils/assertIsInstance.kt17
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