@Test public void testDiff() throws Exception { PowerMockito.doNothing().when(GitDiffRunner.class, "addFileTypeFilters", Mockito.any()); RevisionScope<ObjectId> scope = revisionResolver.resolve("ec302a13", "60075ec4"); List<Diff> diffs = GitDiffRunner.diff(repository, scope); assertNotNull(diffs); assertEquals(33, diffs.size()); List<Diff> cbfDiffs = findDiff(diffs, "CachedBcelFinder.java"); assertEquals(1, cbfDiffs.size()); Diff cbfDiff = cbfDiffs.get(0); assertEquals("/dev/null", cbfDiff.getToFileName()); List<Hunk> cbfHunks = cbfDiff.getHunks(); assertEquals(1, cbfHunks.size()); assertEquals(23, cbfHunks.get(0).getLines().size()); List<Diff> jfDiffs = findDiff(diffs, "JarFinder.java"); assertEquals(1, jfDiffs.size()); Diff jfDiff = jfDiffs.get(0); assertEquals("a/engine/src/main/java/com/sandboni/core/engine/finder/JarFinder.java", jfDiff.getFromFileName()); assertEquals("b/engine/src/main/java/com/sandboni/core/engine/finder/jar/JarFinder.java", jfDiff.getToFileName()); List<Hunk> jfHunks = jfDiff.getHunks(); assertEquals(5, jfHunks.size()); List<Diff> dsDiffs = findDiff(diffs, "DirectoryScanner.java"); assertEquals(1, dsDiffs.size()); Diff dsDiff = dsDiffs.get(0); assertEquals("/dev/null", dsDiff.getFromFileName()); List<Hunk> dsHunks = dsDiff.getHunks(); assertEquals(1, dsHunks.size()); assertEquals(55, dsHunks.get(0).getLines().size()); List<Diff> feDiffs = findDiff(diffs, "FinderExecutor.java"); assertEquals(1, feDiffs.size()); Diff feDiff = feDiffs.get(0); List<Hunk> feHunks = feDiff.getHunks(); assertEquals(3, feHunks.size()); Hunk feHunk1 = feHunks.get(0); assertEquals(4, feHunk1.getFromFileRange().getLineStart()); assertEquals(3, feHunk1.getLines().size()); assertEquals(Line.LineType.NEUTRAL, feHunk1.getLines().get(0).getLineType()); assertEquals(Line.LineType.FROM, feHunk1.getLines().get(1).getLineType()); assertEquals(Line.LineType.NEUTRAL, feHunk1.getLines().get(2).getLineType()); Hunk feHunk2 = feHunks.get(1); assertEquals(21, feHunk2.getFromFileRange().getLineStart()); assertEquals(4, feHunk2.getLines().size()); assertEquals(Line.LineType.NEUTRAL, feHunk2.getLines().get(0).getLineType()); assertEquals(Line.LineType.FROM, feHunk2.getLines().get(1).getLineType()); assertEquals(Line.LineType.TO, feHunk2.getLines().get(2).getLineType()); assertEquals(Line.LineType.NEUTRAL, feHunk2.getLines().get(3).getLineType()); Hunk feHunk3 = feHunks.get(2); assertEquals(25, feHunk3.getFromFileRange().getLineStart()); assertEquals(7, feHunk3.getLines().size()); assertEquals(2, feHunk3.getLines().stream().filter(l -> l.getLineType().equals(Line.LineType.NEUTRAL)).count()); assertEquals(5, feHunk3.getLines().stream().filter(l -> l.getLineType().equals(Line.LineType.TO)).count()); }
public static List<Diff> diff(Repository repository, RevisionScope<ObjectId> revisionScope) throws SourceControlException { String[] command = buildDiffCommand(revisionScope); try { List<String> diffLines = ProcessRunner.runCommand(getRepositoryBaseFolder(repository), command); byte[] diffBytes = pad(diffLines); return new UnifiedDiffParser().parse(diffBytes); } catch (IOException e) { throw new SourceControlException("Error running git diff command", e); } }
GitDiffRunner { public static List<Diff> diff(Repository repository, RevisionScope<ObjectId> revisionScope) throws SourceControlException { String[] command = buildDiffCommand(revisionScope); try { List<String> diffLines = ProcessRunner.runCommand(getRepositoryBaseFolder(repository), command); byte[] diffBytes = pad(diffLines); return new UnifiedDiffParser().parse(diffBytes); } catch (IOException e) { throw new SourceControlException("Error running git diff command", e); } } }
GitDiffRunner { public static List<Diff> diff(Repository repository, RevisionScope<ObjectId> revisionScope) throws SourceControlException { String[] command = buildDiffCommand(revisionScope); try { List<String> diffLines = ProcessRunner.runCommand(getRepositoryBaseFolder(repository), command); byte[] diffBytes = pad(diffLines); return new UnifiedDiffParser().parse(diffBytes); } catch (IOException e) { throw new SourceControlException("Error running git diff command", e); } } private  GitDiffRunner(); }
GitDiffRunner { public static List<Diff> diff(Repository repository, RevisionScope<ObjectId> revisionScope) throws SourceControlException { String[] command = buildDiffCommand(revisionScope); try { List<String> diffLines = ProcessRunner.runCommand(getRepositoryBaseFolder(repository), command); byte[] diffBytes = pad(diffLines); return new UnifiedDiffParser().parse(diffBytes); } catch (IOException e) { throw new SourceControlException("Error running git diff command", e); } } private  GitDiffRunner(); static List<Diff> diff(Repository repository, RevisionScope<ObjectId> revisionScope); }
GitDiffRunner { public static List<Diff> diff(Repository repository, RevisionScope<ObjectId> revisionScope) throws SourceControlException { String[] command = buildDiffCommand(revisionScope); try { List<String> diffLines = ProcessRunner.runCommand(getRepositoryBaseFolder(repository), command); byte[] diffBytes = pad(diffLines); return new UnifiedDiffParser().parse(diffBytes); } catch (IOException e) { throw new SourceControlException("Error running git diff command", e); } } private  GitDiffRunner(); static List<Diff> diff(Repository repository, RevisionScope<ObjectId> revisionScope);  }