### Question:
Application extends AbstractIdleService { public void start() throws InterruptedException { startAsync().awaitRunning(); } protected  Application(AbstractBuilder<? extends AbstractBuilder, H, T> builder); void start(); synchronized void shutdown(String event); @VisibleForTesting static void setLogger(Logger logger); static final String INCREMENTAL_INTERVAL_SECONDS; static final String TRAVERSE_ON_START; static final String POLL_INTERVAL_SECONDS; static final String TRAVERSE_INTERVAL_SECONDS; static final String RUN_ONCE; }### Answer:
@Test public void startShouldSucceedWhenNoFurtherExceptionOccursAfterRetry() throws Exception { IOException ex = new IOException(); doThrow(ex).doNothing().when(mockConnector).init(mockContext); when(mockHelper.getDefaultExceptionHandler()).thenReturn(mockExceptionHandler); when(mockExceptionHandler.handleException(ex, 1)).thenReturn(true); Application subject = new Application.Builder(mockConnector, new String[] {}) .setHelper(mockHelper) .build(); subject.start(); InOrder inOrder = inOrder( mockExceptionHandler, mockHelper, mockTraverserBuilder, mockTraverser); inOrder.verify(mockHelper).createShutdownHookThread(any(ShutdownHook.class)); inOrder.verify(mockExceptionHandler).handleException(ex, 1); inOrder.verify(mockHelper).createSchedulerBuilderInstance(); inOrder.verify(mockTraverserBuilder).setConnector(eq(mockConnector)); inOrder.verify(mockTraverserBuilder).setContext(eq(mockContext)); inOrder.verify(mockTraverserBuilder).setShutdownHolder(any()); inOrder.verify(mockTraverser).start(); inOrder.verifyNoMoreInteractions(); }
@Test public void startSuccessful() throws Exception { Application subject = new Application.Builder(mockConnector, new String[] {}) .setHelper(mockHelper) .build(); subject.start(); InOrder inOrder = inOrder(mockRuntime, mockHelper, mockTraverserBuilder, mockTraverser); inOrder.verify(mockHelper).createShutdownHookThread(any(ShutdownHook.class)); inOrder.verify(mockHelper).getRuntimeInstance(); inOrder.verify(mockRuntime).addShutdownHook(mockShutdownThread); inOrder.verify(mockHelper).createContextBuilderInstance(); inOrder.verify(mockHelper).createSchedulerBuilderInstance(); inOrder.verify(mockTraverserBuilder).setConnector(eq(mockConnector)); inOrder.verify(mockTraverserBuilder).setContext(eq(mockContext)); inOrder.verify(mockTraverserBuilder).setShutdownHolder(any()); inOrder.verify(mockTraverser).start(); inOrder.verifyNoMoreInteractions(); }
@Test public void multipleStarts() throws Exception { Application subject = new Application.Builder(mockConnector, new String[] {}) .setHelper(mockHelper) .build(); subject.start(); thrown.expect(IllegalStateException.class); subject.start(); }