LifecycleManager extends AbstractLifecycle { public Lifecycle addStartupTask(Runnable startupTask) { Lifecycle lifecycle = new Lifecycle() { @Override public void startup() { startupTask.run(); } @Override public void shutdown() {} }; addLifecycle(lifecycle); return lifecycle; } LifecycleManager();  LifecycleManager(ShutdownOrder shutdownOrder); void addLifecycle(Lifecycle lifecycle); void removeLifecycle(Lifecycle lifecycle); Lifecycle addStartupTask(Runnable startupTask); Lifecycle addShutdownTask(Runnable shutdownTask);  }
@Test public void testStartupOrder() { LifecycleManager manager = new LifecycleManager(); AtomicInteger i = new AtomicInteger(0); manager.addStartupTask(() -> assertEquals(i.getAndIncrement(), 0)); manager.addStartupTask(() -> assertEquals(i.getAndIncrement(), 1)); manager.addStartupTask(() -> assertEquals(i.getAndIncrement(), 2)); manager.startup(); manager.shutdown(); }