ShutdownHook { public boolean register(final Handler handler) { if (handler == null) { throw new IllegalArgumentException("Handler may not be null."); } try { final Optional<Consumer<ReturnCode>> end = handler.get(); if (end.isPresent()) { stack.push(end.get()); return true; } else { return false; } } catch (final RuntimeException ex) { LOGGER.warn("Failed to register state handler.", ex); return false; } }  boolean register(final Handler handler); void execute(final ReturnCode result);  }
@Test void exceptionHandlingOnRegistration() { final ShutdownHook.Handler h = mock(ShutdownHook.Handler.class); doThrow(new IllegalStateException("Testing exception")).when(h) .get(); assertThat(new ShutdownHook().register(h)).isFalse(); }
@Test void nullHandler() { assertThatThrownBy(() -> new ShutdownHook().register(null)) .isInstanceOf(IllegalArgumentException.class); }