From b498bc2a0e770272399ac407cdbc9171ab2d0ae7 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 5 Mar 2018 10:59:43 +0900 Subject: [PATCH] CheckoutCommandTest: Open FileInputStream in try-with-resource Change-Id: I972958373ceaf4c3ae756559ccbc341506d4e72d Signed-off-by: David Pursehouse --- .../tst/org/eclipse/jgit/api/CheckoutCommandTest.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java index 4f0f2a7fb..71df59e1f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java @@ -170,15 +170,12 @@ public class CheckoutCommandTest extends RepositoryTestCase { @Test public void testCheckoutWithNonDeletedFiles() throws Exception { File testFile = writeTrashFile("temp", ""); - FileInputStream fis = new FileInputStream(testFile); - try { + try (FileInputStream fis = new FileInputStream(testFile)) { FileUtils.delete(testFile); return; } catch (IOException e) { // the test makes only sense if deletion of // a file with open stream fails - } finally { - fis.close(); } FileUtils.delete(testFile); CheckoutCommand co = git.checkout(); @@ -192,15 +189,12 @@ public class CheckoutCommandTest extends RepositoryTestCase { git.checkout().setName("master").call(); assertTrue(testFile.exists()); // lock the file so it can't be deleted (in Windows, that is) - fis = new FileInputStream(testFile); - try { + try (FileInputStream fis = new FileInputStream(testFile)) { assertEquals(Status.NOT_TRIED, co.getResult().getStatus()); co.setName("test").call(); assertTrue(testFile.exists()); assertEquals(Status.NONDELETED, co.getResult().getStatus()); assertTrue(co.getResult().getUndeletedList().contains("Test.txt")); - } finally { - fis.close(); } }