aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorXing Huang <xingkhuang@google.com>2024-03-15 15:19:15 -0500
committerXing Huang <xingkhuang@google.com>2024-03-18 10:51:11 -0500
commit9e841dd4ac8435b97333c380eaa34e7bf01be97e (patch)
treea0c18e35dccc151b601885ab02cca0223b20a5b4 /org.eclipse.jgit.test
parentc1eba8abe04493ceb9b30c4f747fb0255c4f28e1 (diff)
downloadjgit-9e841dd4ac8435b97333c380eaa34e7bf01be97e.tar.gz
jgit-9e841dd4ac8435b97333c380eaa34e7bf01be97e.zip
PathFilterGroup: implement getPathsBestEffort()
getPathsBestEffort() is a method in the TreeFilter class to retrieve file paths specified by the caller. PathFilterGroup do not propagate the paths of their subfilters as it does not implement the getPathsBestEffort() method, resulting in the caller only getting an empty list of paths. Override getPathsBestEffort() in PathFilterGroup to propagate subfilter values. Signed-off-by: Xing Huang <xingkhuang@google.com> Change-Id: I76bf08795360abc0874a7c258636d4f37da35060
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java
index 32bd40312f..1bb4939c85 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java
@@ -11,6 +11,7 @@
package org.eclipse.jgit.treewalk.filter;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -21,7 +22,9 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEditor;
@@ -30,6 +33,7 @@ import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.StopWalkException;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Sets;
@@ -143,6 +147,29 @@ public class PathFilterGroupTest {
}
@Test
+ public void testGetPathsBestEffort() {
+ String[] paths = { "path1", "path2", "path3" };
+ Set<byte[]> expected = Arrays.stream(paths).map(Constants::encode)
+ .collect(Collectors.toSet());
+ TreeFilter pathFilterGroup = PathFilterGroup.createFromStrings(paths);
+ Optional<Set<byte[]>> bestEffortPaths = pathFilterGroup
+ .getPathsBestEffort();
+ assertTrue(bestEffortPaths.isPresent());
+ Set<byte[]> actual = bestEffortPaths.get();
+ assertEquals(expected.size(), actual.size());
+ for (byte[] actualPath : actual) {
+ boolean findMatch = false;
+ for (byte[] expectedPath : expected) {
+ if (Arrays.equals(actualPath, expectedPath)) {
+ findMatch = true;
+ break;
+ }
+ }
+ assertTrue(findMatch);
+ }
+ }
+
+ @Test
public void testStopWalk() throws MissingObjectException,
IncorrectObjectTypeException, IOException {
// Obvious