diff options
author | David Pursehouse <david.pursehouse@sonymobile.com> | 2016-01-22 14:21:15 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@sonymobile.com> | 2016-01-22 14:21:15 +0900 |
commit | ddcbd22cd376754fed73ae1824b924ff5403380d (patch) | |
tree | e9671ee15ce9afbbdb093e9afdefdda25f4af743 | |
parent | 20c2079f70c0150dcda105a6952a73b57c2c4f6a (diff) | |
download | jgit-ddcbd22cd376754fed73ae1824b924ff5403380d.tar.gz jgit-ddcbd22cd376754fed73ae1824b924ff5403380d.zip |
RepositorySetupWorkDirTest: Fix "resource leak" warnings
Use FileRepositoryBuilder to create the Repository, except in cases
where the creation was already in a try-block. Convert those to use
a try-with-resource.
Change-Id: I7d7adeee81bda6e80d91a119c7d690de3d00dc2b
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RepositorySetupWorkDirTest.java | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RepositorySetupWorkDirTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RepositorySetupWorkDirTest.java index 295ef45a79..84c2543c15 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RepositorySetupWorkDirTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RepositorySetupWorkDirTest.java @@ -73,13 +73,14 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { public void testIsBare_CreateRepositoryFromArbitraryGitDir() throws Exception { File gitDir = getFile("workdir"); - assertTrue(new FileRepository(gitDir).isBare()); + Repository repo = new FileRepositoryBuilder().setGitDir(gitDir).build(); + assertTrue(repo.isBare()); } @Test public void testNotBare_CreateRepositoryFromDotGitGitDir() throws Exception { File gitDir = getFile("workdir", Constants.DOT_GIT); - Repository repo = new FileRepository(gitDir); + Repository repo = new FileRepositoryBuilder().setGitDir(gitDir).build(); assertFalse(repo.isBare()); assertWorkdirPath(repo, "workdir"); assertGitdirPath(repo, "workdir", Constants.DOT_GIT); @@ -89,7 +90,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { public void testWorkdirIsParentDir_CreateRepositoryFromDotGitGitDir() throws Exception { File gitDir = getFile("workdir", Constants.DOT_GIT); - Repository repo = new FileRepository(gitDir); + Repository repo = new FileRepositoryBuilder().setGitDir(gitDir).build(); String workdir = repo.getWorkTree().getName(); assertEquals(workdir, "workdir"); } @@ -157,8 +158,8 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { @Test public void testExceptionThrown_BareRepoGetWorkDir() throws Exception { File gitDir = getFile("workdir"); - try { - new FileRepository(gitDir).getWorkTree(); + try (Repository repo = new FileRepository(gitDir)) { + repo.getWorkTree(); fail("Expected NoWorkTreeException missing"); } catch (NoWorkTreeException e) { // expected @@ -168,8 +169,8 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { @Test public void testExceptionThrown_BareRepoGetIndex() throws Exception { File gitDir = getFile("workdir"); - try { - new FileRepository(gitDir).readDirCache(); + try (Repository repo = new FileRepository(gitDir)) { + repo.readDirCache(); fail("Expected NoWorkTreeException missing"); } catch (NoWorkTreeException e) { // expected @@ -179,8 +180,8 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { @Test public void testExceptionThrown_BareRepoGetIndexFile() throws Exception { File gitDir = getFile("workdir"); - try { - new FileRepository(gitDir).getIndexFile(); + try (Repository repo = new FileRepository(gitDir)) { + repo.getIndexFile(); fail("Expected NoWorkTreeException missing"); } catch (NoWorkTreeException e) { // expected |