org.junit.runner.manipulation
Class Ordering

java.lang.Object
  extended by org.junit.runner.manipulation.Ordering
Direct Known Subclasses:
Sorter

public abstract class Ordering
extends Object

Reorders tests. An Ordering 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, use Request.orderWith(Ordering).

Since:
4.13

Nested Class Summary
static class Ordering.Context
          Context about the ordering being applied.
static interface Ordering.Factory
          Factory for creating Ordering instances.
 
Constructor Summary
Ordering()
           
 
Method Summary
 void apply(Object target)
          Order the tests in target using this ordering.
static Ordering definedBy(Class<? extends Ordering.Factory> factoryClass, Description annotatedTestClass)
          Creates an Ordering from the given factory class.
static Ordering definedBy(Ordering.Factory factory, Description annotatedTestClass)
          Creates an Ordering from the given factory.
protected abstract  List<Description> orderItems(Collection<Description> descriptions)
          Implemented by sub-classes to order the descriptions.
static Ordering shuffledBy(Random random)
          Creates an Ordering that shuffles the items using the given Random instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Ordering

public Ordering()
Method Detail

shuffledBy

public static Ordering shuffledBy(Random random)
Creates an Ordering that shuffles the items using the given Random instance.


definedBy

public static Ordering definedBy(Class<? extends Ordering.Factory> factoryClass,
                                 Description annotatedTestClass)
                          throws InvalidOrderingException
Creates an Ordering from the given factory class. The class must have a public no-arg constructor.

Parameters:
factoryClass - class to use to create the ordering
annotatedTestClass - test class that is annotated with OrderWith.
Throws:
InvalidOrderingException - if the instance could not be created

definedBy

public static Ordering definedBy(Ordering.Factory factory,
                                 Description annotatedTestClass)
                          throws InvalidOrderingException
Creates an Ordering from the given factory.

Parameters:
factory - factory to use to create the ordering
annotatedTestClass - test class that is annotated with OrderWith.
Throws:
InvalidOrderingException - if the instance could not be created

apply

public void apply(Object target)
           throws InvalidOrderingException
Order the tests in target using this ordering.

Throws:
InvalidOrderingException - if ordering does something invalid (like remove or add children)

orderItems

protected abstract List<Description> orderItems(Collection<Description> descriptions)
Implemented by sub-classes to order the descriptions.

Returns:
descriptions in order


Copyright © 2002–2020 JUnit. All rights reserved.