summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2018-03-07 14:49:21 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2018-03-07 14:49:21 +0900
commit9f689e90d42a6405054df1f98e43902c87595317 (patch)
tree37397fa4d56e2cee44d2dfea541c3ef2d8a6a2a7
parent2c29af786763c0c8d74741c86edbeff4e5140e35 (diff)
downloadjgit-9f689e90d42a6405054df1f98e43902c87595317.tar.gz
jgit-9f689e90d42a6405054df1f98e43902c87595317.zip
MergeHeadMsgTest: Open FileOutputStream in try-with-resource
Change-Id: I8efa549b98bf661665dc29d48d0e5661b0e8530c Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MergeHeadMsgTest.java22
1 files 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 4f26a27ef6..347883f842 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.<ObjectId> 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);
}