fix(api): add test util for type assertion

This commit is contained in:
Harsh Shandilya 2023-05-04 03:33:19 +05:30
parent 5c8057d71f
commit 5d2eebf093
No known key found for this signature in database

View file

@ -6,8 +6,12 @@
*/ */
package dev.msfjarvis.claw.util package dev.msfjarvis.claw.util
import com.google.common.truth.Truth.assertThat
import java.io.File import java.io.File
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
@OptIn(ExperimentalContracts::class)
object TestUtils { object TestUtils {
fun getJson(path: String): String { fun getJson(path: String): String {
// Load the JSON response // Load the JSON response
@ -15,4 +19,10 @@ object TestUtils {
val file = File(uri.path) val file = File(uri.path)
return String(file.readBytes()) return String(file.readBytes())
} }
inline fun <reified T> assertIs(value: Any?): T {
contract { returns() implies (value is T) }
assertThat(value).isInstanceOf(T::class.java)
return value as T
}
} }