jmfayard
03/10/2022, 12:37 PMsealed class Either
which either a Left
or a Right
But actually no, because in my unit tests, mockk creates a subclass of Either
which is neither Left nor Right and break the contract of my type
Is there a way to forbit mockkk to create a subclass of a sealed class?eurycea
03/10/2022, 12:44 PMEither
or are you wanting a warning/error when you try to mock a sealed class?jmfayard
03/10/2022, 12:52 PMephemient
03/10/2022, 12:53 PMephemient
03/10/2022, 12:54 PMjmfayard
03/10/2022, 1:17 PM@ForbidMockk
to tell explicitely that the class is not to be mocked?jmfayard
03/10/2022, 3:31 PMJvmMockKGateway.anyValueGeneratorFactory = { voidInstance ->
object : JvmAnyValueGenerator(voidInstance) {
override fun anyValue(cls: KClass<*>, isNullable: Boolean, orInstantiateVia: () -> Any?): Any? {
if (cls == Either::class) return Either.Left(MockingError)
return super.anyValue(cls, isNullable, orInstantiateVia)
}
}
}