From b6fe0abc4ce66dcc65991f80c15035486afd1e53 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Sun, 20 Jan 2019 17:08:01 +0900 Subject: PackParserTest: Open TestRepository in try-with-resource Change-Id: Ie3521f40ac80bc58df95f9f5dc79d51b29380461 Signed-off-by: David Pursehouse --- .../org/eclipse/jgit/transport/PackParserTest.java | 52 ++++++++++++++-------- 1 file changed, 34 insertions(+), 18 deletions(-) (limited to 'org.eclipse.jgit.test/tst/org') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java index 0f98fac706..fd952f328f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java @@ -141,8 +141,10 @@ public class PackParserTest extends RepositoryTestCase { @Test public void testTinyThinPack() throws Exception { - TestRepository d = new TestRepository(db); - RevBlob a = d.blob("a"); + RevBlob a; + try (TestRepository d = new TestRepository(db)) { + a = d.blob("a"); + } TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); @@ -162,8 +164,9 @@ public class PackParserTest extends RepositoryTestCase { @Test public void testPackWithDuplicateBlob() throws Exception { final byte[] data = Constants.encode("0123456789abcdefg"); - TestRepository d = new TestRepository<>(db); - assertTrue(db.getObjectDatabase().has(d.blob(data))); + try (TestRepository d = new TestRepository<>(db)) { + assertTrue(db.getObjectDatabase().has(d.blob(data))); + } TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); packHeader(pack, 1); @@ -179,8 +182,10 @@ public class PackParserTest extends RepositoryTestCase { @Test public void testPackWithTrailingGarbage() throws Exception { - TestRepository d = new TestRepository(db); - RevBlob a = d.blob("a"); + RevBlob a; + try (TestRepository d = new TestRepository(db)) { + a = d.blob("a"); + } TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); packHeader(pack, 1); @@ -206,9 +211,10 @@ public class PackParserTest extends RepositoryTestCase { @Test public void testMaxObjectSizeFullBlob() throws Exception { - TestRepository d = new TestRepository(db); final byte[] data = Constants.encode("0123456789"); - d.blob(data); + try (TestRepository d = new TestRepository(db)) { + d.blob(data); + } TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); @@ -238,8 +244,10 @@ public class PackParserTest extends RepositoryTestCase { @Test public void testMaxObjectSizeDeltaBlock() throws Exception { - TestRepository d = new TestRepository(db); - RevBlob a = d.blob("a"); + RevBlob a; + try (TestRepository d = new TestRepository(db)) { + a = d.blob("a"); + } TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); @@ -269,8 +277,10 @@ public class PackParserTest extends RepositoryTestCase { @Test public void testMaxObjectSizeDeltaResultSize() throws Exception { - TestRepository d = new TestRepository(db); - RevBlob a = d.blob("0123456789"); + RevBlob a; + try (TestRepository d = new TestRepository(db)) { + a = d.blob("0123456789"); + } TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); @@ -299,8 +309,10 @@ public class PackParserTest extends RepositoryTestCase { @Test public void testNonMarkingInputStream() throws Exception { - TestRepository d = new TestRepository(db); - RevBlob a = d.blob("a"); + RevBlob a; + try (TestRepository d = new TestRepository(db)) { + a = d.blob("a"); + } TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); packHeader(pack, 1); @@ -337,8 +349,10 @@ public class PackParserTest extends RepositoryTestCase { @Test public void testDataAfterPackFooterSingleRead() throws Exception { - TestRepository d = new TestRepository(db); - RevBlob a = d.blob("a"); + RevBlob a; + try (TestRepository d = new TestRepository(db)) { + a = d.blob("a"); + } TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(32*1024); packHeader(pack, 1); @@ -395,9 +409,11 @@ public class PackParserTest extends RepositoryTestCase { @Test public void testDataAfterPackFooterSplitHeaderRead() throws Exception { - TestRepository d = new TestRepository(db); final byte[] data = Constants.encode("a"); - RevBlob b = d.blob(data); + RevBlob b; + try (TestRepository d = new TestRepository(db)) { + b = d.blob(data); + } int objects = 248; TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(32 * 1024); -- cgit v1.2.3