1 package org.junit.experimental.categories; 2 3 import java.util.HashSet; 4 import java.util.List; 5 import java.util.Set; 6 7 import org.junit.experimental.categories.Categories.CategoryFilter; 8 import org.junit.runner.manipulation.Filter; 9 10 /** 11 * {@link org.junit.runner.FilterFactory} to exclude categories. 12 * 13 * The {@link Filter} that is created will filter out tests that are categorized with any of the 14 * given categories. 15 * 16 * Usage from command line: 17 * <code> 18 * --filter=org.junit.experimental.categories.ExcludeCategories=pkg.of.Cat1,pkg.of.Cat2 19 * </code> 20 * 21 * Usage from API: 22 * <code> 23 * new ExcludeCategories().createFilter(Cat1.class, Cat2.class); 24 * </code> 25 */ 26 public final class ExcludeCategories extends CategoryFilterFactory { 27 /** 28 * Creates a {@link Filter} which is only passed by tests that are 29 * not categorized with any of the specified categories. 30 * 31 * @param categories Category classes. 32 */ 33 @Override 34 protected Filter createFilter(List<Class<?>> categories) { 35 return new ExcludesAny(categories); 36 } 37 38 private static class ExcludesAny extends CategoryFilter { 39 public ExcludesAny(List<Class<?>> categories) { 40 this(new HashSet<Class<?>>(categories)); 41 } 42 43 public ExcludesAny(Set<Class<?>> categories) { 44 super(true, null, true, categories); 45 } 46 47 @Override 48 public String describe() { 49 return "excludes " + super.describe(); 50 } 51 } 52 } 53