### Question:
RetryReportExecution extends ReportExecution { @NotNull @Override public ReportExport export(@NotNull ReportExportOptions options) throws ServiceException { try { return mDelegate.export(options); } catch (ServiceException ex) { boolean isCancelled = (ex.code() == StatusCodes.EXPORT_EXECUTION_CANCELLED || ex.code() == StatusCodes.REPORT_EXECUTION_CANCELLED); if (isCancelled) { return mDelegate.export(options); } throw ex; } } RetryReportExecution(ReportExecution delegate); @NotNull @Override ReportExport export(@NotNull ReportExportOptions options); @NotNull @Override ReportMetadata waitForReportCompletion(); @NotNull @Override ReportExecution updateExecution(@Nullable List<ReportParameter> newParameters); @NotNull @Override String getExecutionId();  }### Answer:
@Test public void should_retry_export_if_cancelled_on_first_run() throws Exception { when(mDelegate.export(any(ReportExportOptions.class))).then(crashOnFirstRun()); reportExecution.export(EXPORT_CRITERIA); verify(mDelegate, times(2)).export(EXPORT_CRITERIA); }
@Test(expected = ServiceException.class) public void should_throw_if_cancelled_on_second_run() throws Exception { when(mDelegate.export(any(ReportExportOptions.class))).thenThrow(CANCELLED_EXCEPTION); reportExecution.export(EXPORT_CRITERIA); }