From 9f689e90d42a6405054df1f98e43902c87595317 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Wed, 7 Mar 2018 14:49:21 +0900 Subject: [PATCH] MergeHeadMsgTest: Open FileOutputStream in try-with-resource Change-Id: I8efa549b98bf661665dc29d48d0e5661b0e8530c Signed-off-by: David Pursehouse --- .../eclipse/jgit/lib/MergeHeadMsgTest.java | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MergeHeadMsgTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MergeHeadMsgTest.java index 4f26a27ef..347883f84 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MergeHeadMsgTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MergeHeadMsgTest.java @@ -68,13 +68,11 @@ public class MergeHeadMsgTest extends RepositoryTestCase { assertEquals(db.readMergeHeads().size(), 2); assertEquals(db.readMergeHeads().get(0), ObjectId.zeroId()); assertEquals(db.readMergeHeads().get(1), ObjectId.fromString(sampleId)); + // same test again, this time with lower-level io - FileOutputStream fos = new FileOutputStream(new File(db.getDirectory(), - "MERGE_HEAD")); - try { + try (FileOutputStream fos = new FileOutputStream( + new File(db.getDirectory(), "MERGE_HEAD"));) { fos.write("0000000000000000000000000000000000000000\n1c6db447abdbb291b25f07be38ea0b1bf94947c5\n".getBytes(Constants.CHARACTER_ENCODING)); - } finally { - fos.close(); } assertEquals(db.readMergeHeads().size(), 2); assertEquals(db.readMergeHeads().get(0), ObjectId.zeroId()); @@ -82,12 +80,9 @@ public class MergeHeadMsgTest extends RepositoryTestCase { db.writeMergeHeads(Collections. emptyList()); assertEquals(read(new File(db.getDirectory(), "MERGE_HEAD")), ""); assertEquals(db.readMergeHeads(), null); - fos = new FileOutputStream(new File(db.getDirectory(), - "MERGE_HEAD")); - try { + try (FileOutputStream fos = new FileOutputStream( + new File(db.getDirectory(), "MERGE_HEAD"))) { fos.write(sampleId.getBytes(Constants.CHARACTER_ENCODING)); - } finally { - fos.close(); } assertEquals(db.readMergeHeads().size(), 1); assertEquals(db.readMergeHeads().get(0), ObjectId.fromString(sampleId)); @@ -103,12 +98,9 @@ public class MergeHeadMsgTest extends RepositoryTestCase { db.writeMergeCommitMsg(null); assertEquals(db.readMergeCommitMsg(), null); assertFalse(new File(db.getDirectory(), "MERGE_MSG").exists()); - FileOutputStream fos = new FileOutputStream(new File(db.getDirectory(), - Constants.MERGE_MSG)); - try { + try (FileOutputStream fos = new FileOutputStream( + new File(db.getDirectory(), Constants.MERGE_MSG))) { fos.write(mergeMsg.getBytes(Constants.CHARACTER_ENCODING)); - } finally { - fos.close(); } assertEquals(db.readMergeCommitMsg(), mergeMsg); }