SafeShutdown { public static void exit(ExitCode statusCode, @Nullable PreSystemExitHook hook) { flagStopping(); try { if (hook != null) { hook.run(); } } finally { Logger.getLogger(SafeShutdown.class.getName()).info("Exiting GRIP"); System.exit(statusCode.getCode()); } } private  SafeShutdown(); static void exit(ExitCode statusCode, @Nullable PreSystemExitHook hook); static void exit(ExitCode statusCode); static boolean isStopping(); static void flagStopping(); static volatile boolean stopping; }
@Test public void testSafeShutdownShutsDownIfHandlerThrowsError() throws Exception { try { SafeShutdown.exit(SafeShutdown.ExitCode.SAFE_SHUTDOWN, () -> { throw new AssertionError("This should not be the exception that appears"); }); } catch (IllegalStateException e) { assertThat(e).hasMessageThat().contains(SHUTDOWN_EXCEPTION_MESSAGE); } }