NodeNameInFilter implements NodeFilter { @Override public boolean isAccepted(Node node) { return wildcards.stream().anyMatch(p -> nameMatcher.matches(p, node.getName())); } NodeNameInFilter(String... patterns); final NodeNameInFilter addFilter(String... patterns); @Override boolean isAccepted(Node node);  }
@Test public void testFilterPlain() { NodeNameInFilter filter = new NodeNameInFilter("x*"); assertThat(filter.isAccepted(new Node("x1")), is(true)); assertThat(filter.isAccepted(new Node("x219")), is(true)); assertThat(filter.isAccepted(new Node("foo")), is(false)); }
@Test public void testFilterWithPackageNames() { NodeNameInFilter filter = new NodeNameInFilter("foo.*"); assertThat(filter.isAccepted(new Node("foo.bar")), is(true)); assertThat(filter.isAccepted(new Node("other.foo.bar")), is(false)); }
@Test public void testFilterMultipleNames() { NodeNameInFilter filter = new NodeNameInFilter("a.**", "b.*", "c.*"); assertThat(filter.isAccepted(new Node("a.Clazz")), is(true)); assertThat(filter.isAccepted(new Node("b.Clazz")), is(true)); assertThat(filter.isAccepted(new Node("c.Clazz")), is(true)); assertThat(filter.isAccepted(new Node("a.my.Clazz")), is(true)); assertThat(filter.isAccepted(new Node("other.Clazz")), is(false)); }
@Test(expected = NullPointerException.class) public void testNullInput() { assertThat(new NodeNameInFilter("x*").isAccepted(null), is(false)); }