diff options
author | David Pursehouse <david.pursehouse@sonymobile.com> | 2016-02-15 14:49:58 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@sonymobile.com> | 2016-02-15 14:49:58 +0900 |
commit | de73fbf5972589462674c83f4e48ada9037b0405 (patch) | |
tree | ca30206fd3060171b73b5dba51b6a38680864377 | |
parent | 6d33322df42aff5bc25a26f66a19464b46afd826 (diff) | |
download | jgit-de73fbf5972589462674c83f4e48ada9037b0405.tar.gz jgit-de73fbf5972589462674c83f4e48ada9037b0405.zip |
InterIndexDiffFilterTest: Open TreeWalk in try-with-resource
Change-Id: Ie0046771b1ab1c9784d9a3bb597a9d76c6c3017d
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilterTest.java | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilterTest.java index b3aa0ee686..9f0f067326 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilterTest.java @@ -76,10 +76,11 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase { public void testEmpty() throws IOException { DirCache dc1 = DirCache.newInCore(); DirCache dc2 = DirCache.newInCore(); - TreeWalk tw = new TreeWalk(db); - tw.addTree(new DirCacheIterator(dc1)); - tw.addTree(new DirCacheIterator(dc2)); - assertFalse(tw.next()); + try (TreeWalk tw = new TreeWalk(db)) { + tw.addTree(new DirCacheIterator(dc1)); + tw.addTree(new DirCacheIterator(dc2)); + assertFalse(tw.next()); + } } static final class AddEdit extends PathEdit { @@ -124,14 +125,15 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase { editor.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, false)); editor.finish(); - TreeWalk tw = new TreeWalk(db); - tw.setRecursive(true); - tw.addTree(new DirCacheIterator(dc1)); - tw.addTree(new DirCacheIterator(dc2)); - tw.setFilter(InterIndexDiffFilter.INSTANCE); - assertTrue(tw.next()); - assertEquals("a/a", tw.getPathString()); - assertFalse(tw.next()); + try (TreeWalk tw = new TreeWalk(db)) { + tw.setRecursive(true); + tw.addTree(new DirCacheIterator(dc1)); + tw.addTree(new DirCacheIterator(dc2)); + tw.setFilter(InterIndexDiffFilter.INSTANCE); + assertTrue(tw.next()); + assertEquals("a/a", tw.getPathString()); + assertFalse(tw.next()); + } } @Test @@ -145,13 +147,14 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase { ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, false)); ed2.finish(); - TreeWalk tw = new TreeWalk(db); - tw.setRecursive(true); - tw.addTree(new DirCacheIterator(dc1)); - tw.addTree(new DirCacheIterator(dc2)); - tw.setFilter(InterIndexDiffFilter.INSTANCE); + try (TreeWalk tw = new TreeWalk(db)) { + tw.setRecursive(true); + tw.addTree(new DirCacheIterator(dc1)); + tw.addTree(new DirCacheIterator(dc2)); + tw.setFilter(InterIndexDiffFilter.INSTANCE); - assertFalse(tw.next()); + assertFalse(tw.next()); + } } @Test @@ -165,15 +168,16 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase { ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, true)); ed2.finish(); - TreeWalk tw = new TreeWalk(db); - tw.setRecursive(true); - tw.addTree(new DirCacheIterator(dc1)); - tw.addTree(new DirCacheIterator(dc2)); - tw.setFilter(InterIndexDiffFilter.INSTANCE); + try (TreeWalk tw = new TreeWalk(db)) { + tw.setRecursive(true); + tw.addTree(new DirCacheIterator(dc1)); + tw.addTree(new DirCacheIterator(dc2)); + tw.setFilter(InterIndexDiffFilter.INSTANCE); - assertTrue(tw.next()); - assertEquals("a/a", tw.getPathString()); - assertFalse(tw.next()); + assertTrue(tw.next()); + assertEquals("a/a", tw.getPathString()); + assertFalse(tw.next()); + } } @Test @@ -188,12 +192,13 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase { ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("b"), 1, true)); ed2.finish(); - TreeWalk tw = new TreeWalk(db); - tw.setRecursive(true); - tw.addTree(new DirCacheIterator(dc1)); - tw.addTree(new DirCacheIterator(dc2)); - tw.setFilter(InterIndexDiffFilter.INSTANCE); + try (TreeWalk tw = new TreeWalk(db)) { + tw.setRecursive(true); + tw.addTree(new DirCacheIterator(dc1)); + tw.addTree(new DirCacheIterator(dc2)); + tw.setFilter(InterIndexDiffFilter.INSTANCE); - assertFalse(tw.next()); + assertFalse(tw.next()); + } } } |