SystemManager { public void stopServices() throws ConflictException { if (!statusRef.compareAndSet(RUNNING, PREPARING_TO_SHUTDOWN)) { throw new ConflictException( "System shutdown has been already called, system status: " + statusRef.get()); } ExecutorService exec = Executors.newSingleThreadExecutor( new ThreadFactoryBuilder() .setDaemon(false) .setNameFormat("ShutdownSystemServicesPool") .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()) .build()); exec.execute(ThreadLocalPropagateContext.wrap(this::doStopServices)); exec.shutdown(); } @Inject  SystemManager(
      ServiceTerminator terminator, DBTermination dbTermination, EventService eventService); void stopServices(); void suspendServices(); SystemStatus getSystemStatus();  }
@Test public void servicesAreStopped() throws Exception { systemManager.stopServices(); verifyShutdownCompleted(); }
@Test(expectedExceptions = ConflictException.class) public void exceptionIsThrownWhenStoppingServicesTwice() throws Exception { systemManager.stopServices(); systemManager.stopServices(); }