diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2019-10-15 00:58:27 +0200 |
---|---|---|
committer | Thomas Wolf <thomas.wolf@paranor.ch> | 2019-10-15 08:54:25 +0200 |
commit | 5e0eca69432c4a382ab6b0d08728f52b1e305a30 (patch) | |
tree | 4e322c03d313c39b7ecc9cd1bded6cadf1013638 /org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleInitTest.java | |
parent | 36e16435bed5ba457f6d709643acc93505e99d2c (diff) | |
download | jgit-5e0eca69432c4a382ab6b0d08728f52b1e305a30.tar.gz jgit-5e0eca69432c4a382ab6b0d08728f52b1e305a30.zip |
Close SubmoduleWalks in tests
Change-Id: If1b9d80830b6b136d4ab33f5c7043b140bd92f85
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleInitTest.java')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleInitTest.java | 106 |
1 files changed, 56 insertions, 50 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleInitTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleInitTest.java index c7a009c5bf..9fe2fc6fdc 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleInitTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleInitTest.java @@ -86,11 +86,11 @@ public class SubmoduleInitTest extends RepositoryTestCase { ConfigInvalidException, GitAPIException { final String path = addSubmoduleToIndex(); - SubmoduleWalk generator = SubmoduleWalk.forIndex(db); - assertTrue(generator.next()); - assertNull(generator.getConfigUrl()); - assertNull(generator.getConfigUpdate()); - + try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) { + assertTrue(generator.next()); + assertNull(generator.getConfigUrl()); + assertNull(generator.getConfigUpdate()); + } FileBasedConfig modulesConfig = new FileBasedConfig(new File( db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, @@ -109,10 +109,11 @@ public class SubmoduleInitTest extends RepositoryTestCase { assertEquals(1, modules.size()); assertEquals(path, modules.iterator().next()); - generator = SubmoduleWalk.forIndex(db); - assertTrue(generator.next()); - assertEquals(url, generator.getConfigUrl()); - assertEquals(update, generator.getConfigUpdate()); + try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) { + assertTrue(generator.next()); + assertEquals(url, generator.getConfigUrl()); + assertEquals(update, generator.getConfigUpdate()); + } } @Test @@ -126,11 +127,11 @@ public class SubmoduleInitTest extends RepositoryTestCase { base); config.save(); - SubmoduleWalk generator = SubmoduleWalk.forIndex(db); - assertTrue(generator.next()); - assertNull(generator.getConfigUrl()); - assertNull(generator.getConfigUpdate()); - + try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) { + assertTrue(generator.next()); + assertNull(generator.getConfigUrl()); + assertNull(generator.getConfigUpdate()); + } FileBasedConfig modulesConfig = new FileBasedConfig(new File( db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, @@ -149,10 +150,12 @@ public class SubmoduleInitTest extends RepositoryTestCase { assertEquals(1, modules.size()); assertEquals(path, modules.iterator().next()); - generator = SubmoduleWalk.forIndex(db); - assertTrue(generator.next()); - assertEquals("git://server/repo.git/sub.git", generator.getConfigUrl()); - assertEquals(update, generator.getConfigUpdate()); + try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) { + assertTrue(generator.next()); + assertEquals("git://server/repo.git/sub.git", + generator.getConfigUrl()); + assertEquals(update, generator.getConfigUpdate()); + } } @Test @@ -167,11 +170,11 @@ public class SubmoduleInitTest extends RepositoryTestCase { base); config.save(); - SubmoduleWalk generator = SubmoduleWalk.forIndex(db); - assertTrue(generator.next()); - assertNull(generator.getConfigUrl()); - assertNull(generator.getConfigUpdate()); - + try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) { + assertTrue(generator.next()); + assertNull(generator.getConfigUrl()); + assertNull(generator.getConfigUpdate()); + } FileBasedConfig modulesConfig = new FileBasedConfig(new File( db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, @@ -190,10 +193,11 @@ public class SubmoduleInitTest extends RepositoryTestCase { assertEquals(1, modules.size()); assertEquals(path, modules.iterator().next()); - generator = SubmoduleWalk.forIndex(db); - assertTrue(generator.next()); - assertEquals("git://server/sub.git", generator.getConfigUrl()); - assertEquals(update, generator.getConfigUpdate()); + try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) { + assertTrue(generator.next()); + assertEquals("git://server/sub.git", generator.getConfigUrl()); + assertEquals(update, generator.getConfigUpdate()); + } } @Test @@ -208,11 +212,11 @@ public class SubmoduleInitTest extends RepositoryTestCase { base); config.save(); - SubmoduleWalk generator = SubmoduleWalk.forIndex(db); - assertTrue(generator.next()); - assertNull(generator.getConfigUrl()); - assertNull(generator.getConfigUpdate()); - + try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) { + assertTrue(generator.next()); + assertNull(generator.getConfigUrl()); + assertNull(generator.getConfigUpdate()); + } FileBasedConfig modulesConfig = new FileBasedConfig(new File( db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, @@ -231,10 +235,11 @@ public class SubmoduleInitTest extends RepositoryTestCase { assertEquals(1, modules.size()); assertEquals(path, modules.iterator().next()); - generator = SubmoduleWalk.forIndex(db); - assertTrue(generator.next()); - assertEquals("git://server2/sub.git", generator.getConfigUrl()); - assertEquals(update, generator.getConfigUpdate()); + try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) { + assertTrue(generator.next()); + assertEquals("git://server2/sub.git", generator.getConfigUrl()); + assertEquals(update, generator.getConfigUpdate()); + } } @Test @@ -250,11 +255,11 @@ public class SubmoduleInitTest extends RepositoryTestCase { Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL); config.save(); - SubmoduleWalk generator = SubmoduleWalk.forIndex(db); - assertTrue(generator.next()); - assertNull(generator.getConfigUrl()); - assertNull(generator.getConfigUpdate()); - + try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) { + assertTrue(generator.next()); + assertNull(generator.getConfigUrl()); + assertNull(generator.getConfigUpdate()); + } FileBasedConfig modulesConfig = new FileBasedConfig(new File( db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, @@ -273,10 +278,11 @@ public class SubmoduleInitTest extends RepositoryTestCase { assertEquals(1, modules.size()); assertEquals(path, modules.iterator().next()); - generator = SubmoduleWalk.forIndex(db); - assertTrue(generator.next()); - assertEquals(base + "/sub.git", generator.getConfigUrl()); - assertEquals(update, generator.getConfigUpdate()); + try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) { + assertTrue(generator.next()); + assertEquals(base + "/sub.git", generator.getConfigUrl()); + assertEquals(update, generator.getConfigUpdate()); + } } @Test @@ -291,11 +297,11 @@ public class SubmoduleInitTest extends RepositoryTestCase { base); config.save(); - SubmoduleWalk generator = SubmoduleWalk.forIndex(db); - assertTrue(generator.next()); - assertNull(generator.getConfigUrl()); - assertNull(generator.getConfigUpdate()); - + try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) { + assertTrue(generator.next()); + assertNull(generator.getConfigUrl()); + assertNull(generator.getConfigUpdate()); + } FileBasedConfig modulesConfig = new FileBasedConfig(new File( db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, |