### Question:
PreviewRunnerService extends AbstractExecutionThreadService { private void stopPreview(PreviewRequest request) { try { previewRunner.stopPreview(request.getProgram()); } catch (Exception e) { LOG.error("Failed to stop preview for {}", request.getProgram(), e); } } @Inject  PreviewRunnerService(CConfiguration cConf, PreviewRequestFetcher previewRequestFetcher,
                       @Assisted PreviewRunner previewRunner); Optional<ApplicationId> getPreviewApplication();  }### Answer:
@Test public void testStopPreview() throws InterruptedException, ExecutionException, TimeoutException { MockPreviewRunner mockRunner = new MockPreviewRunner(); MockPreviewRequestFetcher fetcher = new MockPreviewRequestFetcher(); PreviewRunnerService runnerService = new PreviewRunnerService(createCConf(), fetcher, mockRunner); runnerService.startAndWait(); ProgramId programId = NamespaceId.DEFAULT.app("app").program(ProgramType.WORKFLOW, "workflow"); fetcher.addRequest(new PreviewRequest(programId, null)); Tasks.waitFor(true, () -> mockRunner.requests.get(programId) != null, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); runnerService.stopAndWait(); Tasks.waitFor(PreviewStatus.Status.KILLED, () -> mockRunner.requests.get(programId).status.getStatus(), 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); Tasks.waitFor(Service.State.TERMINATED, runnerService::state, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); }