aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2018-02-26 17:39:57 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2018-02-26 17:39:57 +0900
commitca7d3e27342dfd98b041dc12a3094408f08b554d (patch)
treed62d14e02c6749e772847269bf3401359be05393 /org.eclipse.jgit.test
parent4651d01e29aab1aac9c7c798695bafa8a04b25b1 (diff)
downloadjgit-ca7d3e27342dfd98b041dc12a3094408f08b554d.tar.gz
jgit-ca7d3e27342dfd98b041dc12a3094408f08b554d.zip
RecursiveMergerTest: Open FileOutputStream in try-with-resource
Change-Id: I158333d6393fb807bc21fba23fec7ad474384471 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java61
1 files changed, 28 insertions, 33 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java
index 039a6e8cfc..190224a855 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java
@@ -817,40 +817,35 @@ public class RecursiveMergerTest extends RepositoryTestCase {
void modifyWorktree(WorktreeState worktreeState, String path, String other)
throws Exception {
- FileOutputStream fos = null;
- ObjectId bloblId;
-
- try {
- switch (worktreeState) {
- case Missing:
- new File(db.getWorkTree(), path).delete();
- break;
- case DifferentFromHeadAndOther:
- write(new File(db.getWorkTree(), path),
- Integer.toString(counter++));
- break;
- case SameAsHead:
- bloblId = contentId(Constants.HEAD, path);
- fos = new FileOutputStream(new File(db.getWorkTree(), path));
- db.newObjectReader().open(bloblId).copyTo(fos);
- break;
- case SameAsOther:
- bloblId = contentId(other, path);
- fos = new FileOutputStream(new File(db.getWorkTree(), path));
- db.newObjectReader().open(bloblId).copyTo(fos);
- break;
- case Bare:
- if (db.isBare())
- return;
- File workTreeFile = db.getWorkTree();
- db.getConfig().setBoolean("core", null, "bare", true);
- db.getDirectory().renameTo(new File(workTreeFile, "test.git"));
- db = new FileRepository(new File(workTreeFile, "test.git"));
- db_t = new TestRepository<>(db);
+ switch (worktreeState) {
+ case Missing:
+ new File(db.getWorkTree(), path).delete();
+ break;
+ case DifferentFromHeadAndOther:
+ write(new File(db.getWorkTree(), path),
+ Integer.toString(counter++));
+ break;
+ case SameAsHead:
+ try (FileOutputStream fos = new FileOutputStream(
+ new File(db.getWorkTree(), path))) {
+ db.newObjectReader().open(contentId(Constants.HEAD, path))
+ .copyTo(fos);
}
- } finally {
- if (fos != null)
- fos.close();
+ break;
+ case SameAsOther:
+ try (FileOutputStream fos = new FileOutputStream(
+ new File(db.getWorkTree(), path))) {
+ db.newObjectReader().open(contentId(other, path)).copyTo(fos);
+ }
+ break;
+ case Bare:
+ if (db.isBare())
+ return;
+ File workTreeFile = db.getWorkTree();
+ db.getConfig().setBoolean("core", null, "bare", true);
+ db.getDirectory().renameTo(new File(workTreeFile, "test.git"));
+ db = new FileRepository(new File(workTreeFile, "test.git"));
+ db_t = new TestRepository<>(db);
}
}