public static CategoryFilter categoryFilter(boolean matchAnyInclusions, Set<Class<?>> inclusions, boolean matchAnyExclusions, Set<Class<?>> exclusions) { return new CategoryFilter(matchAnyInclusions, inclusions, matchAnyExclusions, exclusions); }
public static CategoryFilter exclude(boolean matchAny, Class<?>... categories) { if (hasNull(categories)) { throw new NullPointerException("has null category"); } return categoryFilter(true, null, matchAny, createSet(categories)); }
protected CategoryFilter(boolean matchAnyIncludes, Set<Class<?>> includes, boolean matchAnyExcludes, Set<Class<?>> excludes) { includedAny = matchAnyIncludes; excludedAny = matchAnyExcludes; included = copyAndRefine(includes); excluded = copyAndRefine(excludes); }
private static Set<Class<?>> categories(Description description) { Set<Class<?>> categories= new HashSet<Class<?>>(); Collections.addAll(categories, directCategories(description)); Collections.addAll(categories, directCategories(parentDescription(description))); return categories; }
private boolean hasCorrectCategoryAnnotation(Description description) { final Set<Class<?>> childCategories= categories(description); // If a child has no categories, immediately return. if (childCategories.isEmpty()) { return included.isEmpty(); } if (!excluded.isEmpty()) { if (excludedAny) { if (matchesAnyParentCategories(childCategories, excluded)) { return false; } } else { if (matchesAllParentCategories(childCategories, excluded)) { return false; } } } if (included.isEmpty()) { // Couldn't be excluded, and with no suite's included categories treated as should run. return true; } else { if (includedAny) { return matchesAnyParentCategories(childCategories, included); } else { return matchesAllParentCategories(childCategories, included); } } }
VolumeQuery query = new VolumeQuery( new URL("http://www.google.com/books/feeds/users/USER_ID/collections/library/volumes")); CategoryFilter filter = new CategoryFilter();; filter.addCategory( new Category(BooksCategory.Scheme.LABELS_SCHEME, "favorite")); query.addCategoryFilter(filter); VolumeFeed volumeFeed = service.query(query, VolumeFeed.class);
@Override public boolean shouldRun(Description description) { if (hasCorrectCategoryAnnotation(description)) { return true; } for (Description each : description.getChildren()) { if (shouldRun(each)) { return true; } } return false; }
/** * @return <tt>false</tt> if at least one parent category does not match children, otherwise <tt>true</tt>. * If empty <tt>parentCategories</tt>, returns <tt>true</tt>. */ private boolean matchesAllParentCategories(Set<Class<?>> childCategories, Set<Class<?>> parentCategories) { for (Class<?> parentCategory : parentCategories) { if (!hasAssignableTo(childCategories, parentCategory)) { return false; } } return true; }
public static CategoryFilter exclude(Class<?> category) { return exclude(true, category); }
if(!includeCategories.isEmpty() || !excludeCategories.isEmpty()) { request = new SilentFilterRequest(request, CategoryFilter.categoryFilter(true, loadClasses(testClassLoader, includeCategories), true, loadClasses(testClassLoader, excludeCategories)));
/** * @return <tt>true</tt> if at least one (any) parent category match a child, otherwise <tt>false</tt>. * If empty <tt>parentCategories</tt>, returns <tt>false</tt>. */ private boolean matchesAnyParentCategories(Set<Class<?>> childCategories, Set<Class<?>> parentCategories) { for (Class<?> parentCategory : parentCategories) { if (hasAssignableTo(childCategories, parentCategory)) { return true; } } return false; }
public static CategoryFilter exclude(Class<?>... categories) { return exclude(true, categories); }
public static CategoryFilter include(boolean matchAny, Class<?>... categories) { if (hasNull(categories)) { throw new NullPointerException("has null category"); } return categoryFilter(matchAny, createSet(categories), true, null); }
super(suiteClass, builder); try { filter(new CategoryFilter(getIncludedCategory(suiteClass), getExcludedCategory(suiteClass))); filter(new DevFilter());