@Test public void testWhenReportReady_complete() throws IOException, InterruptedException { ReportDownloader downloader = new ReportDownloader(reportService, 1); when(reportService.getReportJobStatus(Matchers.anyLong())) .thenReturn(ReportJobStatus.COMPLETED); ReportCallback callback = mock(ReportCallback.class); downloader.whenReportReady(callback).join(); Mockito.verify(callback).onSuccess(); }
public Thread whenReportReady(final ReportCallback callback) { Preconditions.checkNotNull(callback, "Report callback cannot be null."); Thread waitThread = new Thread("ReportUtils.whenReportReady " + reportJobId) { @Override public void run() { try { if (waitForReportReady()) { callback.onSuccess(); } else { callback.onFailure(); } } catch (RemoteException e) { callback.onException(e); } catch (InterruptedException e) { callback.onInterruption(); } catch (RuntimeException e) { callback.onException(e); } } }; waitThread.start(); return waitThread; }
ReportDownloader { public Thread whenReportReady(final ReportCallback callback) { Preconditions.checkNotNull(callback, "Report callback cannot be null."); Thread waitThread = new Thread("ReportUtils.whenReportReady " + reportJobId) { @Override public void run() { try { if (waitForReportReady()) { callback.onSuccess(); } else { callback.onFailure(); } } catch (RemoteException e) { callback.onException(e); } catch (InterruptedException e) { callback.onInterruption(); } catch (RuntimeException e) { callback.onException(e); } } }; waitThread.start(); return waitThread; } }
ReportDownloader { public Thread whenReportReady(final ReportCallback callback) { Preconditions.checkNotNull(callback, "Report callback cannot be null."); Thread waitThread = new Thread("ReportUtils.whenReportReady " + reportJobId) { @Override public void run() { try { if (waitForReportReady()) { callback.onSuccess(); } else { callback.onFailure(); } } catch (RemoteException e) { callback.onException(e); } catch (InterruptedException e) { callback.onInterruption(); } catch (RuntimeException e) { callback.onException(e); } } }; waitThread.start(); return waitThread; } ReportDownloader(ReportServiceInterface reportService, long reportJobId); @VisibleForTesting  ReportDownloader(ReportServiceInterface reportService, long reportJobId, Sleeper sleeper); }
ReportDownloader { public Thread whenReportReady(final ReportCallback callback) { Preconditions.checkNotNull(callback, "Report callback cannot be null."); Thread waitThread = new Thread("ReportUtils.whenReportReady " + reportJobId) { @Override public void run() { try { if (waitForReportReady()) { callback.onSuccess(); } else { callback.onFailure(); } } catch (RemoteException e) { callback.onException(e); } catch (InterruptedException e) { callback.onInterruption(); } catch (RuntimeException e) { callback.onException(e); } } }; waitThread.start(); return waitThread; } 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); }
ReportDownloader { public Thread whenReportReady(final ReportCallback callback) { Preconditions.checkNotNull(callback, "Report callback cannot be null."); Thread waitThread = new Thread("ReportUtils.whenReportReady " + reportJobId) { @Override public void run() { try { if (waitForReportReady()) { callback.onSuccess(); } else { callback.onFailure(); } } catch (RemoteException e) { callback.onException(e); } catch (InterruptedException e) { callback.onInterruption(); } catch (RuntimeException e) { callback.onException(e); } } }; waitThread.start(); return waitThread; } 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; }