aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/api
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2019-10-15 08:52:39 +0200
committerThomas Wolf <thomas.wolf@paranor.ch>2019-10-15 13:24:30 +0200
commit563ec9ecb671d5b329a71c08ff49e9acd4fa0b33 (patch)
tree51ea209bbc981adb2364798e6fbec892cc23840c /org.eclipse.jgit.test/tst/org/eclipse/jgit/api
parent5e0eca69432c4a382ab6b0d08728f52b1e305a30 (diff)
downloadjgit-563ec9ecb671d5b329a71c08ff49e9acd4fa0b33.tar.gz
jgit-563ec9ecb671d5b329a71c08ff49e9acd4fa0b33.zip
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 <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/api')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java38
1 files changed, 17 insertions, 21 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java
index 47806cb99d..d0dfd1ab92 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java
@@ -142,8 +142,6 @@ public class EolRepositoryTest extends RepositoryTestCase {
protected String CONTENT_MIXED;
- private TreeWalk walk;
-
/** work tree root .gitattributes */
private File dotGitattributes;
@@ -689,27 +687,25 @@ public class EolRepositoryTest extends RepositoryTestCase {
private void collectRepositoryState() throws Exception {
dirCache = db.readDirCache();
- walk = beginWalk();
- if (dotGitattributes != null)
- collectEntryContentAndAttributes(F, ".gitattributes", null);
- collectEntryContentAndAttributes(F, fileCRLF.getName(), entryCRLF);
- collectEntryContentAndAttributes(F, fileLF.getName(), entryLF);
- collectEntryContentAndAttributes(F, fileMixed.getName(), entryMixed);
- endWalk();
- }
-
- private TreeWalk beginWalk() throws Exception {
- TreeWalk newWalk = new TreeWalk(db);
- newWalk.addTree(new FileTreeIterator(db));
- newWalk.addTree(new DirCacheIterator(db.readDirCache()));
- return newWalk;
- }
-
- private void endWalk() throws IOException {
- assertFalse("Not all files tested", walk.next());
+ try (TreeWalk walk = new TreeWalk(db)) {
+ walk.addTree(new FileTreeIterator(db));
+ walk.addTree(new DirCacheIterator(db.readDirCache()));
+ if (dotGitattributes != null) {
+ collectEntryContentAndAttributes(walk, F, ".gitattributes",
+ null);
+ }
+ collectEntryContentAndAttributes(walk, F, fileCRLF.getName(),
+ entryCRLF);
+ collectEntryContentAndAttributes(walk, F, fileLF.getName(),
+ entryLF);
+ collectEntryContentAndAttributes(walk, F, fileMixed.getName(),
+ entryMixed);
+ assertFalse("Not all files tested", walk.next());
+ }
}
- private void collectEntryContentAndAttributes(FileMode type, String pathName,
+ private void collectEntryContentAndAttributes(TreeWalk walk, FileMode type,
+ String pathName,
ActualEntry e) throws IOException {
assertTrue("walk has entry", walk.next());