Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse2016-02-05 02:51:27 +0000
committerDavid Pursehouse2016-02-05 02:51:27 +0000
commitd0d37737631f5ea7c0bed3d408d6d824372b096a (patch)
tree30fb62e21e79d62b0b18a5832ba2ecb32414b7e8
parent84ae3f499176f8d0af9473a79f65c67108f047c7 (diff)
downloadjgit-d0d37737631f5ea7c0bed3d408d6d824372b096a.tar.gz
jgit-d0d37737631f5ea7c0bed3d408d6d824372b096a.tar.xz
jgit-d0d37737631f5ea7c0bed3d408d6d824372b096a.zip
T0003_BasicTest: Open autocloseable types in try-with-resource
FileRepository and ObjectInserter.Formatter are autocloseable, so use try-with-resource for these. Remove suppression of unused variable warning that is no longer necessary. Change-Id: I270829f0a4030083c9599eb5785b0145dc590ed8 Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java22
1 files changed, 11 insertions, 11 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
index cb8726be5c..b6ad22bbe5 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
@@ -354,14 +354,14 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
@Test
public void test007_Open() throws IOException {
- final FileRepository db2 = new FileRepository(db.getDirectory());
- assertEquals(db.getDirectory(), db2.getDirectory());
- assertEquals(db.getObjectDatabase().getDirectory(), db2
- .getObjectDatabase().getDirectory());
- assertNotSame(db.getConfig(), db2.getConfig());
+ try (final FileRepository db2 = new FileRepository(db.getDirectory())) {
+ assertEquals(db.getDirectory(), db2.getDirectory());
+ assertEquals(db.getObjectDatabase().getDirectory(), db2
+ .getObjectDatabase().getDirectory());
+ assertNotSame(db.getConfig(), db2.getConfig());
+ }
}
- @SuppressWarnings("unused")
@Test
public void test008_FailOnWrongVersion() throws IOException {
final File cfg = new File(db.getDirectory(), Constants.CONFIG);
@@ -370,8 +370,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
+ badvers + "\n";
write(cfg, configStr);
- try {
- new FileRepository(db.getDirectory());
+ try (FileRepository unused = new FileRepository(db.getDirectory())) {
fail("incorrectly opened a bad repository");
} catch (IllegalArgumentException ioe) {
assertNotNull(ioe.getMessage());
@@ -533,9 +532,10 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
public void test025_computeSha1NoStore() throws IOException {
byte[] data = "test025 some data, more than 16 bytes to get good coverage"
.getBytes("ISO-8859-1");
- final ObjectId id = new ObjectInserter.Formatter().idFor(
- Constants.OBJ_BLOB, data);
- assertEquals("4f561df5ecf0dfbd53a0dc0f37262fef075d9dde", id.name());
+ try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) {
+ final ObjectId id = formatter.idFor(Constants.OBJ_BLOB, data);
+ assertEquals("4f561df5ecf0dfbd53a0dc0f37262fef075d9dde", id.name());
+ }
}
@Test

Back to the top