Skip to content

Instantly share code, notes, and snippets.

@sukyology
Created January 17, 2021 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sukyology/7a77b8b1725283249163cdd202301665 to your computer and use it in GitHub Desktop.
Save sukyology/7a77b8b1725283249163cdd202301665 to your computer and use it in GitHub Desktop.
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