我试着嘲笑.头,但它不起作用,有人知道吗



我试着用when(requestHeadersSpec.header(notNull((,notNull;,或者类似的东西,但我不工作,有人有想法吗?

return defaultWebClient
.get()
.uri(some uri)
.headers(httpHeaders -> httpHeaders.set("Content-Type", "application/pdf"))
.retrieve()
.bodyToFlux(DataBuffer.class)

}

这就是我试图编写单元测试的方式when(defaultWebClient.get(((.thenReturn(requestHeadersUriSpec(;doReturn(requestHeadersSpec(.when(requestHeadersUriSpec(.uri(anyString(((;Mockito.when(requestHeadersSpec.header(anyString((((.thenReturn(requestHeadersSpec(;when(requestHeadersSpec.reveive(((.thenReturn(responseSpec(;DefaultDataBufferFactory工厂=新的DefaultDataBufferFactory((;

DefaultDataBuffer dataBuffer =
factory.wrap(ByteBuffer.wrap("{"username":"foo","password":"bar"}".getBytes(StandardCharsets.UTF_8)));
when(responseSpec.bodyToFlux(DataBuffer.class))
.thenReturn(Flux.just(dataBuffer));

您可以尝试下面的

.withHeader(
HttpHeaders.ACCEPT, 
containing(org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
)

相关内容

  • 没有找到相关文章

最新更新