com.openpojo.reflection.PojoClassFilter Java Examples
The following examples show how to use
com.openpojo.reflection.PojoClassFilter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BeanTest.java From openpojo with Apache License 2.0 | 6 votes |
@Before public void setup() { LogHelper.initializeLoggers(); PojoClassFilter pojoClassFilter = new FilterChain(new FilterEnum(), new FilterPackageInfo()); pojoClasses = PojoClassFactory.getPojoClassesRecursively(this.getClass().getPackage().getName() + ".sampleclasses", pojoClassFilter); ValidatorBuilder validatorBuilder = ValidatorBuilder.create(); // Create Rules to validate structure for POJO_PACKAGE validatorBuilder.with(new NoPublicFieldsRule()); validatorBuilder.with(new NoStaticExceptFinalRule()); validatorBuilder.with(new GetterMustExistRule()); validatorBuilder.with(new SetterMustExistRule()); // Create Testers to validate behaviour for POJO_PACKAGE validatorBuilder.with(new DefaultValuesNullTester()); validatorBuilder.with(new SetterTester()); validatorBuilder.with(new GetterTester()); pojoValidator = validatorBuilder.build(); }
Example #2
Source File: OpenPojoTest.java From tessera with Apache License 2.0 | 6 votes |
@Test public void executeOpenPojoValidations() { final Validator pojoValidator = ValidatorBuilder.create() .with(new GetterMustExistRule()) .with(new GetterTester()) .with(new SetterTester()) .build(); final PojoClassFilter[] filters = new PojoClassFilter[] { pc -> !pc.getClazz().getName().contains(KeyVaultConfigTest.class.getSimpleName()), pc -> !pc.getClazz().isAssignableFrom(ObjectFactory.class), pc -> !pc.getClazz().getName().startsWith(JaxbConfigFactory.class.getName()), pc -> !pc.getClazz().isAssignableFrom(ConfigException.class), pc -> !pc.getClazz().getName().contains(ConfigItem.class.getName()), pc -> !pc.getClazz().getSimpleName().contains("Test"), pc -> !pc.isNestedClass() }; pojoValidator.validate("com.quorum.tessera.config", filters); }
Example #3
Source File: DefaultPojoClassLookupService.java From openpojo with Apache License 2.0 | 6 votes |
public List<PojoClass> getPojoClassesRecursively(final String packageName, final PojoClassFilter pojoClassFilter) { final List<PojoClass> pojoClasses = new LinkedList<PojoClass>(); final PojoClassFilter finalFilterChain = getFinalFilterChain(pojoClassFilter); final PojoPackage pojoPackage = PojoPackageFactory.getPojoPackage(packageName); Queue<PojoPackage> pending = new ConcurrentLinkedQueue<PojoPackage>(); pending.add(pojoPackage); while (!pending.isEmpty()) { final PojoPackage entry = pending.remove(); pending.addAll(entry.getPojoSubPackages()); pojoClasses.addAll(entry.getPojoClasses(finalFilterChain)); } return pojoClasses; }
Example #4
Source File: FilterNonConcreteTest.java From openpojo with Apache License 2.0 | 6 votes |
@Test public void testInclude() { PojoClassFilter pojoClassFilter = new FilterNonConcrete(); PojoClass stubPojoClass = PojoStubFactory.getStubPojoClass(false); Affirm.affirmTrue(String.format("Filter[%s] was supposed to filter OUT non concrete class", pojoClassFilter), stubPojoClass .isConcrete() == pojoClassFilter.include(stubPojoClass)); stubPojoClass = PojoStubFactory.getStubPojoClass(true); Affirm.affirmTrue(String.format("Filter[%s] was supposed to filter IN concrete class", pojoClassFilter), stubPojoClass.isConcrete() == pojoClassFilter.include(stubPojoClass)); final StubPojoClassFilter stubPojoClassFilter = new StubPojoClassFilter(); pojoClassFilter = new FilterChain(new FilterNonConcrete(), stubPojoClassFilter); stubPojoClass = PojoStubFactory.getStubPojoClass(true); pojoClassFilter.include(stubPojoClass); Affirm.affirmTrue(String.format("Filter [%s] didn't invoke next in filter chain", pojoClassFilter), stubPojoClassFilter .includeCalled); }
Example #5
Source File: FilterChainTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void oneOneFilterAdded_FilterChainHasOneFilter() { PojoClassFilter dummyFilter = new DummyPojoClassFilter(); FilterChain filter = new FilterChain(dummyFilter); Assert.assertEquals(1, filter.size()); Assert.assertTrue(filter.getPojoClassFilters().contains(dummyFilter)); }
Example #6
Source File: FilterChainTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void addingArrayWithNullFilters_ignored() { PojoClassFilter dummyFilter = new DummyPojoClassFilter(); FilterChain filter = new FilterChain(dummyFilter, null); Assert.assertEquals(1, filter.size()); Assert.assertTrue(filter.getPojoClassFilters().contains(dummyFilter)); }
Example #7
Source File: GetterTesterAndSetterTesterTest.java From openpojo with Apache License 2.0 | 5 votes |
private List<PojoClass> getBadPojoClasses() { return PojoClassFactory.getPojoClassesRecursively(TESTPACKAGE, new PojoClassFilter() { public boolean include(final PojoClass pojoClass) { return pojoClass.getClazz().getSimpleName().startsWith("Bad_"); } }); }
Example #8
Source File: DefaultPojoClassLookupService.java From openpojo with Apache License 2.0 | 5 votes |
public List<PojoClass> enumerateClassesByExtendingType(final String packageName, final Class<?> type, final PojoClassFilter pojoClassFilter) { final FilterBasedOnInheritance inheritanceFilter = new FilterBasedOnInheritance(type); final FilterChain filterChain = new FilterChain(inheritanceFilter, pojoClassFilter); return getPojoClassesRecursively(packageName, filterChain); }
Example #9
Source File: GetterTesterAndSetterTesterTest.java From openpojo with Apache License 2.0 | 5 votes |
private List<PojoClass> getGoodPojoClasses() { return PojoClassFactory.getPojoClasses(TESTPACKAGE, new PojoClassFilter() { public boolean include(PojoClass pojoClass) { return pojoClass.getClazz().getSimpleName().startsWith("Good_"); } }); }
Example #10
Source File: FilterClassNameTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void testShouldExcludeFileName() { // Include only class names that are in the format of xSample final PojoClassFilter filter = new FilterClassName(".+Sample$"); final String[] classNames = new String[] { "packagepath.packageSample.MyClass", "SampleClass", "Sample", "sample", "Somesample", "someSampleClass" }; for (final String className : classNames) { PojoClass pojoClassStub = PojoStubFactory.getStubPojoClass(className); Affirm.affirmFalse(String.format("[%s] didn't exclude class [%s]!!", filter, className), filter.include(pojoClassStub)); } }
Example #11
Source File: FilterChain.java From openpojo with Apache License 2.0 | 5 votes |
public boolean include(final PojoClass pojoClass) { for (PojoClassFilter pojoClassFilter : pojoClassFilters) { if (!pojoClassFilter.include(pojoClass)) return false; } return true; }
Example #12
Source File: FilterChain.java From openpojo with Apache License 2.0 | 5 votes |
public FilterChain(final PojoClassFilter... pojoClassFilters) { if (pojoClassFilters != null) for (PojoClassFilter pojoClassFilter : pojoClassFilters) { if (pojoClassFilter != null) { this.pojoClassFilters.add(pojoClassFilter); } } }
Example #13
Source File: PojoClassCoverageFilter.java From openpojo with Apache License 2.0 | 5 votes |
public boolean include(PojoClass pojoClass) { for (PojoClassFilter filter : filters) { if (!filter.include(pojoClass)) return false; } return true; }
Example #14
Source File: PojoPackageImpl.java From openpojo with Apache License 2.0 | 5 votes |
public List<PojoClass> getPojoClasses(final PojoClassFilter filter) { List<PojoClass> pojoClasses = new LinkedList<PojoClass>(); for (Type type : jdkPackage.getTypes()) { PojoClass pojoClass = PojoClassFactory.getPojoClass((Class<?>) type); if (pojoClass != null && (filter == null || filter.include(pojoClass))) { pojoClasses.add(pojoClass); } } return pojoClasses; }
Example #15
Source File: FilterChainTest.java From openpojo with Apache License 2.0 | 4 votes |
@Test public void filterChain_shouldIgonreNullFilterArray() { FilterChain filter = new FilterChain((PojoClassFilter[]) null); Assert.assertEquals(0, filter.size()); }
Example #16
Source File: FilterChain.java From openpojo with Apache License 2.0 | 4 votes |
public Collection<PojoClassFilter> getPojoClassFilters() { return Collections.unmodifiableSet(pojoClassFilters); }
Example #17
Source File: Cobertura.java From openpojo with Apache License 2.0 | 4 votes |
@Override public PojoClassFilter getPojoClassFilter() { return null; }
Example #18
Source File: Clover3.java From openpojo with Apache License 2.0 | 4 votes |
@Override public PojoClassFilter getPojoClassFilter() { return FilterCloverClasses.getInstance(); }
Example #19
Source File: Jacoco.java From openpojo with Apache License 2.0 | 4 votes |
@Override public PojoClassFilter getPojoClassFilter() { return null; }
Example #20
Source File: DefaultValidator.java From openpojo with Apache License 2.0 | 4 votes |
public List<PojoClass> validate(String packageName, PojoClassFilter... filters) { PojoClassFilter pojoClassFilter = new FilterChain(filters); List<PojoClass> pojoClasses = PojoClassFactory.getPojoClasses(packageName, pojoClassFilter); validate(pojoClasses); return pojoClasses; }
Example #21
Source File: DefaultValidator.java From openpojo with Apache License 2.0 | 4 votes |
public List<PojoClass> validateRecursively(String packageName, PojoClassFilter... filters) { PojoClassFilter pojoClassFilter = new FilterChain(filters); List<PojoClass> pojoClasses = PojoClassFactory.getPojoClassesRecursively(packageName, pojoClassFilter); validate(pojoClasses); return pojoClasses; }
Example #22
Source File: PojoClassLookupService.java From openpojo with Apache License 2.0 | 4 votes |
List<PojoClass> enumerateClassesByExtendingType(final String packageName, final Class<?> type, final PojoClassFilter pojoClassFilter);
Example #23
Source File: DefaultPojoClassLookupService.java From openpojo with Apache License 2.0 | 4 votes |
public List<PojoClass> getPojoClasses(final String packageName, final PojoClassFilter pojoClassFilter) { return PojoPackageFactory.getPojoPackage(packageName).getPojoClasses(getFinalFilterChain(pojoClassFilter)); }
Example #24
Source File: DefaultPojoClassLookupService.java From openpojo with Apache License 2.0 | 4 votes |
private PojoClassFilter getFinalFilterChain(PojoClassFilter pojoClassFilter) { return new FilterChain(pojoClassFilter, ServiceRegistrar.getInstance().getPojoCoverageFilterService()); }
Example #25
Source File: PojoClassCoverageFilter.java From openpojo with Apache License 2.0 | 4 votes |
public void add(PojoClassFilter pojoClassFilter) { if (pojoClassFilter != null) { filters.add(pojoClassFilter); } }
Example #26
Source File: Clover4.java From openpojo with Apache License 2.0 | 4 votes |
@Override public PojoClassFilter getPojoClassFilter() { return FilterCloverClasses.getInstance(); }
Example #27
Source File: PojoClassFactory.java From openpojo with Apache License 2.0 | 2 votes |
/** * Return a list of classes that implement/extend a given type * * @param packageName * Parent package to recurse through. * @param type * Inheritance type (can be interface / abstract class or class). * @param pojoClassFilter * A filter to use for PojoClasses. * @return List of all Pojo's that extend type. */ public static List<PojoClass> enumerateClassesByExtendingType(final String packageName, final Class<?> type, final PojoClassFilter pojoClassFilter) { return ServiceRegistrar.getInstance().getPojoClassLookupService().enumerateClassesByExtendingType(packageName, type, pojoClassFilter); }
Example #28
Source File: PojoClassFactory.java From openpojo with Apache License 2.0 | 2 votes |
/** * This method enumerates all classes in a package path. This method will enumerate using the class loader, so if * you're tests live in the same package as your code, make sure you pass in a filter that can weed those out for * testing. * * @param packageName * The package name in question. * @param pojoClassFilter * The filter to use. * @return List of PojoClasses enumerated. */ public static List<PojoClass> getPojoClassesRecursively(final String packageName, final PojoClassFilter pojoClassFilter) { return ServiceRegistrar.getInstance().getPojoClassLookupService().getPojoClassesRecursively(packageName, pojoClassFilter); }
Example #29
Source File: PojoClassFactory.java From openpojo with Apache License 2.0 | 2 votes |
/** * This method returns a list of PojoClasses in a package representation with filtering capabilities. * * @param packageName * Package to introspect (eg. com.mypackage.pojo). * @param pojoClassFilter * The filter to apply to the list of PojoClasses. * @return A list of PojoClasses. */ public static List<PojoClass> getPojoClasses(final String packageName, final PojoClassFilter pojoClassFilter) { return ServiceRegistrar.getInstance().getPojoClassLookupService().getPojoClasses(packageName, pojoClassFilter); }
Example #30
Source File: Validator.java From openpojo with Apache License 2.0 | 2 votes |
/** * Validate for a given package and all its sub-packages with a given filter. * * @param packageName * The package name to run the validation against. * @param filters * The filter(s) to be used for filtering which classes are to be included in the validation. * * @return the list of PojoClasses that were validated. */ List<PojoClass> validateRecursively(String packageName, PojoClassFilter... filters);