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.Object
Reorders tests. AnOrdering
can reverse the order of tests, sort the order or even shuffle the order.In general you will not need to use a
Ordering
directly. Instead, useRequest.orderWith(Ordering)
.- Since:
- 4.13
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Ordering.Context
Context about the ordering being applied.static interface
Ordering.Factory
Factory for creatingOrdering
instances.
-
Constructor Summary
Constructors Constructor Description Ordering()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
apply(java.lang.Object target)
Order the tests intarget
using this ordering.static Ordering
definedBy(java.lang.Class<? extends Ordering.Factory> factoryClass, Description annotatedTestClass)
Creates anOrdering
from the given factory class.static Ordering
definedBy(Ordering.Factory factory, Description annotatedTestClass)
Creates anOrdering
from the given factory.protected abstract java.util.List<Description>
orderItems(java.util.Collection<Description> descriptions)
Implemented by sub-classes to order the descriptions.static Ordering
shuffledBy(java.util.Random random)
Creates anOrdering
that shuffles the items using the givenRandom
instance.
-
-
-
Constructor Detail
-
Ordering
public Ordering()
-
-
Method Detail
-
shuffledBy
public static Ordering shuffledBy(java.util.Random random)
Creates anOrdering
that shuffles the items using the givenRandom
instance.
-
definedBy
public static Ordering definedBy(java.lang.Class<? extends Ordering.Factory> factoryClass, Description annotatedTestClass) throws InvalidOrderingException
Creates anOrdering
from 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 anOrdering
from 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
-
apply
public void apply(java.lang.Object target) throws InvalidOrderingException
Order the tests intarget
using this ordering.- Throws:
InvalidOrderingException
- if ordering does something invalid (like remove or add children)
-
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
-
-