Skip to content

Instantly share code, notes, and snippets.

@sukyology

sukyology/block13.kt Secret

Created Jan 17, 2021
Embed
What would you like to do?
class Container<S: Sealed>(val sealed: S)
sealed class Sealed
data class SubSealed(val a: String) : Sealed()
class ExampleTest {
@Test
fun test1() {
val container: Container<SubSealed> = mockk(relaxed = true)
assertEquals(SubSealed::class, container.sealed::class) // failed
}
@Test
fun test2() {
val container: Container<SubSealed> = mockk(relaxed = true)
val sealed: SubSealed = container.sealed // ClassCastException
assertEquals(SubSealed::class, sealed::class)
}
@Test
fun test3() {
val container: Container<SubSealed> = mockk(relaxed = true)
every { container.sealed } returns mockk()
val sealed: SubSealed = container.sealed
assertEquals(SubSealed::class, sealed::class) // success
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment