### Question:
ExcelUtils { public static String replaceCellReferencesOfSameRow(String formula, int row, int newRow) { String rowAsText = Integer.toString(row); String patternString = "([A-Z]+)([0-9]+)"; Pattern pattern = Pattern.compile(patternString); Matcher matcher = pattern.matcher(formula); while(matcher.find()) { String cellRefRowAsText = matcher.group(2); if (cellRefRowAsText.equals(rowAsText)) { int start = matcher.start(2); int end = matcher.end(2); formula = formula.substring(0, start) + newRow + formula.substring(end); matcher = pattern.matcher(formula); } } return formula; } private  ExcelUtils(); static void copyRow(HSSFWorkbook workbook, HSSFSheet worksheet, int sourceRowNum, int destinationRowNum); static void save(HSSFWorkbook workBook, File outputFile); static String replaceCellReferencesOfSameRow(String formula, int row, int newRow);  }### Answer:
@Test public void replaceCellReferencesOfSameRow_replace_one_cell_ref() { Assert.assertEquals("YEAR(NOW())-YEAR(D6)", ExcelUtils.replaceCellReferencesOfSameRow("YEAR(NOW())-YEAR(D5)", 5, 6)); }
@Test public void replaceCellReferencesOfSameRow_replace_multiple_cell_refs() { Assert.assertEquals("D6-E6-G6-F4", ExcelUtils.replaceCellReferencesOfSameRow("D5-E5-G5-F4", 5, 6)); Assert.assertEquals("D5-E5-G80-F80", ExcelUtils.replaceCellReferencesOfSameRow("D5-E5-G4-F4", 4, 80)); Assert.assertEquals("D5-E5-G40-F40", ExcelUtils.replaceCellReferencesOfSameRow("D5-E5-G4-F4", 4, 40)); }
@Test public void replaceCellReferencesOfSameRow_replace_cell_refs_with_row_starting_with_the_same_value() { Assert.assertEquals("D50", ExcelUtils.replaceCellReferencesOfSameRow("D50", 5, 6)); }