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())); + } } }