/** * @return a new Request, which contains all of the same tests, but in a new order. */ public Request sortRequest(Request request) { if (request instanceof SortingRequest) { // We'll pay big karma points for this return request; } List<Description> leaves = findLeaves(request); Collections.sort(leaves, fHistory.testComparator()); return constructLeafRequest(leaves); }
/** * Returns a Request whose Tests can be run in a certain order, defined by * <code>comparator</code> * <p> * For example, here is code to run a test suite in alphabetical order: * <pre> * private static Comparator<Description> forward() { * return new Comparator<Description>() { * public int compare(Description o1, Description o2) { * return o1.getDisplayName().compareTo(o2.getDisplayName()); * } * }; * } * * public static main() { * new JUnitCore().run(Request.aClass(AllTests.class).sortWith(forward())); * } * </pre> * * @param comparator definition of the order of the tests in this Request * @return a Request with ordered Tests */ public Request sortWith(Comparator<Description> comparator) { return new SortingRequest(this, comparator); }
/** * Returns a Request whose Tests can be run in a certain order, defined by * <code>comparator</code> * * For example, here is code to run a test suite in alphabetical order: * * <pre> * private static Comparator<Description> forward() { * return new Comparator<Description>() { * public int compare(Description o1, Description o2) { * return o1.getDisplayName().compareTo(o2.getDisplayName()); * } * }; * } * * public static main() { * new JUnitCore().run(Request.aClass(AllTests.class).sortWith(forward())); * } * </pre> * * @param comparator definition of the order of the tests in this Request * @return a Request with ordered Tests */ public Request sortWith(Comparator<Description> comparator) { return new SortingRequest(this, comparator); }