From 6503a67e46108ebd6bc07a518ea28310f7223038 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 21 Jan 2019 13:40:48 +0900 Subject: [PATCH] SubmoduleWalkTest: Open Repository in try-with-resource Change-Id: I9c4ee4e4c55f48db1f21e18b212657e4dd3de053 Signed-off-by: David Pursehouse --- .../jgit/submodule/SubmoduleWalkTest.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java index a0cd37ee5..ea1ace364 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java @@ -145,7 +145,6 @@ public class SubmoduleWalkTest extends RepositoryTestCase { assertFalse(gen.next()); } - @SuppressWarnings("resource" /* java 7 */) @Test public void repositoryWithRootLevelSubmoduleAbsoluteRef() throws IOException, ConfigInvalidException { @@ -189,17 +188,16 @@ public class SubmoduleWalkTest extends RepositoryTestCase { assertNull(gen.getModulesPath()); assertNull(gen.getModulesUpdate()); assertNull(gen.getModulesUrl()); - Repository subRepo = gen.getRepository(); - assertNotNull(subRepo); - assertEquals(modulesGitDir.getAbsolutePath(), - subRepo.getDirectory().getAbsolutePath()); - assertEquals(new File(db.getWorkTree(), path).getAbsolutePath(), - subRepo.getWorkTree().getAbsolutePath()); - subRepo.close(); + try (Repository subRepo = gen.getRepository()) { + assertNotNull(subRepo); + assertEquals(modulesGitDir.getAbsolutePath(), + subRepo.getDirectory().getAbsolutePath()); + assertEquals(new File(db.getWorkTree(), path).getAbsolutePath(), + subRepo.getWorkTree().getAbsolutePath()); + } assertFalse(gen.next()); } - @SuppressWarnings("resource" /* java 7 */) @Test public void repositoryWithRootLevelSubmoduleRelativeRef() throws IOException, ConfigInvalidException { @@ -244,13 +242,14 @@ public class SubmoduleWalkTest extends RepositoryTestCase { assertNull(gen.getModulesPath()); assertNull(gen.getModulesUpdate()); assertNull(gen.getModulesUrl()); - Repository subRepo = gen.getRepository(); - assertNotNull(subRepo); - assertEqualsFile(modulesGitDir, subRepo.getDirectory()); - assertEqualsFile(new File(db.getWorkTree(), path), - subRepo.getWorkTree()); - subRepo.close(); - assertFalse(gen.next()); + try (Repository subRepo = gen.getRepository()) { + assertNotNull(subRepo); + assertEqualsFile(modulesGitDir, subRepo.getDirectory()); + assertEqualsFile(new File(db.getWorkTree(), path), + subRepo.getWorkTree()); + subRepo.close(); + assertFalse(gen.next()); + } } @Test