Trying to write a mockito test for the below service code:
.build()
.post()
.uri(fullURL + queryPart )
.contentType(MediaType.MULTIPART_FORM_DATA)
.headers(headers -> headers.set("Authorization",token))
.body(BodyInserters.fromMultipartData(parts))
.exchange()
.flatMap(clientResponse -> clientResponse.bodyToMono(String.class))
.flux()
.blockFirst();```
Mockito code fails for Java language null pointer exception at exchange (last line in the below code)..
```when(webClientBuilder.build()).thenReturn(webClient);
when(webClient.post()).thenReturn(requestBodyUriSpec);
when(requestBodyUriSpec.uri(anyString())).thenReturn(requestBodySpec);
when(requestBodySpec.contentType(any(MediaType.class))).thenReturn(requestBodySpec);
when(requestBodySpec.headers(any())).thenReturn(requestBodySpec);
when(requestBodySpec.body(any())).thenReturn(requestHeadersSpec);
when(requestBodySpec.exchange().flatMap(any()).flux().blockFirst()).thenReturn(clientResponse.bodyToMono(String.class));
Any input will be appreciated..
Aucun commentaire:
Enregistrer un commentaire