From 7c21aeb5083ca5ec3a8eaf54ab2ba8d2f84ce87a Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Wed, 20 Jan 2016 11:22:18 +0900 Subject: [PATCH] FileTreeIteratorJava7Test: Create Git instances in try-with-resource Change-Id: I493e90e8a0d96db5acc49759c8e138b0a8c7b099 Signed-off-by: David Pursehouse --- .../treewalk/FileTreeIteratorJava7Test.java | 70 ++++++++++--------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorJava7Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorJava7Test.java index 429f35ea4..cd55cbae7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorJava7Test.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorJava7Test.java @@ -103,18 +103,20 @@ public class FileTreeIteratorJava7Test extends RepositoryTestCase { }); assertTrue(dce.commit()); } - new Git(db).commit().setMessage("Adding link").call(); - new Git(db).reset().setMode(ResetType.HARD).call(); - DirCacheIterator dci = new DirCacheIterator(db.readDirCache()); - FileTreeIterator fti = new FileTreeIterator(db); + try (Git git = new Git(db)) { + git.commit().setMessage("Adding link").call(); + git.reset().setMode(ResetType.HARD).call(); + DirCacheIterator dci = new DirCacheIterator(db.readDirCache()); + FileTreeIterator fti = new FileTreeIterator(db); - // self-check - assertEquals("link", fti.getEntryPathString()); - assertEquals("link", dci.getEntryPathString()); + // self-check + assertEquals("link", fti.getEntryPathString()); + assertEquals("link", dci.getEntryPathString()); - // test - assertFalse(fti.isModified(dci.getDirCacheEntry(), true, - db.newObjectReader())); + // test + assertFalse(fti.isModified(dci.getDirCacheEntry(), true, + db.newObjectReader())); + } } /** @@ -142,18 +144,20 @@ public class FileTreeIteratorJava7Test extends RepositoryTestCase { }); assertTrue(dce.commit()); } - new Git(db).commit().setMessage("Adding link").call(); - new Git(db).reset().setMode(ResetType.HARD).call(); - DirCacheIterator dci = new DirCacheIterator(db.readDirCache()); - FileTreeIterator fti = new FileTreeIterator(db); + try (Git git = new Git(db)) { + git.commit().setMessage("Adding link").call(); + git.reset().setMode(ResetType.HARD).call(); + DirCacheIterator dci = new DirCacheIterator(db.readDirCache()); + FileTreeIterator fti = new FileTreeIterator(db); - // self-check - assertEquals("link", fti.getEntryPathString()); - assertEquals("link", dci.getEntryPathString()); + // self-check + assertEquals("link", fti.getEntryPathString()); + assertEquals("link", dci.getEntryPathString()); - // test - assertFalse(fti.isModified(dci.getDirCacheEntry(), true, - db.newObjectReader())); + // test + assertFalse(fti.isModified(dci.getDirCacheEntry(), true, + db.newObjectReader())); + } } /** @@ -182,20 +186,22 @@ public class FileTreeIteratorJava7Test extends RepositoryTestCase { }); assertTrue(dce.commit()); } - new Git(db).commit().setMessage("Adding link").call(); - new Git(db).reset().setMode(ResetType.HARD).call(); + try (Git git = new Git(db)) { + git.commit().setMessage("Adding link").call(); + git.reset().setMode(ResetType.HARD).call(); - FileUtils.delete(new File(trash, "link"), FileUtils.NONE); - FS.DETECTED.createSymLink(new File(trash, "link"), "newtarget"); - DirCacheIterator dci = new DirCacheIterator(db.readDirCache()); - FileTreeIterator fti = new FileTreeIterator(db); + FileUtils.delete(new File(trash, "link"), FileUtils.NONE); + FS.DETECTED.createSymLink(new File(trash, "link"), "newtarget"); + DirCacheIterator dci = new DirCacheIterator(db.readDirCache()); + FileTreeIterator fti = new FileTreeIterator(db); - // self-check - assertEquals("link", fti.getEntryPathString()); - assertEquals("link", dci.getEntryPathString()); + // self-check + assertEquals("link", fti.getEntryPathString()); + assertEquals("link", dci.getEntryPathString()); - // test - assertTrue(fti.isModified(dci.getDirCacheEntry(), true, - db.newObjectReader())); + // test + assertTrue(fti.isModified(dci.getDirCacheEntry(), true, + db.newObjectReader())); + } } }