summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2016-07-04 23:36:33 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2016-07-07 17:36:55 -0400
commit450c0af42fe71f58677330f6982164187dcde5c3 (patch)
treea018b952f9a8ae843ce5f8e156c680d98e41818d /org.eclipse.jgit.test
parent4c25757df75bb845f66f6970c7d9addfa0f09fac (diff)
downloadjgit-450c0af42fe71f58677330f6982164187dcde5c3.tar.gz
jgit-450c0af42fe71f58677330f6982164187dcde5c3.zip
Fix unclosed resource warnings in FileTreeIteratorTest
Change-Id: I75ea7deca64a707cd6b5c61c3c83062f20041684 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java59
1 files changed, 30 insertions, 29 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
index bf1d0e6d23..efb5ddb4e7 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
@@ -286,7 +286,7 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
@Test
public void testTreewalkEnterSubtree() throws Exception {
- try (Git git = new Git(db)) {
+ try (Git git = new Git(db); TreeWalk tw = new TreeWalk(db)) {
writeTrashFile("b/c", "b/c");
writeTrashFile("z/.git", "gitdir: /tmp/somewhere");
git.add().addFilepattern(".").call();
@@ -297,7 +297,6 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
FileUtils.delete(new File(db.getWorkTree(), "b"),
FileUtils.RECURSIVE);
- TreeWalk tw = new TreeWalk(db);
tw.addTree(new DirCacheIterator(db.readDirCache()));
tw.addTree(new FileTreeIterator(db));
assertTrue(tw.next());
@@ -617,39 +616,41 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
public void testCustomFileModeStrategy() throws Exception {
Repository nestedRepo = createNestedRepo();
- Git git = new Git(nestedRepo);
- // validate that our custom strategy is honored
- WorkingTreeIterator customIterator =
- new FileTreeIterator(nestedRepo, NO_GITLINKS_STRATEGY);
- git.add().setWorkingTreeIterator(customIterator)
- .addFilepattern(".").call();
- assertEquals(
- "[sub/a.txt, mode:100644, content:content]" +
- "[sub/nested/b.txt, mode:100644, content:content b]",
- indexState(nestedRepo, CONTENT));
-
+ try (Git git = new Git(nestedRepo)) {
+ // validate that our custom strategy is honored
+ WorkingTreeIterator customIterator = new FileTreeIterator(
+ nestedRepo, NO_GITLINKS_STRATEGY);
+ git.add().setWorkingTreeIterator(customIterator).addFilepattern(".")
+ .call();
+ assertEquals(
+ "[sub/a.txt, mode:100644, content:content]"
+ + "[sub/nested/b.txt, mode:100644, content:content b]",
+ indexState(nestedRepo, CONTENT));
+ }
}
@Test
public void testCustomFileModeStrategyFromParentIterator() throws Exception {
Repository nestedRepo = createNestedRepo();
- Git git = new Git(nestedRepo);
-
- FileTreeIterator customIterator =
- new FileTreeIterator(nestedRepo, NO_GITLINKS_STRATEGY);
- File r = new File(nestedRepo.getWorkTree(), "sub");
-
- // here we want to validate that if we create a new iterator using the
- // constructor that accepts a parent iterator, that the child iterator
- // correctly inherits the FileModeStrategy from the parent iterator.
- FileTreeIterator childIterator =
- new FileTreeIterator(customIterator, r, nestedRepo.getFS());
- git.add().setWorkingTreeIterator(childIterator).addFilepattern(".").call();
- assertEquals(
- "[sub/a.txt, mode:100644, content:content]" +
- "[sub/nested/b.txt, mode:100644, content:content b]",
- indexState(nestedRepo, CONTENT));
+ try (Git git = new Git(nestedRepo)) {
+ FileTreeIterator customIterator = new FileTreeIterator(nestedRepo,
+ NO_GITLINKS_STRATEGY);
+ File r = new File(nestedRepo.getWorkTree(), "sub");
+
+ // here we want to validate that if we create a new iterator using
+ // the constructor that accepts a parent iterator, that the child
+ // iterator correctly inherits the FileModeStrategy from the parent
+ // iterator.
+ FileTreeIterator childIterator = new FileTreeIterator(
+ customIterator, r, nestedRepo.getFS());
+ git.add().setWorkingTreeIterator(childIterator).addFilepattern(".")
+ .call();
+ assertEquals(
+ "[sub/a.txt, mode:100644, content:content]"
+ + "[sub/nested/b.txt, mode:100644, content:content b]",
+ indexState(nestedRepo, CONTENT));
+ }
}