How to write junit test for graceful shutdown in spring boot

Viewed 703

I'm new to code coverage. I have started to write test cases for my spring boot application.

The below highlighted part in red, I'm unable to cover. Could you please suggest how to test these?

enter image description here

Here is my code.

@SpringBootApplication
public class ImsApplication extends SpringBootServletInitializer implements WebApplicationInitializer {


    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(ImsApplication.class);
    }

    public static void contextDestroyed(ConfigurableApplicationContext ctx) {
        int exitCode = SpringApplication.exit(ctx, new ExitCodeGenerator() {
            @Override
            public int getExitCode() {
                return 0;
            }
        });
        System.exit(exitCode);
    }

    public static void main(String[] args) {
        ConfigurableApplicationContext ctx = SpringApplication.run(ImsApplication.class, args);
        contextDestroyed(ctx);
    }
    

    public ImsApplication() {
        super();
        setRegisterErrorPageFilter(false);
    }

    @PostConstruct
    public void init() {
        TimeZone.setDefault(TimeZone.getTimeZone("IST"));
    }
}
0 Answers
Related