]> source.dussan.org Git - jgit.git/commitdiff
BundleWriterTest: Open RevWalk in try-with-resource 54/64854/1
authorDavid Pursehouse <david.pursehouse@sonymobile.com>
Thu, 21 Jan 2016 10:13:04 +0000 (19:13 +0900)
committerDavid Pursehouse <david.pursehouse@sonymobile.com>
Thu, 21 Jan 2016 10:13:23 +0000 (19:13 +0900)
Change-Id: Ie25770a73b19d6522bad9fdc0966f48370f96265
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java

index ba89d2d616d6832f6987f068f70860c4993ca5c2..461530896d3b0d10f7506b99059d176e38d5c1e1 100644 (file)
@@ -126,24 +126,26 @@ public class BundleWriterTest extends SampleDataRepositoryTestCase {
                assertNull(newRepo.resolve("refs/heads/a"));
 
                // Next an incremental bundle
-               bundle = makeBundle("refs/heads/cc", db.resolve("c").name(),
-                               new RevWalk(db).parseCommit(db.resolve("a").toObjectId()));
-               fetchResult = fetchFromBundle(newRepo, bundle);
-               advertisedRef = fetchResult.getAdvertisedRef("refs/heads/cc");
-               assertEquals(db.resolve("c").name(), advertisedRef.getObjectId().name());
-               assertEquals(db.resolve("c").name(), newRepo.resolve("refs/heads/cc")
-                               .name());
-               assertNull(newRepo.resolve("refs/heads/c"));
-               assertNull(newRepo.resolve("refs/heads/a")); // still unknown
-
-               try {
-                       // Check that we actually needed the first bundle
-                       Repository newRepo2 = createBareRepository();
-                       fetchResult = fetchFromBundle(newRepo2, bundle);
-                       fail("We should not be able to fetch from bundle with prerequisites that are not fulfilled");
-               } catch (MissingBundlePrerequisiteException e) {
-                       assertTrue(e.getMessage()
-                                       .indexOf(db.resolve("refs/heads/a").name()) >= 0);
+               try (RevWalk rw = new RevWalk(db)) {
+                       bundle = makeBundle("refs/heads/cc", db.resolve("c").name(),
+                                       rw.parseCommit(db.resolve("a").toObjectId()));
+                       fetchResult = fetchFromBundle(newRepo, bundle);
+                       advertisedRef = fetchResult.getAdvertisedRef("refs/heads/cc");
+                       assertEquals(db.resolve("c").name(), advertisedRef.getObjectId().name());
+                       assertEquals(db.resolve("c").name(), newRepo.resolve("refs/heads/cc")
+                                       .name());
+                       assertNull(newRepo.resolve("refs/heads/c"));
+                       assertNull(newRepo.resolve("refs/heads/a")); // still unknown
+
+                       try {
+                               // Check that we actually needed the first bundle
+                               Repository newRepo2 = createBareRepository();
+                               fetchResult = fetchFromBundle(newRepo2, bundle);
+                               fail("We should not be able to fetch from bundle with prerequisites that are not fulfilled");
+                       } catch (MissingBundlePrerequisiteException e) {
+                               assertTrue(e.getMessage()
+                                               .indexOf(db.resolve("refs/heads/a").name()) >= 0);
+                       }
                }
        }