### Question:
WaarpShutdownHook extends Thread { public static void addShutdownHook() { if (shutdownHook != null) { Runtime.getRuntime().addShutdownHook(shutdownHook); } } protected  WaarpShutdownHook(final ShutdownConfiguration configuration); ShutdownConfiguration getShutdownConfiguration(); static void addShutdownHook(); static boolean isInShutdown(); static boolean isShutdownStarting(); static void shutdownWillStart(); static void terminate(final boolean immediateSet); static void removeShutdownHook(); static boolean isRestart(); void launchFinalExit(); static void setRestart(final boolean toRestart); static void registerMain(final Class<?> main, final String[] args); @Override void run(); static WaarpShutdownHook shutdownHook; }### Answer:
@Test public void addShutdownHook() throws InterruptedException { WaarpShutdownHook.shutdownHook = new WaarpShutdownHookForTest(new ShutdownConfiguration()); WaarpShutdownHook.addShutdownHook(); assertNotNull(WaarpShutdownHook.shutdownHook); assertFalse(WaarpShutdownHook.isInShutdown()); assertFalse(WaarpShutdownHook.isShutdownStarting()); assertFalse(WaarpShutdownHook.isRestart()); WaarpShutdownHook.setRestart(true); assertTrue(WaarpShutdownHook.isRestart()); WaarpShutdownHook.setRestart(false); assertFalse(WaarpShutdownHook.isRestart()); WaarpShutdownHook.registerMain(FileConvert.class, new String[0]); assertFalse(WaarpShutdownHook.isRestart()); WaarpShutdownHook.shutdownWillStart(); assertTrue(WaarpShutdownHook.isShutdownStarting()); WaarpShutdownHook.terminate(false); assertFalse(WaarpShutdownHook.isInShutdown()); assertNull(WaarpShutdownHook.shutdownHook); ShutdownConfiguration shutdownConfiguration = new ShutdownConfiguration(); shutdownConfiguration.timeout = 100; shutdownConfiguration.serviceFuture = new WaarpFuture(); WaarpShutdownHook.shutdownHook = new WaarpShutdownHookForTest(shutdownConfiguration); new WaarpShutdownHookForTest(shutdownConfiguration); WaarpShutdownHook.addShutdownHook(); assertNotNull(WaarpShutdownHook.shutdownHook); final Timer timer = new Timer("WaarpFinalExit", true); final ShutdownTimerTask timerTask = new ShutdownTimerTask(); timer.schedule(timerTask, 100); shutdownConfiguration.serviceFuture.awaitOrInterruptible(); assertFalse(WaarpShutdownHook.isInShutdown()); WaarpShutdownHook.terminate(true); assertFalse(WaarpShutdownHook.isInShutdown()); assertNull(WaarpShutdownHook.shutdownHook); shutdownConfiguration.timeout = 100; shutdownConfiguration.serviceFuture = new WaarpFuture(); WaarpShutdownHook.shutdownHook = new WaarpShutdownHookForTest(shutdownConfiguration); WaarpShutdownHook.addShutdownHook(); assertNotNull(WaarpShutdownHook.shutdownHook); assertFalse(WaarpShutdownHook.isInShutdown()); WaarpShutdownHook.shutdownHook.run(); assertFalse(WaarpShutdownHook.isInShutdown()); assertNull(WaarpShutdownHook.shutdownHook); }