Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nested value classes #859

Open
aSemy opened this issue Jul 24, 2022 · 3 comments
Open

Support nested value classes #859

aSemy opened this issue Jul 24, 2022 · 3 comments

Comments

@aSemy
Copy link
Contributor

aSemy commented Jul 24, 2022

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.

@stale
Copy link

stale bot commented Nov 2, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If you are sure that this issue is important and should not be marked as stale just ask to put an important label.

@fleboulch
Copy link

I got the same issue. Is it planned to be fixed?

@aSemy
Copy link
Contributor Author

aSemy commented Nov 29, 2022

I got the same issue. Is it planned to be fixed?

There are no plans as far as I know. I hope that this would be easy to fix. The helper functions in ValueClassSupport need to be updated to recursively unbox value classes.

https://github.com/mockk/mockk/blob/219ddafc94869feec4d808e2b1108db9a3ce005f/modules/mockk-core/src/jvmMain/kotlin/io/mockk/core/ValueClassSupport.kt

Feel free to give it a go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants