Browse Source

DumbClientSmartServerTest: Open auto-closeable resources in try-with-resource

Change-Id: I599c6e274fe80af7bfd2205f56f469c22d1dd3e0
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-4.11
David Pursehouse 7 years ago
parent
commit
ef9046fa89
  1. 25
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java

25
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java

@ -140,9 +140,8 @@ public class DumbClientSmartServerTest extends HttpTestCase {
assertEquals("http", remoteURI.getScheme()); assertEquals("http", remoteURI.getScheme());
Map<String, Ref> map; Map<String, Ref> map;
Transport t = Transport.open(dst, remoteURI); try (Transport t = Transport.open(dst, remoteURI)) {
((TransportHttp) t).setUseSmartHttp(false); ((TransportHttp) t).setUseSmartHttp(false);
try {
// I didn't make up these public interface names, I just // I didn't make up these public interface names, I just
// approved them for inclusion into the code base. Sorry. // approved them for inclusion into the code base. Sorry.
// --spearce // --spearce
@ -150,14 +149,9 @@ public class DumbClientSmartServerTest extends HttpTestCase {
assertTrue("isa TransportHttp", t instanceof TransportHttp); assertTrue("isa TransportHttp", t instanceof TransportHttp);
assertTrue("isa HttpTransport", t instanceof HttpTransport); assertTrue("isa HttpTransport", t instanceof HttpTransport);
FetchConnection c = t.openFetch(); try (FetchConnection c = t.openFetch()) {
try {
map = c.getRefsMap(); map = c.getRefsMap();
} finally {
c.close();
} }
} finally {
t.close();
} }
assertNotNull("have map of refs", map); assertNotNull("have map of refs", map);
@ -201,12 +195,9 @@ public class DumbClientSmartServerTest extends HttpTestCase {
Repository dst = createBareRepository(); Repository dst = createBareRepository();
assertFalse(dst.hasObject(A_txt)); assertFalse(dst.hasObject(A_txt));
Transport t = Transport.open(dst, remoteURI); try (Transport t = Transport.open(dst, remoteURI)) {
((TransportHttp) t).setUseSmartHttp(false); ((TransportHttp) t).setUseSmartHttp(false);
try {
t.fetch(NullProgressMonitor.INSTANCE, mirror(master)); t.fetch(NullProgressMonitor.INSTANCE, mirror(master));
} finally {
t.close();
} }
assertTrue(dst.hasObject(A_txt)); assertTrue(dst.hasObject(A_txt));
@ -229,12 +220,9 @@ public class DumbClientSmartServerTest extends HttpTestCase {
Repository dst = createBareRepository(); Repository dst = createBareRepository();
assertFalse(dst.hasObject(A_txt)); assertFalse(dst.hasObject(A_txt));
Transport t = Transport.open(dst, remoteURI); try (Transport t = Transport.open(dst, remoteURI)) {
((TransportHttp) t).setUseSmartHttp(false); ((TransportHttp) t).setUseSmartHttp(false);
try {
t.fetch(NullProgressMonitor.INSTANCE, mirror(master)); t.fetch(NullProgressMonitor.INSTANCE, mirror(master));
} finally {
t.close();
} }
assertTrue(dst.hasObject(A_txt)); assertTrue(dst.hasObject(A_txt));
@ -265,9 +253,8 @@ public class DumbClientSmartServerTest extends HttpTestCase {
final RevCommit Q = src.commit().create(); final RevCommit Q = src.commit().create();
final Repository db = src.getRepository(); final Repository db = src.getRepository();
Transport t = Transport.open(db, remoteURI); try (Transport t = Transport.open(db, remoteURI)) {
((TransportHttp) t).setUseSmartHttp(false); ((TransportHttp) t).setUseSmartHttp(false);
try {
try { try {
t.push(NullProgressMonitor.INSTANCE, push(src, Q)); t.push(NullProgressMonitor.INSTANCE, push(src, Q));
fail("push incorrectly completed against a smart server"); fail("push incorrectly completed against a smart server");
@ -275,8 +262,6 @@ public class DumbClientSmartServerTest extends HttpTestCase {
String exp = "smart HTTP push disabled"; String exp = "smart HTTP push disabled";
assertEquals(exp, nse.getMessage()); assertEquals(exp, nse.getMessage());
} }
} finally {
t.close();
} }
} }
} }

Loading…
Cancel
Save