mockito / mockito-kotlin

Using Mockito with Kotlin
MIT License
3.09k stars 198 forks source link

Mocking fails in a test method containing space in its name #443

Open MastaP opened 2 years ago

MastaP commented 2 years ago

Another bug has emerged while working on #441 The following two methods have identical bodies, the only difference is in test methods' names, the second one contains a space

    @Test
    fun test() {
        val deferredSupplier = spy(java.util.function.Supplier { Flux.empty<String>() })
        Flux.defer(deferredSupplier).blockLast()
        verify(deferredSupplier, times(1)).get()
    }

    @Test
    fun `test spy`() {
        val deferredSupplier = spy(java.util.function.Supplier { Flux.empty<String>() })
        Flux.defer(deferredSupplier).blockLast()
        verify(deferredSupplier, times(1)).get()
    }

The error message is:

Mockito cannot mock this class: class com.example.Test$test spy$deferredSupplier$1.
Can not mock final classes with the following settings :
 - explicit serialization (e.g. withSettings().serializable())
 - extra interfaces (e.g. withSettings().extraInterfaces(...))

You are seeing this disclaimer because Mockito is configured to create inlined mocks.

See https://github.com/MastaP/mockito-kotlin15-bug/actions/runs/1241073434 for details kotlin: 1.5.30 mockito-kotlin:3.2.0 mockito-inline:3.12.4