Selaa lähdekoodia

RecursiveMergerTest: Open FileOutputStream in try-with-resource

Change-Id: I158333d6393fb807bc21fba23fec7ad474384471
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
tags/v4.11.0.201803080745-r
David Pursehouse 6 vuotta sitten
vanhempi
commit
ca7d3e2734

+ 28
- 33
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java Näytä tiedosto

@@ -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);
}
}


Loading…
Peruuta
Tallenna