### Question:
ComponentStarter { public static CompletableFuture<Void> startComponent(LifecycleComponent component) { CompletableFuture<Void> future = new CompletableFuture<>(); final Thread shutdownHookThread = new Thread( new ComponentShutdownHook(component, future), "component-shutdown-thread" ); Runtime.getRuntime().addShutdownHook(shutdownHookThread); component.setExceptionHandler((t, e) -> { log.error("Triggered exceptionHandler of Component: {} because of Exception in Thread: {}", component.getName(), t, e); shutdownHookThread.start(); }); component.publishInfo(new ComponentInfoPublisher()); log.info("Starting component {}.", component.getName()); component.start(); log.info("Started component {}.", component.getName()); return future; }  static CompletableFuture<Void> startComponent(LifecycleComponent component);  }### Answer:
@Test public void testStartComponent() { LifecycleComponent component = mock(LifecycleComponent.class); when(component.getName()).thenReturn("test-start-component"); ComponentStarter.startComponent(component); verify(component).publishInfo(any(ComponentInfoPublisher.class)); verify(component).start(); }
@Test public void testExceptionHandler() throws Exception { LifecycleComponent component = mock(LifecycleComponent.class); when(component.getName()).thenReturn("test-exception-handler"); AtomicReference<UncaughtExceptionHandler> exceptionHandlerRef = new AtomicReference<>(); doAnswer(invocationOnMock -> { UncaughtExceptionHandler handler = invocationOnMock.getArgument(0); exceptionHandlerRef.set(handler); return null; }).when(component).setExceptionHandler(any(UncaughtExceptionHandler.class)); CompletableFuture<Void> startFuture = ComponentStarter.startComponent(component); verify(component, times(1)).start(); verify(component, times(1)).setExceptionHandler(eq(exceptionHandlerRef.get())); exceptionHandlerRef.get().uncaughtException( Thread.currentThread(), new Exception("test-exception-handler")); startFuture.get(); verify(component, times(1)).close(); }