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 static on Java 19 is broken #929

Open
3 tasks done
uthark opened this issue Sep 26, 2022 · 1 comment
Open
3 tasks done

mocking static on Java 19 is broken #929

uthark opened this issue Sep 26, 2022 · 1 comment

Comments

@uthark
Copy link

uthark commented Sep 26, 2022

Prerequisites

Please answer the following questions for yourself before submitting an 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

Expected Behavior

Tests are working.

Current Behavior

Exception from mockk

Failure Information (for bugs)

Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. step 1
  2. step 2
  3. you get it...

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • MockK version: 1.13.1
  • OS: macOS 12.6
  • Kotlin version: 1.17.10
  • JDK version: Java 19
  • JUnit version: 5.9.2
  • Type of test: unit test

Failure Logs

Please include any relevant log snippets or files here.

Stack trace

// -----------------------[ YOUR STACK STARTS HERE ] -----------------------
    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:64)
        at app//io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:30)
        at app//io.mockk.MockKDsl.internalEvery(API.kt:93)
        at app//io.mockk.MockKKt.every(MockK.kt:98)
// -----------------------[ YOUR STACK TRACE ENDS HERE ] -----------------------

Minimal reproducible code (the gist of this issue)

// -----------------------[ GRADLE DEFINITIONS ] -----------------------
testFixturesApi("io.mockk:mockk-jvm:1.13.1")
// -----------------------[ YOUR CODE STARTS HERE ] -----------------------
package io.mockk.gh


import io.mockk.*
import kotlin.test.Test

class Issue69Test {
 
private val startTime: Instant = Instant.now()

     @BeforeEach
    fun setup() {
        // Mocking instant to return always value on now().
        mockkStatic(Instant::class)
        every { Instant.now() } returns startTime
    }

}
// -----------------------[ YOUR CODE ENDS HERE ] -----------------------
@Lacritz
Copy link

Lacritz commented Oct 13, 2022

Having the same issue but running and building on JVM 17.
It seems to not recognize the mockkStatic(Instant::class) when trying to mock the static call.

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

2 participants