Skip to content

Commit

Permalink
Add tests for issue mockk#934
Browse files Browse the repository at this point in the history
  • Loading branch information
diastremskii authored and cliffred committed Oct 25, 2022
1 parent a2421bf commit ce37b26
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
22 changes: 22 additions & 0 deletions modules/mockk/src/commonTest/kotlin/io/mockk/it/SealedClassTest.kt
Expand Up @@ -2,6 +2,8 @@ package io.mockk.it

import io.mockk.every
import io.mockk.mockk
import org.junit.jupiter.api.condition.DisabledForJreRange
import org.junit.jupiter.api.condition.JRE
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -30,6 +32,22 @@ class SealedClassTest {
assertEquals(Leaf(1), result)
}

@Test
@DisabledForJreRange(
min = JRE.JAVA_17,
disabledReason = "https://github.com/mockk/mockk/issues/934"
)
fun serviceTakesSealedClassAsInput() {
val formattedNode = "Formatted node"
val factory = mockk<Factory> {
every { format(any()) } answers { formattedNode }
}

val result = factory.format(Root(0))

assertEquals(formattedNode, result)
}

companion object {

sealed class Node
Expand All @@ -39,10 +57,14 @@ class SealedClassTest {

interface Factory {
fun create(): Node

fun format(node: Node): String
}

class FactoryImpl : Factory {
override fun create(): Node = Root(0)

override fun format(node: Node): String = node.toString()
}

}
Expand Down
Expand Up @@ -2,6 +2,8 @@ package io.mockk.it

import io.mockk.every
import io.mockk.mockk
import org.junit.jupiter.api.condition.DisabledForJreRange
import org.junit.jupiter.api.condition.JRE
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -30,6 +32,22 @@ class SealedInterfaceTest {
assertEquals(Leaf(1), result)
}

@Test
@DisabledForJreRange(
min = JRE.JAVA_17,
disabledReason = "https://github.com/mockk/mockk/issues/934"
)
fun serviceTakesSealedInterfaceAsInput() {
val formattedNode = "Formatted node"
val factory = mockk<Factory> {
every { format(any()) } answers { formattedNode }
}

val result = factory.format(Root(0))

assertEquals(formattedNode, result)
}

companion object {

sealed interface Node
Expand All @@ -39,10 +57,14 @@ class SealedInterfaceTest {

interface Factory {
fun create(): Node

fun format(node: Node): String
}

class FactoryImpl : Factory {
override fun create(): Node = Root(0)

override fun format(node: Node): String = node.toString()
}

}
Expand Down

0 comments on commit ce37b26

Please sign in to comment.