Skip to content

Commit

Permalink
test: add test cases for exceptions 💣
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Mar 22, 2024
1 parent 7d23fb0 commit 0c44b4c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/test/java/io/foldright/inspectablewrappers/WrapperTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.foldright.inspectablewrappers

import io.foldright.inspectablewrappers.utils.AttachableDelegate
import io.kotest.assertions.fail
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.booleans.shouldBeFalse
import io.kotest.matchers.booleans.shouldBeTrue
Expand All @@ -24,6 +26,25 @@ class WrapperTest : FunSpec({

Wrapper.getAttachment<Executor, String, String>(chatty, "not existed").shouldBeNull()
}

test("ClassCastException") {
shouldThrow<ClassCastException> {
val value = Wrapper.getAttachment<Executor, String, Int?>(chatty, "busy")
fail(value.toString())
}
}

test("argument null") {
shouldThrow<NullPointerException> {
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS", "CAST_NEVER_SUCCEEDS")
Wrapper.getAttachment<Executor, String, String>(null as? Executor, "busy")
}.message shouldBe "wrapper is null"

shouldThrow<NullPointerException> {
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS", "CAST_NEVER_SUCCEEDS")
Wrapper.getAttachment<Executor, String, String>(chatty, null as? String)
}.message shouldBe "key is null"
}
})

class ChattyExecutorWrapper(private val executor: Executor) : Executor, Wrapper<Executor> {
Expand Down

0 comments on commit 0c44b4c

Please sign in to comment.