### Question:
DiffMapper implements Function<RawDiff, Diff> { @Override public Diff apply(RawDiff rawDiff) { Diff diff = new Diff(); Optional<String> fileName = Optional.ofNullable(rawDiff.getFileName()).map(this::removeNewFilePrefix); log.info("parse diff / {}", fileName); if (!fileName.isPresent()) { log.error("diff parse fail"); rawDiff.getRawDiff().forEach(l -> log.error("{}", l)); return null; } diff.setFileName(fileName.get()); if (rawDiff.getType() == FileType.BINARY) { diff.setDiffSectionList(Collections.emptyList()); return diff; } Optional<List<DiffSection>> diffSectionList = getDiffSectionListFromRawDiff(rawDiff); if (!diffSectionList.isPresent()) { log.error("unexpected diff type {}", rawDiff); return null; } diff.setDiffSectionList(diffSectionList.get()); return diff; }  static DiffMapper getDefault(); @Override Diff apply(RawDiff rawDiff);  }### Answer:
@Test public void testSingleLineFix() { String testContent = "@@ -1 +1 @@\n-test\n\\\\ No newline at end of file\n+test1\n\\\\ No newline at end of file"; Diff test = mapper.apply(RawDiff.builder().fileName("test") .rawDiff(Arrays.asList(testContent.split("\n"))).build()); assertEquals(1, test.getDiffSectionList().size()); DiffSection diffSection = test.getDiffSectionList().get(0); List<Line> lineList = diffSection.getLineList(); assertEquals(2, lineList.size()); assertEquals("test", lineList.get(0).getBody()); assertEquals(ModifyType.DEL, lineList.get(0).getType()); assertEquals("test1", lineList.get(1).getBody()); assertEquals(ModifyType.ADD, lineList.get(1).getType()); }
@Test public void testNewSingleLine() { String testContent = "@@ -0 +1 @@\n+test1\n\\\\ No newline at end of file"; Diff test = mapper.apply(RawDiff.builder().fileName("test") .rawDiff(Arrays.asList(testContent.split("\n"))).build()); assertEquals(1, test.getDiffSectionList().size()); DiffSection diffSection = test.getDiffSectionList().get(0); List<Line> lineList = diffSection.getLineList(); assertEquals(1, lineList.size()); assertEquals("test1", lineList.get(0).getBody()); assertEquals(ModifyType.ADD, lineList.get(0).getType()); }