Enhance unit test

This commit is contained in:
René Pfeuffer
2018-11-06 12:36:36 +01:00
parent 8be8c19a26
commit adce24fcd7

View File

@@ -43,6 +43,23 @@ public class GitDiffCommandTest extends AbstractGitCommandTestBase {
assertEquals(DIFF_LATEST_COMMIT_TEST_BRANCH, output.toString());
}
@Test
public void diffForPathShouldCreateLimitedDiff() {
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
diffCommandRequest.setRevision("test-branch");
diffCommandRequest.setPath("a.txt");
ByteArrayOutputStream output = new ByteArrayOutputStream();
gitDiffCommand.getDiffResult(diffCommandRequest, output);
assertEquals("diff --git a/a.txt b/a.txt\n" +
"index 7898192..1dc60c7 100644\n" +
"--- a/a.txt\n" +
"+++ b/a.txt\n" +
"@@ -1 +1 @@\n" +
"-a\n" +
"+a and b\n", output.toString());
}
@Test
public void diffBetweenTwoBranchesShouldCreateDiff() {
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
@@ -66,4 +83,22 @@ public class GitDiffCommandTest extends AbstractGitCommandTestBase {
"@@ -0,0 +1 @@\n" +
"+f\n", output.toString());
}
@Test
public void diffBetweenTwoBranchesForPathShouldCreateLimitedDiff() {
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
diffCommandRequest.setRevision("master");
diffCommandRequest.setAncestorChangeset("test-branch");
diffCommandRequest.setPath("a.txt");
ByteArrayOutputStream output = new ByteArrayOutputStream();
gitDiffCommand.getDiffResult(diffCommandRequest, output);
assertEquals("diff --git a/a.txt b/a.txt\n" +
"index 7898192..2f8bc28 100644\n" +
"--- a/a.txt\n" +
"+++ b/a.txt\n" +
"@@ -1 +1,2 @@\n" +
" a\n" +
"+line for blame\n", output.toString());
}
}