]> source.dussan.org Git - jgit.git/commitdiff
ReceivePackAdvertiseRefsHookTest#testSuccess: Open TransportLocal in t-w-r 82/119382/2
authorDavid Pursehouse <david.pursehouse@gmail.com>
Wed, 14 Mar 2018 04:05:41 +0000 (13:05 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Wed, 14 Mar 2018 22:57:02 +0000 (07:57 +0900)
Change-Id: I198ff2ff36de482445141b5ce489204a9c2f4933
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java

index 8ef87cb3c116b3e2a5c51854bb149d28e4855371..7aae7b0c32b0e20af3b009a5d1a7e1e64a454215 100644 (file)
@@ -199,6 +199,23 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
                assertFalse(haves.get().contains(P));
        }
 
+       private TransportLocal newTransportLocalWithStrictValidation()
+                       throws Exception {
+               return new TransportLocal(src, uriOf(dst), dst.getDirectory()) {
+                       @Override
+                       ReceivePack createReceivePack(final Repository db) {
+                               db.close();
+                               dst.incrementOpen();
+
+                               final ReceivePack rp = super.createReceivePack(dst);
+                               rp.setCheckReceivedObjects(true);
+                               rp.setCheckReferencedObjectsAreReachable(true);
+                               rp.setAdvertiseRefsHook(new HidePrivateHook());
+                               return rp;
+                       }
+               };
+       }
+
        @Test
        public void testSuccess() throws Exception {
                // Manually force a delta of an object so we reuse it later.
@@ -230,19 +247,7 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
 
                // Push this new content to the remote, doing strict validation.
                //
-               TransportLocal t = new TransportLocal(src, uriOf(dst), dst.getDirectory()) {
-                       @Override
-                       ReceivePack createReceivePack(final Repository db) {
-                               db.close();
-                               dst.incrementOpen();
-
-                               final ReceivePack rp = super.createReceivePack(dst);
-                               rp.setCheckReceivedObjects(true);
-                               rp.setCheckReferencedObjectsAreReachable(true);
-                               rp.setAdvertiseRefsHook(new HidePrivateHook());
-                               return rp;
-                       }
-               };
+               PushResult r;
                RemoteRefUpdate u = new RemoteRefUpdate( //
                                src, //
                                R_MASTER, // src name
@@ -251,12 +256,9 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
                                null, // local tracking branch
                                null // expected id
                );
-               PushResult r;
-               try {
+               try (TransportLocal t = newTransportLocalWithStrictValidation()) {
                        t.setPushThin(true);
                        r = t.push(PM, Collections.singleton(u));
-               } finally {
-                       t.close();
                }
 
                assertNotNull("have result", r);