@Test public void commitTest() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException, ComponentLookupException { SpreadsheetExporter exporter = new SpreadsheetExporter(); SpreadsheetExporter spy = spy(exporter); Sheet sheet = mock(Sheet.class); DataSection section = mock(DataSection.class); DataCell cell = mock(DataCell.class); DataCell[][] matrix = new DataCell[1][1]; matrix[0][0] = cell; InOrder order = inOrder(sheet, sheet); doNothing().when(spy).commitRows(eq(section), eq(sheet), any(Styler.class)); doReturn(0).when(section).getMaxX(); doReturn(0).when(section).getMaxY(); doReturn(matrix).when(section).getMatrix(); doReturn(1).when(cell).getMergeX(); Field field = ReflectionUtils.getField(ComponentManagerRegistry.class, "cmProvider"); boolean isAccessible = field.isAccessible(); try { field.setAccessible(true); @SuppressWarnings("unchecked") Provider<ComponentManager> cmp = mock(Provider.class); field.set(null, cmp); ComponentManager cm = mock(ComponentManager.class); when(cmp.get()).thenReturn(cm); TranslationManager tm = mock(TranslationManager.class); when(cm.getInstance(TranslationManager.class)).thenReturn(tm); } finally { field.setAccessible(isAccessible); } doReturn(DataToCellConverter.MAX_CHARACTERS_PER_LINE * 210 + 1).when(sheet).getColumnWidth(anyInt()); spy.commit(section, sheet); order.verify(sheet, atLeastOnce()).autoSizeColumn(anyInt()); verify(sheet, atLeastOnce()).setColumnWidth(anyInt(), anyInt()); order.verify(sheet).addMergedRegion(any(CellRangeAddress.class)); }
protected void commit(DataSection section, Sheet sheet) { DataCell[][] cells = section.getMatrix(); Styler styler = new Styler(); commitRows(section, sheet, styler); for (int col = 0; section.getMaxX() >= col; col++) { sheet.autoSizeColumn(col); int correctWidth = DataToCellConverter.MAX_CHARACTERS_PER_LINE * 210; if (sheet.getColumnWidth(col) > correctWidth) { sheet.setColumnWidth(col, correctWidth); } } for (Integer y = 0; y <= section.getMaxY(); y++) { for (Integer x = 0; x <= section.getMaxX(); x++) { DataCell dataCell = cells[x][y]; if (dataCell != null && dataCell.getMergeX() != null) { sheet.addMergedRegion(new CellRangeAddress(y, y, x, x + dataCell.getMergeX())); } } } }
SpreadsheetExporter { protected void commit(DataSection section, Sheet sheet) { DataCell[][] cells = section.getMatrix(); Styler styler = new Styler(); commitRows(section, sheet, styler); for (int col = 0; section.getMaxX() >= col; col++) { sheet.autoSizeColumn(col); int correctWidth = DataToCellConverter.MAX_CHARACTERS_PER_LINE * 210; if (sheet.getColumnWidth(col) > correctWidth) { sheet.setColumnWidth(col, correctWidth); } } for (Integer y = 0; y <= section.getMaxY(); y++) { for (Integer x = 0; x <= section.getMaxX(); x++) { DataCell dataCell = cells[x][y]; if (dataCell != null && dataCell.getMergeX() != null) { sheet.addMergedRegion(new CellRangeAddress(y, y, x, x + dataCell.getMergeX())); } } } } }
SpreadsheetExporter { protected void commit(DataSection section, Sheet sheet) { DataCell[][] cells = section.getMatrix(); Styler styler = new Styler(); commitRows(section, sheet, styler); for (int col = 0; section.getMaxX() >= col; col++) { sheet.autoSizeColumn(col); int correctWidth = DataToCellConverter.MAX_CHARACTERS_PER_LINE * 210; if (sheet.getColumnWidth(col) > correctWidth) { sheet.setColumnWidth(col, correctWidth); } } for (Integer y = 0; y <= section.getMaxY(); y++) { for (Integer x = 0; x <= section.getMaxX(); x++) { DataCell dataCell = cells[x][y]; if (dataCell != null && dataCell.getMergeX() != null) { sheet.addMergedRegion(new CellRangeAddress(y, y, x, x + dataCell.getMergeX())); } } } }  }
SpreadsheetExporter { protected void commit(DataSection section, Sheet sheet) { DataCell[][] cells = section.getMatrix(); Styler styler = new Styler(); commitRows(section, sheet, styler); for (int col = 0; section.getMaxX() >= col; col++) { sheet.autoSizeColumn(col); int correctWidth = DataToCellConverter.MAX_CHARACTERS_PER_LINE * 210; if (sheet.getColumnWidth(col) > correctWidth) { sheet.setColumnWidth(col, correctWidth); } } for (Integer y = 0; y <= section.getMaxY(); y++) { for (Integer x = 0; x <= section.getMaxX(); x++) { DataCell dataCell = cells[x][y]; if (dataCell != null && dataCell.getMergeX() != null) { sheet.addMergedRegion(new CellRangeAddress(y, y, x, x + dataCell.getMergeX())); } } } }  void export(String[] enabledFieldsArray, List<Patient> patients, OutputStream outputStream); }
SpreadsheetExporter { protected void commit(DataSection section, Sheet sheet) { DataCell[][] cells = section.getMatrix(); Styler styler = new Styler(); commitRows(section, sheet, styler); for (int col = 0; section.getMaxX() >= col; col++) { sheet.autoSizeColumn(col); int correctWidth = DataToCellConverter.MAX_CHARACTERS_PER_LINE * 210; if (sheet.getColumnWidth(col) > correctWidth) { sheet.setColumnWidth(col, correctWidth); } } for (Integer y = 0; y <= section.getMaxY(); y++) { for (Integer x = 0; x <= section.getMaxX(); x++) { DataCell dataCell = cells[x][y]; if (dataCell != null && dataCell.getMergeX() != null) { sheet.addMergedRegion(new CellRangeAddress(y, y, x, x + dataCell.getMergeX())); } } } }  void export(String[] enabledFieldsArray, List<Patient> patients, OutputStream outputStream);  }