mardi 13 octobre 2020

org.reflections.Reflections > ConfigurationBuilder.filterByInput() is not filtering the regex provided in the FilterBuilder.exclude()

Problem Statement:

I want to filter the classes that have methods annotated with @Test annotation My project has these two packages com.sidhant.automata.products.ema.fhir.tests.WhateverTest.java com.sidhant.automata.products.ema.fhir.macros.WhateverTest.java

But i want to exclude the package com.sidhant.automata.products.ema.fhir.macros

this is the code i have written

Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(BASE_PACKAGE)).addScanners(new MethodAnnotationsScanner()).filterInputsBy(new FilterBuilder().exclude("(com.sidhant.automata)(\.)(?!products.*\.tests\.)\S+")));
HashSet<Class<?>> allTests = reflections.getMethodsAnnotatedWith(Test.class)
            .stream()
            .map(Method::getDeclaringClass)
            .filter(this::includeTest).collect(Collectors.toCollection(HashSet::new));
//Printing the filtered classes
allTests.forEach(System.out::println);

//output

com.sidhant.automata.products.ema.fhir.macros.WhateverTest com.sidhant.automata.products.ema.fhir.tests.WhateverTest

whereas the expected output should be: com.sidhant.automata.products.ema.fhir.tests.WhateverTest

Can you let me know what is the mistake in the code





Aucun commentaire:

Enregistrer un commentaire