Package org.junit.runner.manipulation
Class Ordering
- java.lang.Object
-
- org.junit.runner.manipulation.Ordering
-
- Direct Known Subclasses:
Sorter
public abstract class Ordering extends java.lang.ObjectReorders tests. AnOrderingcan reverse the order of tests, sort the order or even shuffle the order.In general you will not need to use a
Orderingdirectly. Instead, useRequest.orderWith(Ordering).- Since:
- 4.13
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOrdering.ContextContext about the ordering being applied.static interfaceOrdering.FactoryFactory for creatingOrderinginstances.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringCONSTRUCTOR_ERROR_FORMAT
-
Constructor Summary
Constructors Constructor Description Ordering()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidapply(java.lang.Object target)Order the tests intargetusing this ordering.static OrderingdefinedBy(java.lang.Class<? extends Ordering.Factory> factoryClass, Description annotatedTestClass)Creates anOrderingfrom the given factory class.static OrderingdefinedBy(Ordering.Factory factory, Description annotatedTestClass)Creates anOrderingfrom the given factory.private static java.lang.StringgetClassName(java.lang.Class<?> clazz)protected abstract java.util.List<Description>orderItems(java.util.Collection<Description> descriptions)Implemented by sub-classes to order the descriptions.static OrderingshuffledBy(java.util.Random random)Creates anOrderingthat shuffles the items using the givenRandominstance.(package private) booleanvalidateOrderingIsCorrect()Returnstrueif this ordering could produce invalid results (i.e.
-
-
-
Field Detail
-
CONSTRUCTOR_ERROR_FORMAT
private static final java.lang.String CONSTRUCTOR_ERROR_FORMAT
- See Also:
- Constant Field Values
-
-
Method Detail
-
shuffledBy
public static Ordering shuffledBy(java.util.Random random)
Creates anOrderingthat shuffles the items using the givenRandominstance.
-
definedBy
public static Ordering definedBy(java.lang.Class<? extends Ordering.Factory> factoryClass, Description annotatedTestClass) throws InvalidOrderingException
Creates anOrderingfrom the given factory class. The class must have a public no-arg constructor.- Parameters:
factoryClass- class to use to create the orderingannotatedTestClass- test class that is annotated withOrderWith.- Throws:
InvalidOrderingException- if the instance could not be created
-
definedBy
public static Ordering definedBy(Ordering.Factory factory, Description annotatedTestClass) throws InvalidOrderingException
Creates anOrderingfrom the given factory.- Parameters:
factory- factory to use to create the orderingannotatedTestClass- test class that is annotated withOrderWith.- Throws:
InvalidOrderingException- if the instance could not be created
-
getClassName
private static java.lang.String getClassName(java.lang.Class<?> clazz)
-
apply
public void apply(java.lang.Object target) throws InvalidOrderingExceptionOrder the tests intargetusing this ordering.- Throws:
InvalidOrderingException- if ordering does something invalid (like remove or add children)
-
validateOrderingIsCorrect
boolean validateOrderingIsCorrect()
Returnstrueif this ordering could produce invalid results (i.e. if it could add or remove values).
-
orderItems
protected abstract java.util.List<Description> orderItems(java.util.Collection<Description> descriptions)
Implemented by sub-classes to order the descriptions.- Returns:
- descriptions in order
-
-