Kotlin mock无法与构造函数签名匹配

Kotlin mock无法与构造函数签名匹配,kotlin,mockk,Kotlin,Mockk,我正在实现一个在Elasticsearch中从索引中删除别名的方法。为了验证该方法是否使用所需参数执行对Elasticsearch的请求,我正在使用mockK库编写一个单元测试。但是,org.apache.http.nio.entity.NStringEntity类构造函数签名在单元测试中不匹配,即使只有一个这样的构造函数(public NStringEntity(final String s,final ContentType ContentType))。有没有办法解决这个问题 方法如下:

我正在实现一个在Elasticsearch中从索引中删除别名的方法。为了验证该方法是否使用所需参数执行对Elasticsearch的请求,我正在使用mockK库编写一个单元测试。但是,
org.apache.http.nio.entity.NStringEntity
类构造函数签名在单元测试中不匹配,即使只有一个这样的构造函数(
public NStringEntity(final String s,final ContentType ContentType)
)。有没有办法解决这个问题

方法如下:

    override fun removeFromIndex(context: IndexContext, providedAliases: List<String>?) {
        val aliasesToRemove = providedAliases ?: getByIndex(context)
        val params: Map<String, String> = emptyMap()

        for (alias in aliasesToRemove) {
            val jsonString = IndexToAliasModel(context.index, alias).toJSONString("remove")
            val entity = NStringEntity(jsonString, ContentType.APPLICATION_JSON)
            esClientConf[context.cluster].performRequest("POST", "_aliases/", params, entity)
        }
    }
esClientConf[context.cluster]
返回弹性搜索
RestClient
实例。)

    @Test
    fun `Removing aliases of an index performs a request`() {
        val context = IndexContext(ElasticsearchCluster.AUX, index="dummyIndex")
        val providedAliases = listOf("dummyAlias1")
        val esResponse = mockk<Response>()

        mockkConstructor(NStringEntity::class)
        val nStringEntity = mockk<NStringEntity>()
        every { NStringEntity(any(), ContentType.APPLICATION_JSON) } returns nStringEntity
        every { esClientConf[ElasticsearchCluster.AUX].performRequest(any(), any(), emptyMap<String, String>(), nStringEntity) } returns esResponse

        esAliasService.removeFromIndex(context, providedAliases)

        verify { esClientConf[ElasticsearchCluster.AUX].performRequest("POST", "_aliases/", emptyMap<String, String>(), nStringEntity) }
    }
io.mockk.MockKException: Failed matching mocking signature for

left matchers: [any()]

    at io.mockk.impl.recording.SignatureMatcherDetector.detect(SignatureMatcherDetector.kt:99)
    at io.mockk.impl.recording.states.RecordingState.signMatchers(RecordingState.kt:39)
    at io.mockk.impl.recording.states.RecordingState.round(RecordingState.kt:31)
    at io.mockk.impl.recording.CommonCallRecorder.round(CommonCallRecorder.kt:50)
    at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:59)
    at io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:30)
    at io.mockk.MockKDsl.internalEvery(API.kt:92)
    at io.mockk.MockKKt.every(MockK.kt:104)