### Question:
ReportDownloader { public boolean waitForReportReady() throws RemoteException, InterruptedException { ReportJobStatus status = reportService.getReportJobStatus(reportJobId); while (status == ReportJobStatus.IN_PROGRESS) { sleeper.sleep(SLEEP_TIMER); status = reportService.getReportJobStatus(reportJobId); } return status == ReportJobStatus.COMPLETED; } ReportDownloader(ReportServiceInterface reportService, long reportJobId); @VisibleForTesting  ReportDownloader(ReportServiceInterface reportService, long reportJobId, Sleeper sleeper); Thread whenReportReady(final ReportCallback callback); boolean waitForReportReady(); URL getDownloadUrl(ReportDownloadOptions options); CharSource getReportAsCharSource(ReportDownloadOptions options); static final Charset REPORT_CHARSET; static final int SLEEP_TIMER; }### Answer:
@Test public void testWaitForReportReady_completed() throws ApiException, RemoteException, InterruptedException { ReportDownloader downloader = new ReportDownloader(reportService, 1); when(reportService.getReportJobStatus(Matchers.anyLong())) .thenReturn(ReportJobStatus.COMPLETED); assertTrue(downloader.waitForReportReady()); }
@Test public void testWaitForReportReady_failed() throws ApiException, RemoteException, InterruptedException { ReportDownloader downloader = new ReportDownloader(reportService, 1); when(reportService.getReportJobStatus(Matchers.anyLong())).thenReturn(ReportJobStatus.FAILED); assertFalse(downloader.waitForReportReady()); }
@Test public void testWaitForReportReady_polls() throws ApiException, RemoteException, InterruptedException { Sleeper sleeper = mock(Sleeper.class); ReportDownloader downloader = new ReportDownloader(reportService, 1, sleeper); when(reportService.getReportJobStatus(Matchers.anyLong())) .thenReturn(ReportJobStatus.IN_PROGRESS, ReportJobStatus.COMPLETED); assertTrue(downloader.waitForReportReady()); }