I want to make sure that the Spring Boot WebFlux jUnit test passes through onErrorResume()

Asked 5 months ago, Updated 5 months ago, 23 views

Thank you for your continuous support.

I would like to confirm that the Spring Boot WebFlux jUnit test passes through onErrorResume().
When Exception occurs, the jUnit test stops and the path cannot be verified.
Please let me know if there are any necessary items such as settings.

when Runtime Exception occurs in repository.hello() I would like to confirm that the onResumeError is handling exceptions (logs are printed).

public class HealthCheckHandlerTest{

    private HealthCheckHandler;

    private repository repository;

    public void setUp(){
        // Generating a Test Instance
        handler = new HealthCheckHandler(repository);        

    @ Test
    Error in public void testHandleHealthMonitoring anomaly system 1_DB(){
        // preliminary preparation
        when(repository.hello()) .thenThrow(new RuntimeException("DB connection error"));

        // Running Tests
        Mono<ServerResponse>response=handler.handleHealthMonitoring (request);
  • Tested Class
public class HealthCheckHandler {

     * repository
    private final repository repository;

     * constructor
     * @param repository
    public HealthCheckHandler(
            Repository repository) {

     * handler
     * @param request
     * @return
    public finalMono<ServerResponse>handleHealthMonitoring (finalServerRequest request) {
        // Try calling postgre for now to see if there are any errors.
        // Hogehoge is omitted this time.
        return Mono.zip (hogehoge, postgreOpe).flatMap(r->{
            return ServerResponse
        }).timeout(Duration.ofSeconds(DURATION_TIME)) .onErrorResume(t->{
            logger.error("healthchecked for errors",t);
            return ServerResponse

At the end of the test code, an error stack of the "DB connection error" mock appears stacked when calling response.subscribe.The test is also considered a failure.The timing is right, but I would like you to continue processing...

Put java plugin and other sets into the vscode
* Key Plug-ins
* Maven for Java * Java Test Runner * Language Support for Java(TM) by Red Hat and so on.

spring-boot junit

2022-09-30 11:23

1 Answers

when(repository.hello()) .thenThrow(new RuntimeException("DB connection error"));

when(repository.hello()) .thenReturn(Mono.error(new RuntimeException("DB connection error"));

2022-09-30 11:23

If you have any answers or tips

© 2023 OneMinuteCode. All rights reserved.