### Question:
IndexingApplication extends Application<IndexingApplication.ApplicationHelper, IndexingConnectorContext> { @Override protected void shutDown() throws Exception { logger.log(Level.INFO, "Shutdown Indexing service"); if ((indexingService != null) && indexingService.isRunning()) { indexingService.stopAsync().awaitTerminated(); } super.shutDown(); } private  IndexingApplication(Builder builder);  @Deprecated static final String LOCAL_SCHEMA; }### Answer:
@Test public void createApplicationAndFullConnectorLifecycle() throws Exception { IndexingApplication subject = new IndexingApplication.Builder(mockConnector, new String[] {}) .setIndexingService(mockIndexingService) .setHelper(mockHelper) .build(); doAnswer( invocation -> { mockConnector.traverse(); return mockTraverser; }) .when(mockTraverser) .start(); subject.start(); InOrder inOrder = inOrder(mockConnector); inOrder.verify(mockConnector).init(mockContext); inOrder.verify(mockConnector).traverse(); subject.shutdown("From Test"); inOrder.verify(mockConnector).destroy(); }
@Test public void startAndStopFromTraverser() throws Exception { IndexingApplication subject = new IndexingApplication.Builder(mockConnector, new String[] {}) .setIndexingService(mockIndexingService) .setHelper(mockHelper) .build(); SettableFuture<ShutdownHolder> function = SettableFuture.create(); Mockito.when(mockTraverserBuilder.setShutdownHolder(any())) .thenAnswer(invocation -> { Object[] args = invocation.getArguments(); function.set((ShutdownHolder) args[0]); return mockTraverserBuilder; }); subject.start(); function.get(1L, TimeUnit.SECONDS).shutdown(); verify(mockShutdownThread).start(); }
@Test public void shutdownWithNotRunningTraverser() throws InterruptedException { when(mockTraverser.isStarted()).thenReturn(false); IndexingApplication subject = new IndexingApplication.Builder(mockConnector, new String[] {}) .setIndexingService(mockIndexingService) .setHelper(mockHelper) .build(); subject.start(); subject.shutdown("TestEvent"); InOrder inOrder = inOrder(spyLogger, mockTraverser, mockConnector); inOrder.verify(spyLogger).log(eq(Level.INFO), any(), anyString()); inOrder.verify(mockTraverser).isStarted(); inOrder.verify(mockConnector).destroy(); }
@Test public void shutdownWithRunningTraverser() throws InterruptedException { when(mockTraverser.isStarted()).thenReturn(true); IndexingApplication subject = new IndexingApplication.Builder(mockConnector, new String[] {}) .setIndexingService(mockIndexingService) .setHelper(mockHelper) .build(); subject.start(); subject.shutdown("TestEvent"); InOrder inOrder = inOrder(spyLogger, mockTraverser, mockConnector); inOrder.verify(spyLogger).log(eq(Level.INFO), any(), anyString()); inOrder.verify(mockTraverser).isStarted(); inOrder.verify(mockTraverser).stop(); inOrder.verify(mockConnector).destroy(); }
@Test public void shutdownHookTaskShouldCallShutdown() { ShutdownHook shutdownHook = mockApplication.new ShutdownHook(); shutdownHook.run(); verify(mockApplication).shutdown(any()); }