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

Mocking android.util.Pair throws exception #1246

Closed
BMXsanko opened this issue May 3, 2024 · 1 comment
Closed

Mocking android.util.Pair throws exception #1246

BMXsanko opened this issue May 3, 2024 · 1 comment

Comments

@BMXsanko
Copy link

BMXsanko commented May 3, 2024

Hello, I am trying to mock android AssistStrcuture.ViewNode I am able to mock everything except ViewNode.htmlInfo.attributes it is a list of android.util.Pair class.

I have tried multiple things but nothing seems to work, can someone help me with the issue?

  • [✅] I am running the latest version
  • [✅ ] I checked the documentation and found no answer
  • [✅] I checked to make sure that this issue has not already been filed
  • MockK version: 1.13.10
  • OS: Windows
  • Kotlin version: 1.9.20
  • Type of test: unit test

Stack trace

io.mockk.MockKException: Missing mocked calls inside every { ... } block: make sure the object inside the block is a mock
	at app//io.mockk.impl.recording.states.StubbingState.checkMissingCalls(StubbingState.kt:14)
	at app//io.mockk.impl.recording.states.StubbingState.recordingDone(StubbingState.kt:8)
	at app//io.mockk.impl.recording.CommonCallRecorder.done(CommonCallRecorder.kt:47)
	at app//io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:63)
	at app//io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:30)
	at app//io.mockk.MockKDsl.internalEvery(API.kt:94)
	at app//io.mockk.MockKKt.every(MockK.kt:143)
...

Minimal reproducible code (the gist of this issue)

        val mockedAttributes: android.util.Pair<String, String> = mockk(relaxed = true)
        every { mockedAttributes.toString() } returns "Works as expected"
        every { mockedAttributes.first } returns "throws io.mockk.MockKException: Missing mocked calls inside every "
@BMXsanko
Copy link
Author

BMXsanko commented May 6, 2024

This workaround seems to have worked :)
#1244

@BMXsanko BMXsanko closed this as completed May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant