]> source.dussan.org Git - jgit.git/commitdiff
FileTreeIteratorJava7Test: Create Git instances in try-with-resource 17/64717/1
authorDavid Pursehouse <david.pursehouse@sonymobile.com>
Wed, 20 Jan 2016 02:22:18 +0000 (11:22 +0900)
committerDavid Pursehouse <david.pursehouse@sonymobile.com>
Wed, 20 Jan 2016 02:23:50 +0000 (11:23 +0900)
Change-Id: I493e90e8a0d96db5acc49759c8e138b0a8c7b099
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorJava7Test.java

index 429f35ea4b5f5093224c0725613722f46537e977..cd55cbae7a0a360c4912530c4ae23b64255f90b3 100644 (file)
@@ -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()));
+               }
        }
 }