ExcelFileDefault implements ExcelFile { @Override public Workbook createWorkbook() { if (objects.isEmpty()) { final ExcelSheet excelSheet = new ExcelSheetDefault(this.workbook, this.translateService, "no data"); excelSheet.emptySheet(); } else { final Class clazz = this.objects.get(0).getClass(); final ExcelSheet excelSheet = new ExcelSheetDefault(this.workbook, this.translateService, clazz.getSimpleName().toLowerCase()); excelSheet.writeSheet(clazz, objects); } return workbook; } ExcelFileDefault(final List<Object> objects, final TranslateService translateService); @Override Workbook createWorkbook();  }
@Test public void createWorkbook() throws Exception { final ExcelFile excelFile = new ExcelFileDefault(createObjects(), new TestTranslateService()); final Workbook workbook = excelFile.createWorkbook(); Assert.assertEquals("Number of sheets", 3, workbook.getNumberOfSheets()); Assert.assertNotNull("buyer sheet", workbook.getSheet("testbuyer")); Assert.assertNotNull("contract sheet", workbook.getSheet("testcontract")); Assert.assertNotNull("document sheet", workbook.getSheet("testdocument")); Assert.assertEquals("buyer name", "buyer 1", workbook.getSheet("testbuyer").getRow(1).getCell(0).toString()); Assert.assertEquals("buyer classification", "TP-1 - alii aliquam", workbook.getSheet("testbuyer").getRow(2).getCell(8).toString()); Assert.assertEquals("contract parent", "testbuyer - 1", workbook.getSheet("testcontract").getRow(1).getCell(0).toString()); Assert.assertEquals("contract amount", 1000, workbook.getSheet("testcontract").getRow(1).getCell(2).getNumericCellValue(), 0.0); Assert.assertEquals("document number of rows", 2, workbook.getSheet("testdocument").getLastRowNum()); Assert.assertEquals("buyer address flatten", "Street 1 | Street 2", workbook.getSheet("testbuyer").getRow(1).getCell(4).toString()); }