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

UInt and UByte return values cannot be mocked in suspending functions #1259

Open
3 tasks done
david-livefront opened this issue May 28, 2024 · 0 comments
Open
3 tasks done

Comments

@david-livefront
Copy link

david-livefront commented May 28, 2024

Prerequisites

  • 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

Expected Behavior

When I create a mock for a Kotlin class, I should be able to mock a UInt or UByte response on a suspending function.

Current Behavior

The mock will return a Java Integer or Java Byte instead of the appropriate Kotlin unsigned type, this causes type mismatches and can lead to a ClassCastException.

Context

MockK version: 1.13.11
OS: MacOS Sonoma 14.4.1
Kotlin version: 1.9.24
JDK version: openjdk-17
JUnit version: 5.10.2
Type of test: unit test

Minimal reproducible code (the gist of this issue)

Note that removing the suspend keyword from the bar() function causes this test to pass.

    interface Foo {
        suspend fun bar(): UByte
    }

    @Test
    fun `mock Ubyte`() = runBlocking {
        val result: UByte = 5u
        val mock = mockk<Foo> {
            coEvery { bar() } returns result
        }

       assertEquals(result, mock.bar())
    }
@david-livefront david-livefront changed the title UInt and UByte retur values cannot be mocked in suspending functions UInt and UByte return values cannot be mocked in suspending functions May 28, 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