@Test public void extendVertically() throws Exception { DataSection section = mock(DataSection.class); StyleOption styleTop = StyleOption.SECTION_BORDER_LEFT; StyleOption styleBottom = StyleOption.SECTION_BORDER_RIGHT; DataCell cellTop = new DataCell("", 0, 0); DataCell cellTopSpy = spy(cellTop); DataCell cellMiddle = mock(DataCell.class); DataCell cellBottom = new DataCell("", 0, 0); DataCell cellBottomSpy = spy(cellBottom); DataCell[][] matrix = new DataCell[1][4]; Set<StyleOption> styleSet = new HashSet<>(); styleSet.add(styleBottom); matrix[0][0] = cellTopSpy; matrix[0][1] = cellMiddle; matrix[0][3] = cellBottomSpy; doReturn(matrix).when(section).getMatrix(); doReturn(0).when(section).getMaxX(); doReturn(3).when(section).getMaxY(); doReturn(styleSet).when(cellMiddle).getStyles(); Styler.extendStyleVertically(section, styleTop, styleBottom); verify(cellTopSpy, times(1)).addStyles(anySetOf(StyleOption.class)); verify(cellMiddle, times(1)).addStyles(anySetOf(StyleOption.class)); verify(cellBottomSpy, times(1)).addStyles(anySetOf(StyleOption.class)); Assert.assertTrue(cellBottomSpy.getStyles().contains(styleBottom)); Assert.assertTrue(cellTopSpy.getStyles().contains(styleBottom)); verify(section, times(1)).addCell(any(DataCell.class)); }
@SuppressWarnings({ "checkstyle:NPathComplexity", "checkstyle:CyclomaticComplexity" }) public static void extendStyleVertically(DataSection section, StyleOption... styles) throws Exception { DataCell[][] cellMatrix = section.getMatrix(); if (cellMatrix == null) { throw new Exception(NO_MATRIX_ERR_MSG); } for (int x = 0; x <= section.getMaxX(); x++) { Set<StyleOption> toExtend = new HashSet<>(); Boolean found = false; for (int y = 0; y <= section.getMaxY(); y++) { found = false; DataCell cell = cellMatrix[x][y]; if (cell == null) { continue; } for (StyleOption style : styles) { if (!cell.isChild() && cell.getStyles() != null && cell.getStyles().contains(style)) { toExtend.add(style); found = true; } } if (found) { break; } } if (!found) { continue; } for (int y = 0; y <= section.getMaxY(); y++) { DataCell cell = cellMatrix[x][y]; if (cell == null) { cell = new DataCell("", x, y); section.addCell(cell); } cell.addStyles(toExtend); } } }
Styler { @SuppressWarnings({ "checkstyle:NPathComplexity", "checkstyle:CyclomaticComplexity" }) public static void extendStyleVertically(DataSection section, StyleOption... styles) throws Exception { DataCell[][] cellMatrix = section.getMatrix(); if (cellMatrix == null) { throw new Exception(NO_MATRIX_ERR_MSG); } for (int x = 0; x <= section.getMaxX(); x++) { Set<StyleOption> toExtend = new HashSet<>(); Boolean found = false; for (int y = 0; y <= section.getMaxY(); y++) { found = false; DataCell cell = cellMatrix[x][y]; if (cell == null) { continue; } for (StyleOption style : styles) { if (!cell.isChild() && cell.getStyles() != null && cell.getStyles().contains(style)) { toExtend.add(style); found = true; } } if (found) { break; } } if (!found) { continue; } for (int y = 0; y <= section.getMaxY(); y++) { DataCell cell = cellMatrix[x][y]; if (cell == null) { cell = new DataCell("", x, y); section.addCell(cell); } cell.addStyles(toExtend); } } } }
Styler { @SuppressWarnings({ "checkstyle:NPathComplexity", "checkstyle:CyclomaticComplexity" }) public static void extendStyleVertically(DataSection section, StyleOption... styles) throws Exception { DataCell[][] cellMatrix = section.getMatrix(); if (cellMatrix == null) { throw new Exception(NO_MATRIX_ERR_MSG); } for (int x = 0; x <= section.getMaxX(); x++) { Set<StyleOption> toExtend = new HashSet<>(); Boolean found = false; for (int y = 0; y <= section.getMaxY(); y++) { found = false; DataCell cell = cellMatrix[x][y]; if (cell == null) { continue; } for (StyleOption style : styles) { if (!cell.isChild() && cell.getStyles() != null && cell.getStyles().contains(style)) { toExtend.add(style); found = true; } } if (found) { break; } } if (!found) { continue; } for (int y = 0; y <= section.getMaxY(); y++) { DataCell cell = cellMatrix[x][y]; if (cell == null) { cell = new DataCell("", x, y); section.addCell(cell); } cell.addStyles(toExtend); } } }  }
Styler { @SuppressWarnings({ "checkstyle:NPathComplexity", "checkstyle:CyclomaticComplexity" }) public static void extendStyleVertically(DataSection section, StyleOption... styles) throws Exception { DataCell[][] cellMatrix = section.getMatrix(); if (cellMatrix == null) { throw new Exception(NO_MATRIX_ERR_MSG); } for (int x = 0; x <= section.getMaxX(); x++) { Set<StyleOption> toExtend = new HashSet<>(); Boolean found = false; for (int y = 0; y <= section.getMaxY(); y++) { found = false; DataCell cell = cellMatrix[x][y]; if (cell == null) { continue; } for (StyleOption style : styles) { if (!cell.isChild() && cell.getStyles() != null && cell.getStyles().contains(style)) { toExtend.add(style); found = true; } } if (found) { break; } } if (!found) { continue; } for (int y = 0; y <= section.getMaxY(); y++) { DataCell cell = cellMatrix[x][y]; if (cell == null) { cell = new DataCell("", x, y); section.addCell(cell); } cell.addStyles(toExtend); } } }  static void disallowBodyStyles(DataSection section); static void styleSectionBottom(DataSection section, StyleOption style); static void styleSectionBorder(DataSection section, StyleOption styleLeft, StyleOption styleRight); @SuppressWarnings({ "checkstyle:NPathComplexity", "checkstyle:CyclomaticComplexity" }) static void extendStyleHorizontally(DataSection section, StyleOption... styles); @SuppressWarnings({ "checkstyle:NPathComplexity", "checkstyle:CyclomaticComplexity" }) static void extendStyleVertically(DataSection section, StyleOption... styles); void style(DataCell dataCell, Cell cell, Workbook wBook); }
Styler { @SuppressWarnings({ "checkstyle:NPathComplexity", "checkstyle:CyclomaticComplexity" }) public static void extendStyleVertically(DataSection section, StyleOption... styles) throws Exception { DataCell[][] cellMatrix = section.getMatrix(); if (cellMatrix == null) { throw new Exception(NO_MATRIX_ERR_MSG); } for (int x = 0; x <= section.getMaxX(); x++) { Set<StyleOption> toExtend = new HashSet<>(); Boolean found = false; for (int y = 0; y <= section.getMaxY(); y++) { found = false; DataCell cell = cellMatrix[x][y]; if (cell == null) { continue; } for (StyleOption style : styles) { if (!cell.isChild() && cell.getStyles() != null && cell.getStyles().contains(style)) { toExtend.add(style); found = true; } } if (found) { break; } } if (!found) { continue; } for (int y = 0; y <= section.getMaxY(); y++) { DataCell cell = cellMatrix[x][y]; if (cell == null) { cell = new DataCell("", x, y); section.addCell(cell); } cell.addStyles(toExtend); } } }  static void disallowBodyStyles(DataSection section); static void styleSectionBottom(DataSection section, StyleOption style); static void styleSectionBorder(DataSection section, StyleOption styleLeft, StyleOption styleRight); @SuppressWarnings({ "checkstyle:NPathComplexity", "checkstyle:CyclomaticComplexity" }) static void extendStyleHorizontally(DataSection section, StyleOption... styles); @SuppressWarnings({ "checkstyle:NPathComplexity", "checkstyle:CyclomaticComplexity" }) static void extendStyleVertically(DataSection section, StyleOption... styles); void style(DataCell dataCell, Cell cell, Workbook wBook);  }