TimesheetExcelExport implements ExcelReport { @Override public void write(OutputStream stream) throws IOException { ExcelExportReportModel report = new ExcelExportReportModel(reportCriteria); ExcelWorkbook workbook = createWorkbook(report); workbook.write(stream); } TimesheetExcelExport(ReportCriteria reportCriteria); @Override void write(OutputStream stream); @Override String getFilenameWihoutSuffix();  }
@Test public void produceExcelReport() throws IOException { List<FlatReportElement> elements = SkinConfigPanel.TimesheetExportDummyDataGenerator.createMonthData(getConfig()); ReportData data = new ReportData(elements, SkinConfigPanel.TimesheetExportDummyDataGenerator.getDateRangeForCurrentMonth(), new UserSelectedCriteria()); UserSelectedCriteria userSelectedCriteria = new UserSelectedCriteria(); userSelectedCriteria.getCustomParameters().put(TimesheetExportParameter.INCL_SIGN_OFF.name(), Boolean.TRUE); userSelectedCriteria.setReportRange(SkinConfigPanel.TimesheetExportDummyDataGenerator.getDateRangeForCurrentMonth()); ReportCriteria criteria = new ReportCriteria(userSelectedCriteria); when(detailedReportService.getDetailedReportData(criteria)).thenReturn(data); ByteArrayOutputStream stream = new ByteArrayOutputStream(); new TimesheetExcelExport(criteria).write(stream); byte[] excelData = stream.toByteArray(); assertTrue(excelData.length > 0); }
@Test public void produceForEmptyMonth() throws IOException { List<FlatReportElement> elements = new ArrayList<>(); ReportData data = new ReportData(elements, DateUtil.getDateRangeForMonth(new Date()), new UserSelectedCriteria()); UserSelectedCriteria userSelectedCriteria = new UserSelectedCriteria(); userSelectedCriteria.setReportRange(SkinConfigPanel.TimesheetExportDummyDataGenerator.getDateRangeForCurrentMonth()); ReportCriteria criteria = new ReportCriteria(userSelectedCriteria); when(detailedReportService.getDetailedReportData(criteria)).thenReturn(data); ByteArrayOutputStream stream = new ByteArrayOutputStream(); new TimesheetExcelExport(criteria).write(stream); byte[] excelData = stream.toByteArray(); assertTrue(excelData.length > 0); }