Browse Source

BlameCommandTest: Instantiate Git objects in try-with-resource

Change-Id: Icb9e6bb9ee99589fa2e0388c8b305a8a1f5954db
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
stable-4.2
David Pursehouse 9 years ago
parent
commit
41ace0580c
  1. 46
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java

46
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java

@ -72,8 +72,7 @@ public class BlameCommandTest extends RepositoryTestCase {
@Test @Test
public void testSingleRevision() throws Exception { public void testSingleRevision() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
String[] content = new String[] { "first", "second", "third" }; String[] content = new String[] { "first", "second", "third" };
writeTrashFile("file.txt", join(content)); writeTrashFile("file.txt", join(content));
@ -91,11 +90,11 @@ public class BlameCommandTest extends RepositoryTestCase {
assertEquals(i, lines.getSourceLine(i)); assertEquals(i, lines.getSourceLine(i));
} }
} }
}
@Test @Test
public void testTwoRevisions() throws Exception { public void testTwoRevisions() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
String[] content1 = new String[] { "first", "second" }; String[] content1 = new String[] { "first", "second" };
writeTrashFile("file.txt", join(content1)); writeTrashFile("file.txt", join(content1));
git.add().addFilepattern("file.txt").call(); git.add().addFilepattern("file.txt").call();
@ -120,6 +119,7 @@ public class BlameCommandTest extends RepositoryTestCase {
assertEquals(commit2, lines.getSourceCommit(2)); assertEquals(commit2, lines.getSourceCommit(2));
assertEquals(2, lines.getSourceLine(2)); assertEquals(2, lines.getSourceLine(2));
} }
}
@Test @Test
public void testRename() throws Exception { public void testRename() throws Exception {
@ -138,8 +138,7 @@ public class BlameCommandTest extends RepositoryTestCase {
private void testRename(final String sourcePath, final String destPath) private void testRename(final String sourcePath, final String destPath)
throws Exception { throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
String[] content1 = new String[] { "a", "b", "c" }; String[] content1 = new String[] { "a", "b", "c" };
writeTrashFile(sourcePath, join(content1)); writeTrashFile(sourcePath, join(content1));
git.add().addFilepattern(sourcePath).call(); git.add().addFilepattern(sourcePath).call();
@ -172,11 +171,11 @@ public class BlameCommandTest extends RepositoryTestCase {
assertEquals(2, lines.getSourceLine(2)); assertEquals(2, lines.getSourceLine(2));
assertEquals(destPath, lines.getSourcePath(2)); assertEquals(destPath, lines.getSourcePath(2));
} }
}
@Test @Test
public void testTwoRenames() throws Exception { public void testTwoRenames() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
// Commit 1: Add file.txt // Commit 1: Add file.txt
String[] content1 = new String[] { "a" }; String[] content1 = new String[] { "a" };
writeTrashFile("file.txt", join(content1)); writeTrashFile("file.txt", join(content1));
@ -214,11 +213,11 @@ public class BlameCommandTest extends RepositoryTestCase {
assertEquals(1, lines.getSourceLine(1)); assertEquals(1, lines.getSourceLine(1));
assertEquals("file1.txt", lines.getSourcePath(1)); assertEquals("file1.txt", lines.getSourcePath(1));
} }
}
@Test @Test
public void testDeleteTrailingLines() throws Exception { public void testDeleteTrailingLines() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
String[] content1 = new String[] { "a", "b", "c", "d" }; String[] content1 = new String[] { "a", "b", "c", "d" };
String[] content2 = new String[] { "a", "b" }; String[] content2 = new String[] { "a", "b" };
@ -246,11 +245,11 @@ public class BlameCommandTest extends RepositoryTestCase {
assertEquals(0, lines.getSourceLine(0)); assertEquals(0, lines.getSourceLine(0));
assertEquals(1, lines.getSourceLine(1)); assertEquals(1, lines.getSourceLine(1));
} }
}
@Test @Test
public void testDeleteMiddleLines() throws Exception { public void testDeleteMiddleLines() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
String[] content1 = new String[] { "a", "b", "c", "d", "e" }; String[] content1 = new String[] { "a", "b", "c", "d", "e" };
String[] content2 = new String[] { "a", "c", "e" }; String[] content2 = new String[] { "a", "c", "e" };
@ -281,11 +280,11 @@ public class BlameCommandTest extends RepositoryTestCase {
assertEquals(commit1, lines.getSourceCommit(2)); assertEquals(commit1, lines.getSourceCommit(2));
assertEquals(2, lines.getSourceLine(2)); assertEquals(2, lines.getSourceLine(2));
} }
}
@Test @Test
public void testEditAllLines() throws Exception { public void testEditAllLines() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
String[] content1 = new String[] { "a", "1" }; String[] content1 = new String[] { "a", "1" };
String[] content2 = new String[] { "b", "2" }; String[] content2 = new String[] { "b", "2" };
@ -305,11 +304,11 @@ public class BlameCommandTest extends RepositoryTestCase {
assertEquals(commit2, lines.getSourceCommit(0)); assertEquals(commit2, lines.getSourceCommit(0));
assertEquals(commit2, lines.getSourceCommit(1)); assertEquals(commit2, lines.getSourceCommit(1));
} }
}
@Test @Test
public void testMiddleClearAllLines() throws Exception { public void testMiddleClearAllLines() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
String[] content1 = new String[] { "a", "b", "c" }; String[] content1 = new String[] { "a", "b", "c" };
writeTrashFile("file.txt", join(content1)); writeTrashFile("file.txt", join(content1));
@ -333,6 +332,7 @@ public class BlameCommandTest extends RepositoryTestCase {
assertEquals(commit3, lines.getSourceCommit(1)); assertEquals(commit3, lines.getSourceCommit(1));
assertEquals(commit3, lines.getSourceCommit(2)); assertEquals(commit3, lines.getSourceCommit(2));
} }
}
@Test @Test
public void testCoreAutoCrlf1() throws Exception { public void testCoreAutoCrlf1() throws Exception {
@ -361,7 +361,7 @@ public class BlameCommandTest extends RepositoryTestCase {
private void testCoreAutoCrlf(AutoCRLF modeForCommitting, private void testCoreAutoCrlf(AutoCRLF modeForCommitting,
AutoCRLF modeForReset) throws Exception { AutoCRLF modeForReset) throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
FileBasedConfig config = db.getConfig(); FileBasedConfig config = db.getConfig();
config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null, config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_AUTOCRLF, modeForCommitting); ConfigConstants.CONFIG_KEY_AUTOCRLF, modeForCommitting);
@ -388,11 +388,11 @@ public class BlameCommandTest extends RepositoryTestCase {
assertEquals(commit, lines.getSourceCommit(1)); assertEquals(commit, lines.getSourceCommit(1));
assertEquals(commit, lines.getSourceCommit(2)); assertEquals(commit, lines.getSourceCommit(2));
} }
}
@Test @Test
public void testConflictingMerge1() throws Exception { public void testConflictingMerge1() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
RevCommit base = commitFile("file.txt", join("0", "1", "2", "3", "4"), RevCommit base = commitFile("file.txt", join("0", "1", "2", "3", "4"),
"master"); "master");
@ -422,13 +422,13 @@ public class BlameCommandTest extends RepositoryTestCase {
assertEquals(merge, lines.getSourceCommit(3)); assertEquals(merge, lines.getSourceCommit(3));
assertEquals(base, lines.getSourceCommit(4)); assertEquals(base, lines.getSourceCommit(4));
} }
}
// this test inverts the order of the master and side commit and is // this test inverts the order of the master and side commit and is
// otherwise identical to testConflictingMerge1 // otherwise identical to testConflictingMerge1
@Test @Test
public void testConflictingMerge2() throws Exception { public void testConflictingMerge2() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
RevCommit base = commitFile("file.txt", join("0", "1", "2", "3", "4"), RevCommit base = commitFile("file.txt", join("0", "1", "2", "3", "4"),
"master"); "master");
@ -458,10 +458,11 @@ public class BlameCommandTest extends RepositoryTestCase {
assertEquals(merge, lines.getSourceCommit(3)); assertEquals(merge, lines.getSourceCommit(3));
assertEquals(base, lines.getSourceCommit(4)); assertEquals(base, lines.getSourceCommit(4));
} }
}
@Test @Test
public void testWhitespaceMerge() throws Exception { public void testWhitespaceMerge() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
RevCommit base = commitFile("file.txt", join("0", "1", "2"), "master"); RevCommit base = commitFile("file.txt", join("0", "1", "2"), "master");
RevCommit side = commitFile("file.txt", join("0", "1", " 2 side "), RevCommit side = commitFile("file.txt", join("0", "1", " 2 side "),
"side"); "side");
@ -488,3 +489,4 @@ public class BlameCommandTest extends RepositoryTestCase {
assertEquals(side, lines.getSourceCommit(2)); assertEquals(side, lines.getSourceCommit(2));
} }
} }
}

Loading…
Cancel
Save