1 package org.junit.runner; 2 3 import java.util.Comparator ; 4 5 import org.junit.internal.requests.ClassRequest; 6 import org.junit.internal.requests.ClassesRequest; 7 import org.junit.internal.requests.ErrorReportingRequest; 8 import org.junit.internal.requests.FilterRequest; 9 import org.junit.internal.requests.SortingRequest; 10 import org.junit.runner.manipulation.Filter; 11 12 24 public abstract class Request { 25 33 public static Request method(Class <?> clazz, String methodName) { 34 Description method= Description.createTestDescription(clazz, methodName); 35 return Request.aClass(clazz).filterWith(method); 36 } 37 38 44 public static Request aClass(Class <?> clazz) { 45 return new ClassRequest(clazz); 46 } 47 48 55 public static Request classes(String collectionName, Class <?>... classes) { 56 return new ClassesRequest(collectionName, classes); 57 } 58 59 public static Request errorReport(Class <?> klass, Throwable cause) { 60 return new ErrorReportingRequest(klass, cause); 61 } 62 63 67 public abstract Runner getRunner(); 68 69 75 public Request filterWith(Filter filter) { 76 return new FilterRequest(this, filter); 77 } 78 79 85 public Request filterWith(final Description desiredDescription) { 86 return filterWith(new Filter() { 87 @Override 88 public boolean shouldRun(Description description) { 89 if (description.isTest()) 91 return desiredDescription.equals(description); 92 for (Description each : description.getChildren()) 93 if (shouldRun(each)) 94 return true; 95 return false; 96 } 97 98 @Override 99 public String describe() { 100 return String.format("Method %s", desiredDescription.getDisplayName()); 101 } 102 }); 103 } 104 105 128 public Request sortWith(Comparator <Description> comparator) { 129 return new SortingRequest(this, comparator); 130 } 131 132 public static Request classWithoutSuiteMethod(Class <?> newTestClass) { 133 return new ClassRequest(newTestClass, false); 134 } 135 } 136 | Popular Tags |