]> source.dussan.org Git - jgit.git/commitdiff
RefUpdateTest: Use try-with-resource for auto-closable types 14/64314/1
authorDavid Pursehouse <david.pursehouse@sonymobile.com>
Thu, 14 Jan 2016 06:09:20 +0000 (15:09 +0900)
committerDavid Pursehouse <david.pursehouse@sonymobile.com>
Thu, 14 Jan 2016 06:09:53 +0000 (15:09 +0900)
Change-Id: I25c8db0e410aa2a4a53dc7d8863e4a6efefcf7cb
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java

index 4ae92ccbe2c75a902c74b0960f5a8bcb5aaf40a6..48434189e4b6ca08162fe1046defe43beb6adf06 100644 (file)
@@ -558,13 +558,15 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
                assertEquals(ppid, db.resolve("refs/heads/master"));
 
                // real test
-               RevCommit old = new RevWalk(db).parseCommit(ppid);
-               RefUpdate updateRef2 = db.updateRef("refs/heads/master");
-               updateRef2.setExpectedOldObjectId(old);
-               updateRef2.setNewObjectId(pid);
-               Result update2 = updateRef2.update();
-               assertEquals(Result.FAST_FORWARD, update2);
-               assertEquals(pid, db.resolve("refs/heads/master"));
+               try (RevWalk rw = new RevWalk(db)) {
+                       RevCommit old = rw.parseCommit(ppid);
+                       RefUpdate updateRef2 = db.updateRef("refs/heads/master");
+                       updateRef2.setExpectedOldObjectId(old);
+                       updateRef2.setNewObjectId(pid);
+                       Result update2 = updateRef2.update();
+                       assertEquals(Result.FAST_FORWARD, update2);
+                       assertEquals(pid, db.resolve("refs/heads/master"));
+               }
        }
 
        /**
@@ -707,9 +709,10 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
 
                // Create new Repository instance, to reread caches and make sure our
                // assumptions are persistent.
-               Repository ndb = new FileRepository(db.getDirectory());
-               assertEquals(rb2, ndb.resolve("refs/heads/new/name"));
-               assertNull(ndb.resolve("refs/heads/b"));
+               try (Repository ndb = new FileRepository(db.getDirectory())) {
+                       assertEquals(rb2, ndb.resolve("refs/heads/new/name"));
+                       assertNull(ndb.resolve("refs/heads/b"));
+               }
        }
 
        public void tryRenameWhenLocked(String toLock, String fromName,