gmuecke / reflections

Automatically exported from code.google.com/p/reflections
Do What The F*ck You Want To Public License
0 stars 0 forks source link

getSubTypesOf picks up the test classes that are testing the implementation instances #120

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Reflections reflections = new Reflections(new ConfigurationBuilder()
                .filterInputsBy(new FilterBuilder().includePackage(this.getClass()))
                .setUrls(ClasspathHelper.forPackage(this.getClass().getPackage().getName()))
                .setScanners(new SubTypesScanner()));
Set<Class<? extends IValidator>> validations = 
reflections.getSubTypesOf(IValidator.class);

The above code picks up all the proper classes that implement the IValidator 
class in the package defined, but 
it also picks up the test cases for the classes that implement the IValidator 
class. They are in the same package
but in a different area of the hierarchy. The test cases do not implement the 
IValidator class but they do
instantiate objects that do. That should not affect the list of classes that I 
expect.

tried it in 0.9.6 and 0.9.8

I expect to only see the classes that implement IValidator.class. 
I can change to 
Reflections reflections = new Reflections(new ConfigurationBuilder()
                .filterInputsBy(new FilterBuilder().includePackage(this.getClass()).exclude(".*Test.*"))
                .setUrls(ClasspathHelper.forPackage(this.getClass().getPackage().getName()))
                .setScanners(new SubTypesScanner()));
but that seems like a hack.                

Original issue reported on code.google.com by jayr...@gmail.com on 26 Jun 2012 at 7:17

GoogleCodeExporter commented 8 years ago
Only happens when running in a certain eclipse environment. Does not occur when 
running the test cases from the command line outside of the IDE. :(

Original comment by jayr...@gmail.com on 26 Jun 2012 at 7:32

GoogleCodeExporter commented 8 years ago
choose you urls carefully, know your classpath

Original comment by ronm...@gmail.com on 20 Feb 2013 at 9:07