### Question:
BrooklynShutdownHooks { public static void invokeTerminateOnShutdown(ManagementContext managementContext) { try { semaphore.acquire(); if (isShutDown.get()) { semaphore.release(); try { log.warn("Call to invokeStopOnShutdown for "+managementContext+" while system already shutting down; invoking stop now and throwing exception"); ((ManagementContextInternal)managementContext).terminate(); throw new IllegalStateException("Call to invokeTerminateOnShutdown for "+managementContext+" while system already shutting down"); } catch (Exception e) { throw new IllegalStateException("Call to invokeTerminateOnShutdown for "+managementContext+" while system already shutting down, had error: "+e, e); } } managementContextsToTerminateOnShutdown.add(managementContext); semaphore.release(); addShutdownHookIfNotAlready(); } catch (Exception e) { throw Exceptions.propagate(e); } }  static void setShutdownTimeout(Duration val); static void invokeStopOnShutdown(Entity entity); static void invokeStopAppsOnShutdown(ManagementContext managementContext); static void invokeTerminateOnShutdown(ManagementContext managementContext);  }### Answer:
@Test public void testInvokeTerminateManagementContextOnShutdown() throws Exception { BrooklynShutdownHooks.invokeTerminateOnShutdown(mgmt); BrooklynShutdownHooks.BrooklynShutdownHookJob job = BrooklynShutdownHookJob.newInstanceForTesting(); job.run(); assertFalse(mgmt.isRunning()); }