Search in sources :

Example 26 with FilterBuilder

use of org.reflections.util.FilterBuilder in project metron by apache.

the class ClasspathFunctionResolverTest method testInvalidStellarClass.

@Test
public void testInvalidStellarClass() {
    StellarFunction goodFunc = mock(StellarFunction.class);
    StellarFunction badFunc = mock(StellarFunction.class);
    ClasspathFunctionResolver resolver = new ClasspathFunctionResolver() {

        @Override
        protected Iterable<Class<?>> getStellarClasses(ClassLoader cl) {
            return ImmutableList.of(goodFunc.getClass(), badFunc.getClass());
        }

        @Override
        protected boolean includeClass(Class<?> c, FilterBuilder filterBuilder) {
            if (c != goodFunc.getClass()) {
                throw new LinkageError("failed!");
            }
            return true;
        }
    };
    Set<Class<? extends StellarFunction>> funcs = resolver.resolvables();
    assertEquals(1, funcs.size());
    assertEquals(goodFunc.getClass(), Iterables.getFirst(funcs, null));
}
Also used : StellarFunction(org.apache.metron.stellar.dsl.StellarFunction) FilterBuilder(org.reflections.util.FilterBuilder) Test(org.junit.jupiter.api.Test)

Example 27 with FilterBuilder

use of org.reflections.util.FilterBuilder in project reflections by ronmamo.

the class FilterBuilderTest method test_excludePackage.

@Test
public void test_excludePackage() {
    FilterBuilder filter = new FilterBuilder().excludePackage("org.reflections");
    assertFalse(filter.apply("org.reflections.Reflections"));
    assertFalse(filter.apply("org.reflections.foo.Reflections"));
    assertTrue(filter.apply("org.foobar.Reflections"));
}
Also used : FilterBuilder(org.reflections.util.FilterBuilder) Test(org.junit.Test)

Example 28 with FilterBuilder

use of org.reflections.util.FilterBuilder in project reflections by ronmamo.

the class FilterBuilderTest method test_parsePackages_exclude.

@Test
public void test_parsePackages_exclude() {
    FilterBuilder filter = FilterBuilder.parsePackages("-org.reflections");
    assertFalse(filter.apply("org.reflections.Reflections"));
    assertFalse(filter.apply("org.reflections.foo.Reflections"));
    assertTrue(filter.apply("org.foobar.Reflections"));
    assertTrue(filter.apply("org.reflectionsplus.Reflections"));
}
Also used : FilterBuilder(org.reflections.util.FilterBuilder) Test(org.junit.Test)

Example 29 with FilterBuilder

use of org.reflections.util.FilterBuilder in project reflections by ronmamo.

the class FilterBuilderTest method test_parse_exclude_notRegex.

@Test
public void test_parse_exclude_notRegex() {
    FilterBuilder filter = FilterBuilder.parse("-org.reflections");
    assertTrue(filter.apply("org.reflections.Reflections"));
    assertTrue(filter.apply("org.reflections.foo.Reflections"));
    assertTrue(filter.apply("org.foobar.Reflections"));
    assertTrue(filter.apply("org.reflectionsplus.Reflections"));
}
Also used : FilterBuilder(org.reflections.util.FilterBuilder) Test(org.junit.Test)

Example 30 with FilterBuilder

use of org.reflections.util.FilterBuilder in project reflections by ronmamo.

the class FilterBuilderTest method test_parsePackages_exclude_trailingDot.

@Test
public void test_parsePackages_exclude_trailingDot() {
    FilterBuilder filter = FilterBuilder.parsePackages("-org.reflections.");
    assertFalse(filter.apply("org.reflections.Reflections"));
    assertFalse(filter.apply("org.reflections.foo.Reflections"));
    assertTrue(filter.apply("org.foobar.Reflections"));
    assertTrue(filter.apply("org.reflectionsplus.Reflections"));
}
Also used : FilterBuilder(org.reflections.util.FilterBuilder) Test(org.junit.Test)

Aggregations

FilterBuilder (org.reflections.util.FilterBuilder)46 ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)23 Reflections (org.reflections.Reflections)19 Test (org.junit.Test)17 SubTypesScanner (org.reflections.scanners.SubTypesScanner)9 ResourcesScanner (org.reflections.scanners.ResourcesScanner)8 Test (org.junit.jupiter.api.Test)7 ArrayList (java.util.ArrayList)6 URL (java.net.URL)4 lombok.val (lombok.val)4 Field (java.lang.reflect.Field)2 Collection (java.util.Collection)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Set (java.util.Set)2 BeforeClass (org.junit.BeforeClass)2 MethodAnnotationsScanner (org.reflections.scanners.MethodAnnotationsScanner)2 TypeAnnotationsScanner (org.reflections.scanners.TypeAnnotationsScanner)2 ClasspathHelper (org.reflections.util.ClasspathHelper)2 Stopwatch (com.google.common.base.Stopwatch)1