Skip to content

Commit

Permalink
Refactor ResourceTestJvm from Kotest Plugin to Kotlin-test runtime (#…
Browse files Browse the repository at this point in the history
…3244)

Closes #3213
  • Loading branch information
chrsblck authored Oct 29, 2023
1 parent 1b68bfc commit 2fa4f41
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package arrow.fx.coroutines

import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
import java.util.concurrent.atomic.AtomicBoolean
import java.lang.AutoCloseable
import java.io.Closeable
import io.kotest.property.Arb
import io.kotest.property.checkAll
import kotlinx.coroutines.test.runTest
import kotlin.test.Test

class ResourceTestJvm : StringSpec({
class ResourceTestJvm {

class AutoCloseableTest : AutoCloseable {
val didClose = AtomicBoolean(false)
Expand All @@ -20,32 +21,32 @@ class ResourceTestJvm : StringSpec({
val didClose = AtomicBoolean(false)
override fun close() = didClose.set(true)
}
"AutoCloseable closes" {

@Test fun autoCloseableCloses() = runTest {
val t = AutoCloseableTest()
resourceScope {
autoCloseable { t }
}

t.didClose.get() shouldBe true
}
"AutoCloseable closes on error" {

@Test fun autoCloseableClosesOnError() = runTest {
checkAll(Arb.throwable()) { throwable ->
val t = AutoCloseableTest()

shouldThrow<Exception> {
resourceScope {
autoCloseable { t }
throw throwable
}
} shouldBe throwable

t.didClose.get() shouldBe true
}
}
"Closeable closes" {

@Test fun closeableCloses() = runTest {
val t = CloseableTest()

resourceScope {
Expand All @@ -54,8 +55,8 @@ class ResourceTestJvm : StringSpec({

t.didClose.get() shouldBe true
}
"Closeable closes on error" {

@Test fun closeableClosesOnError() = runTest {
checkAll(Arb.throwable()) { throwable ->
val t = CloseableTest()

Expand All @@ -69,4 +70,4 @@ class ResourceTestJvm : StringSpec({
t.didClose.get() shouldBe true
}
}
})
}

0 comments on commit 2fa4f41

Please sign in to comment.