Browse Source

RecursiveMergerTest: Open FileOutputStream in try-with-resource

Change-Id: I158333d6393fb807bc21fba23fec7ad474384471
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-4.11
David Pursehouse 7 years ago
parent
commit
ca7d3e2734
  1. 61
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java

61
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) void modifyWorktree(WorktreeState worktreeState, String path, String other)
throws Exception { throws Exception {
FileOutputStream fos = null; switch (worktreeState) {
ObjectId bloblId; case Missing:
new File(db.getWorkTree(), path).delete();
try { break;
switch (worktreeState) { case DifferentFromHeadAndOther:
case Missing: write(new File(db.getWorkTree(), path),
new File(db.getWorkTree(), path).delete(); Integer.toString(counter++));
break; break;
case DifferentFromHeadAndOther: case SameAsHead:
write(new File(db.getWorkTree(), path), try (FileOutputStream fos = new FileOutputStream(
Integer.toString(counter++)); new File(db.getWorkTree(), path))) {
break; db.newObjectReader().open(contentId(Constants.HEAD, path))
case SameAsHead: .copyTo(fos);
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);
} }
} finally { break;
if (fos != null) case SameAsOther:
fos.close(); 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);
} }
} }

Loading…
Cancel
Save