mockk icon indicating copy to clipboard operation
mockk copied to clipboard

Support nested value classes

Open aSemy opened this issue 3 years ago • 0 comments

Value class support is being improved in #849

However there are issues when a value class is nested, for example

@JvmInline
value class DummyValue(val value: Int)

@JvmInline
value class DummyValueWrapper(val value: DummyValue)

Stubbing methods which use wrapped types causes exceptions

Caused by: java.lang.ClassCastException: io.mockk.it.ValueClassNestedTest$Companion$DummyValue cannot be cast to java.lang.Integer
	at io.mockk.it.ValueClassNestedTest$Companion$DummyValue.getValue(ValueClassNestedTest.kt:471)

And using any()

Failed matching mocking signature for
SignedCall(retValue=0, isRetValueMock=false, retType=class kotlin.Int, self=DummyService(#1087), method=argWrapperReturnValueClass-_ACQZD0(Int), args=[-1016248876], invocationStr=DummyService(#1087).argWrapperReturnValueClass-_ACQZD0(-1016248876))
left matchers: [any()]
io.mockk.MockKException: Failed matching mocking signature for
SignedCall(retValue=0, isRetValueMock=false, retType=class kotlin.Int, self=DummyService(#1087), method=argWrapperReturnValueClass-_ACQZD0(Int), args=[-1016248876], invocationStr=DummyService(#1087).argWrapperReturnValueClass-_ACQZD0(-1016248876))
left matchers: [any()]

And using slot()

Failed matching mocking signature for
SignedCall(retValue=, isRetValueMock=true, retType=class io.mockk.it.ValueClassNestedTest$Companion$DummyValue, self=DummyService(#1086), method=argWrapperReturnWrapper-QYKvEyQ(Int), args=[376729697], invocationStr=DummyService(#1086).argWrapperReturnWrapper-QYKvEyQ(376729697))
SignedCall(retValue=0, isRetValueMock=false, retType=class kotlin.Int, self=, method=getValue(), args=[], invocationStr=DummyValue(temporary mock).getValue())
left matchers: [slotCapture<DummyValueWrapper>()]
io.mockk.MockKException: Failed matching mocking signature for
SignedCall(retValue=, isRetValueMock=true, retType=class io.mockk.it.ValueClassNestedTest$Companion$DummyValue, self=DummyService(#1086), method=argWrapperReturnWrapper-QYKvEyQ(Int), args=[376729697], invocationStr=DummyService(#1086).argWrapperReturnWrapper-QYKvEyQ(376729697))
SignedCall(retValue=0, isRetValueMock=false, retType=class kotlin.Int, self=, method=getValue(), args=[], invocationStr=DummyValue(temporary mock).getValue())
left matchers: [slotCapture<DummyValueWrapper>()]

I've added tests as part of #849, but disabled them so nested value class support can be added later.

aSemy avatar Jul 24 '22 08:07 aSemy