Skip to content

Commit

Permalink
Add test for folder filter and fix bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Dec 19, 2024
1 parent 071af3c commit b559499
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3398,7 +3398,7 @@ protected enum NoFolderMatcher implements ElementMatcher<Element> {
* {@inheritDoc}
*/
public boolean matches(@MaybeNull Element target) {
return target == null || target.getName().endsWith("/");
return target == null || !target.getName().endsWith("/");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,30 @@ public void testMultiReleaseFilter() throws Exception {
when(second.getName()).thenReturn(ClassFileLocator.META_INF_VERSIONS + "17/foo/Bar.class");
when(third.getName()).thenReturn(ClassFileLocator.META_INF_VERSIONS + "11/foo/Bar.class");

Plugin.Engine.Source.Origin origin = Plugin.Engine.Source.Filtering.dropMultiReleaseClassFilesAbove(this.source, ClassFileVersion.JAVA_V11).read();
Plugin.Engine.Source.Origin origin = Plugin.Engine.Source.Filtering.dropMultiReleaseClassFilesAbove(source, ClassFileVersion.JAVA_V11).read();
Iterator<Plugin.Engine.Source.Element> iterator = origin.iterator();
assertThat(iterator.hasNext(), is(true));
assertThat(iterator.next(), is(first));
assertThat(iterator.hasNext(), is(true));
assertThat(iterator.next(), is(third));
assertThat(iterator.hasNext(), is(false));
}

@Test
public void testFolderFilter() throws Exception {
when(source.read()).thenReturn(origin);
when(origin.iterator()).thenReturn(Arrays.asList(first, second, third).iterator());

when(first.getName()).thenReturn("foo/");
when(second.getName()).thenReturn("foo/Bar.class");
when(third.getName()).thenReturn("foo/Qux.class");

Plugin.Engine.Source.Origin origin = Plugin.Engine.Source.Filtering.dropFolders(source).read();
Iterator<Plugin.Engine.Source.Element> iterator = origin.iterator();
assertThat(iterator.hasNext(), is(true));
assertThat(iterator.next(), is(second));
assertThat(iterator.hasNext(), is(true));
assertThat(iterator.next(), is(third));
assertThat(iterator.hasNext(), is(false));
}
}

0 comments on commit b559499

Please sign in to comment.