PivotUtils { static Cell addCellValueTo(Cell source, Cell target){ if (source == null) { return target; } if (target.getCellType()==CellType.NUMERIC && source.getCellType()==CellType.NUMERIC ){ double val1 = target.getNumericCellValue(); double val2 = source.getNumericCellValue(); target.setCellValue(val1+val2); } return target; }  static void createAnnotationRow(final Row annotationRow, final List<String> annotationList); static void createOrderRow(final Row orderRow, final List<Integer> orderList); static void createTypeRow(final Row typeRow, final List<AggregationType> typeList);  }
@Test public void addCellValueToTest(){ XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet(); Row r = sheet.createRow(0); Cell cSource = null; Cell cTarget = r.createCell(1); cTarget.setCellValue(1); PivotUtils.addCellValueTo(cSource, cTarget); Assertions.assertThat(cTarget.getNumericCellValue()).isEqualTo(1); cSource = r.createCell(0); cTarget = r.createCell(1); cSource.setCellValue(1); cTarget.setCellValue(2); PivotUtils.addCellValueTo(cSource, cTarget); Assertions.assertThat(cTarget.getNumericCellValue()).isEqualTo(3); cSource.setCellValue(1); cTarget.setCellValue("b"); PivotUtils.addCellValueTo(cSource, cTarget); Assertions.assertThat(cTarget.getStringCellValue()).isEqualTo("b"); cSource.setCellValue(true); cTarget.setCellValue(false); PivotUtils.addCellValueTo(cSource, cTarget); Assertions.assertThat(cTarget.getBooleanCellValue()).isEqualTo(false); }