From 563ec9ecb671d5b329a71c08ff49e9acd4fa0b33 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Tue, 15 Oct 2019 08:52:39 +0200 Subject: Close TreeWalks in tests Note that TreeWalk.forPath() needs not be closed; the ObjectReader _is_ closed when that method returns. Change-Id: I6e022e4a2fde0c88d610a82de092ea541b33f75c Signed-off-by: Thomas Wolf --- .../tst/org/eclipse/jgit/merge/CherryPickTest.java | 48 +++++++++++----------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java index 19f6dcbc59..aa4392fcac 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java @@ -106,23 +106,24 @@ public class CherryPickTest extends RepositoryTestCase { boolean merge = twm.merge(new ObjectId[] { O, T }); assertTrue(merge); - final TreeWalk tw = new TreeWalk(db); - tw.setRecursive(true); - tw.reset(twm.getResultTreeId()); + try (TreeWalk tw = new TreeWalk(db)) { + tw.setRecursive(true); + tw.reset(twm.getResultTreeId()); - assertTrue(tw.next()); - assertEquals("a", tw.getPathString()); - assertCorrectId(treeO, tw); + assertTrue(tw.next()); + assertEquals("a", tw.getPathString()); + assertCorrectId(treeO, tw); - assertTrue(tw.next()); - assertEquals("o", tw.getPathString()); - assertCorrectId(treeO, tw); + assertTrue(tw.next()); + assertEquals("o", tw.getPathString()); + assertCorrectId(treeO, tw); - assertTrue(tw.next()); - assertEquals("t", tw.getPathString()); - assertCorrectId(treeT, tw); + assertTrue(tw.next()); + assertEquals("t", tw.getPathString()); + assertCorrectId(treeT, tw); - assertFalse(tw.next()); + assertFalse(tw.next()); + } } @Test @@ -168,19 +169,20 @@ public class CherryPickTest extends RepositoryTestCase { boolean merge = twm.merge(new ObjectId[] { B, T }); assertTrue(merge); - final TreeWalk tw = new TreeWalk(db); - tw.setRecursive(true); - tw.reset(twm.getResultTreeId()); + try (TreeWalk tw = new TreeWalk(db)) { + tw.setRecursive(true); + tw.reset(twm.getResultTreeId()); - assertTrue(tw.next()); - assertEquals("a", tw.getPathString()); - assertCorrectId(treeB, tw); + assertTrue(tw.next()); + assertEquals("a", tw.getPathString()); + assertCorrectId(treeB, tw); - assertTrue(tw.next()); - assertEquals("t", tw.getPathString()); - assertCorrectId(treeT, tw); + assertTrue(tw.next()); + assertEquals("t", tw.getPathString()); + assertCorrectId(treeT, tw); - assertFalse(tw.next()); + assertFalse(tw.next()); + } } private static void assertCorrectId(DirCache treeT, TreeWalk tw) { -- cgit v1.2.3