Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java59
1 files changed, 33 insertions, 26 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
index 36b5c27886..1bf1e586df 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
@@ -366,14 +366,16 @@ public class TestUtil {
Set<String> expectedfiles = new HashSet<String>();
for (String path : paths)
expectedfiles.add(path);
- TreeWalk treeWalk = new TreeWalk(repository);
- treeWalk.addTree(repository.resolve("HEAD^{tree}"));
- treeWalk.setRecursive(true);
- while (treeWalk.next()) {
- String path = treeWalk.getPathString();
- if (!expectedfiles.contains(path))
- fail("Repository contains unexpected expected file " + path);
- expectedfiles.remove(path);
+ try (TreeWalk treeWalk = new TreeWalk(repository)) {
+ treeWalk.addTree(repository.resolve("HEAD^{tree}"));
+ treeWalk.setRecursive(true);
+ while (treeWalk.next()) {
+ String path = treeWalk.getPathString();
+ if (!expectedfiles.contains(path))
+ fail("Repository contains unexpected expected file "
+ + path);
+ expectedfiles.remove(path);
+ }
}
if (expectedfiles.size() > 0) {
StringBuilder message = new StringBuilder(
@@ -401,22 +403,24 @@ public class TestUtil {
public static void assertRepositoryContainsFilesWithContent(Repository repository,
String... args) throws Exception {
HashMap<String, String> expectedfiles = mkmap(args);
- TreeWalk treeWalk = new TreeWalk(repository);
- treeWalk.addTree(repository.resolve("HEAD^{tree}"));
- treeWalk.setRecursive(true);
- while (treeWalk.next()) {
- String path = treeWalk.getPathString();
- assertTrue(expectedfiles.containsKey(path));
- ObjectId objectId = treeWalk.getObjectId(0);
- byte[] expectedContent = expectedfiles.get(path).getBytes("UTF-8");
- byte[] repoContent = treeWalk.getObjectReader().open(objectId)
- .getBytes();
- if (!Arrays.equals(repoContent, expectedContent))
- fail("File " + path + " has repository content "
- + new String(repoContent, "UTF-8")
- + " instead of expected content "
- + new String(expectedContent, "UTF-8"));
- expectedfiles.remove(path);
+ try (TreeWalk treeWalk = new TreeWalk(repository)) {
+ treeWalk.addTree(repository.resolve("HEAD^{tree}"));
+ treeWalk.setRecursive(true);
+ while (treeWalk.next()) {
+ String path = treeWalk.getPathString();
+ assertTrue(expectedfiles.containsKey(path));
+ ObjectId objectId = treeWalk.getObjectId(0);
+ byte[] expectedContent = expectedfiles.get(path)
+ .getBytes("UTF-8");
+ byte[] repoContent = treeWalk.getObjectReader().open(objectId)
+ .getBytes();
+ if (!Arrays.equals(repoContent, expectedContent))
+ fail("File " + path + " has repository content "
+ + new String(repoContent, "UTF-8")
+ + " instead of expected content "
+ + new String(expectedContent, "UTF-8"));
+ expectedfiles.remove(path);
+ }
}
if (expectedfiles.size() > 0) {
StringBuilder message = new StringBuilder(
@@ -510,8 +514,11 @@ public class TestUtil {
throws Exception {
RevCommit headCommit = null;
ObjectId parentId = repository.resolve(Constants.HEAD);
- if (parentId != null)
- headCommit = new RevWalk(repository).parseCommit(parentId);
+ if (parentId != null) {
+ try (RevWalk rw = new RevWalk(repository)) {
+ headCommit = rw.parseCommit(parentId);
+ }
+ }
return headCommit;
}

Back to the top