jeudi 30 janvier 2020

Kotlin MockK: How to capture a Runnable passed to ExecutorService?

I have a @WebMvcTest which tests a @RestController that needs a special ExecutorService @Bean provided in a library, i.e. not present in the slice.

I didn't want to turn it into a full @SpringBootTest so I wanted to use just CompletableFuture.runAsync(). So I tried this:

    every {
        //val captureLambda = captureLambda<Function<T>>()
        val captureRunnable = capture(slotRunnable)
         eventsExecutorService.submit(captureRunnable)
    } returns CompletableFuture.runAsync(slotRunnable.captured)

But it fails, saying that lateinit var "captured" was not initialized.

Is this expected? Is this the right way to do it? Or am I missing something?

Aucun commentaire:

Enregistrer un commentaire