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

Loading…
Cancel
Save