首页 > 解决方案 > Kotlin Mock Fuel HTTP 响应使用 Mockito

问题描述

我正在尝试使用 Mockito 模拟 Fuel HTTP 响应,如下所示:

val client = mock<Client> {
  on { executeRequest(any()) } doReturn Response(
    statusCode = 200,
    responseMessage = response,
    url = URL("https://www.mydomain.test")
    )
  }

但是,我遇到了反序列化的问题:

Error while communicating with x: No content to map due to end-of-input
 at [Source: (BufferedInputStream); line: 1, column: 0]
java.lang.RuntimeException: Error while communicating with x: No content to map due to end-of-input
 at [Source: (BufferedInputStream); line: 1, column: 0]

我已将 responseMessage 设置为非空字符串,因此不确定为什么会发生这种情况。我正在使用 Fuel 版本 > 2.0。

标签: kotlinmockitofuel

解决方案


推荐阅读