Mono.doOnError () блок-тест блока реактора - PullRequest
0 голосов
/ 04 апреля 2019

У меня есть контроллер покоя, использующий пружинный webflux и реактор, я пишу юнит-тест для контроллера.Ниже приведены фрагменты кода и помогите мне написать метод модульного тестирования для проверки блока .doOnError.

Я попытался вызвать исключение с помощью Mockito

doThrow (CriticalException.class).when (myService) .myMethod (объект);

This is my unit test


StepVerifier.create(
Mono.just(
                webTestClient.post() 
                       .uri("/endpoint")
                       .accept(MediaType.APPLICATION_JSON) 


                       .body(BodyInserters.fromObject(requestJson)) //Set the body of the request to the given synchronous Object
                                            //Returns:a Mono with the response
        //Act
                       .exchange()  //Perform the exchange 
        //Assert        
                       .expectStatus().isOk() 
                       .expectBody(Agreement.class)
                       .returnResult()
                       .getResponseBody()))
                .expectNextMatches(agreementResponse -> {
                        assertNotNull(agreementResponse.getAgreementParticipant());
                        return true; 
                }) 
                .expectComplete()
                .verify();

Это мой контроллер

return Mono.fromCallable(() -> { 
            myService.myMethod(object);
            return object;
        }).log().subscribeOn(Schedulers.elastic())
                .map(p -> ResponseEntity.ok(p))
                .defaultIfEmpty(ResponseEntity.notFound().build())
                .doOnError(e -> { 
                    LOGGER.error(LOG_FORMAT, e.getMessage(), e.getStackTrace());                
                }); 


Mockito is not returning exception while myService.myMethod(object) is been called.
Please suggest proper way to write test for .defaultIfEmpty and .doOnError blocks
...