]> source.dussan.org Git - jgit.git/commitdiff
RevCommitListTest: Open Git and RevWalk in try-with-resource 75/65975/1
authorDavid Pursehouse <david.pursehouse@sonymobile.com>
Fri, 5 Feb 2016 08:26:03 +0000 (17:26 +0900)
committerDavid Pursehouse <david.pursehouse@sonymobile.com>
Fri, 5 Feb 2016 08:26:03 +0000 (17:26 +0900)
Change-Id: I4ba273a364a12f82a3b3b06ba050bc633411daf6
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitListTest.java

index 5ec6eb308ec06751a35b74b9ef0046922ff5fe56..4d75322f425df409f912bdcc48e42fe980093ebe 100644 (file)
@@ -57,14 +57,15 @@ public class RevCommitListTest extends RepositoryTestCase {
        private RevCommitList<RevCommit> list;
 
        public void setup(int count) throws Exception {
-               Git git = new Git(db);
-               for (int i = 0; i < count; i++)
-                       git.commit().setCommitter(committer).setAuthor(author)
-                                       .setMessage("commit " + i).call();
-               list = new RevCommitList<RevCommit>();
-               RevWalk w = new RevWalk(db);
-               w.markStart(w.lookupCommit(db.resolve(Constants.HEAD)));
-               list.source(w);
+               try (Git git = new Git(db);
+                               RevWalk w = new RevWalk(db);) {
+                       for (int i = 0; i < count; i++)
+                               git.commit().setCommitter(committer).setAuthor(author)
+                                               .setMessage("commit " + i).call();
+                       list = new RevCommitList<RevCommit>();
+                       w.markStart(w.lookupCommit(db.resolve(Constants.HEAD)));
+                       list.source(w);
+               }
        }
 
        @Test
@@ -107,17 +108,18 @@ public class RevCommitListTest extends RepositoryTestCase {
        public void testFillToCommit() throws Exception {
                setup(3);
 
-               RevWalk w = new RevWalk(db);
-               w.markStart(w.lookupCommit(db.resolve(Constants.HEAD)));
+               try (RevWalk w = new RevWalk(db)) {
+                       w.markStart(w.lookupCommit(db.resolve(Constants.HEAD)));
 
-               w.next();
-               RevCommit c = w.next();
-               assertNotNull("should have found 2. commit", c);
+                       w.next();
+                       RevCommit c = w.next();
+                       assertNotNull("should have found 2. commit", c);
 
-               list.fillTo(c, 5);
-               assertEquals(2, list.size());
-               assertEquals("commit 1", list.get(1).getFullMessage());
-               assertNull(list.get(3));
+                       list.fillTo(c, 5);
+                       assertEquals(2, list.size());
+                       assertEquals("commit 1", list.get(1).getFullMessage());
+                       assertNull(list.get(3));
+               }
        }
 
        @Test