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 Kotlin 1.9.20's enums with mockkObject #1198

Open
TWiStErRob opened this issue Jan 5, 2024 · 2 comments
Open

Support Kotlin 1.9.20's enums with mockkObject #1198

TWiStErRob opened this issue Jan 5, 2024 · 2 comments

Comments

@TWiStErRob
Copy link

TWiStErRob commented Jan 5, 2024

Expected Behavior

Works as before.

Current Behavior

Throws strange exception.

Steps to Reproduce

  1. Clone https://github.com/TWiStErRob/repros/tree/main/mockk/mockkObject-missing-every-on-enum
  2. gradlew test -> fail
  3. Downgrade Kotlin to 1.9.10 (build.gradle.kts > plugins { })
  4. gradlew test -> pass

Context

I was updating a project's dependencies and I was faced with a test failure. The test was working previously, so I narrowed it down to the Kotlin from 1.9.10 to 1.9.21.

My hunch is that is that mockk does something to values(), but doesn't do to entries, because it's not aware of it. This causes mockkObject to misbehave. Don't go just on this though, I might be wrong, because it was added in 1.9.0.

  • MockK version: 1.13.8 or earlier
  • OS: Mac / Ubuntu 20 / not relevant
  • Kotlin version: 1.9.20/.21/.22
  • JDK version: 11 / 17 / not relevant
  • JUnit version: 4.13.2 / not relevant
  • Type of test: unit test

Stack trace

Missing mocked calls inside every { ... } block: make sure the object inside the block is a mock
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)
	at app//com.example.MyEnumTest.test(MyEnumTest.kt:11)

Note: I confirmed mockkObject does what it should with a simple println(MyEnum.A).

Minimal reproducible code (the gist of this issue)

enum class MyEnum { A }

mockkObject(MyEnum.A)
every { MyEnum.A.name } returns "not-a"
TWiStErRob added a commit to TWiStErRob/repros that referenced this issue Jan 5, 2024
@ddaakk
Copy link

ddaakk commented Feb 22, 2024

Hello, I would like to be assigned to the specific issue.

@Raibaz
Copy link
Collaborator

Raibaz commented Feb 29, 2024

Sure, go ahead, thanks!

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

3 participants