All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.junit.runner.manipulation.Sorter Maven / Gradle / Ivy

There is a newer version: 2.12.15
Show newest version
package org.junit.runner.manipulation;

import java.util.Comparator;

import org.junit.runner.Description;

/**
 * A Sorter orders tests. In general you will not need
 * to use a Sorter directly. Instead, use {@link org.junit.runner.Request#sortWith(Comparator)}.
 *
 * @since 4.0
 */
public class Sorter implements Comparator {
    /**
     * NULL is a Sorter that leaves elements in an undefined order
     */
    public static final Sorter NULL = new Sorter(new Comparator() {
        public int compare(Description o1, Description o2) {
            return 0;
        }
    });

    private final Comparator comparator;

    /**
     * Creates a Sorter that uses comparator
     * to sort tests
     *
     * @param comparator the {@link Comparator} to use when sorting tests
     */
    public Sorter(Comparator comparator) {
        this.comparator = comparator;
    }

    /**
     * Sorts the test in runner using comparator
     */
    public void apply(Object object) {
        if (object instanceof Sortable) {
            Sortable sortable = (Sortable) object;
            sortable.sort(this);
        }
    }

    public int compare(Description o1, Description o2) {
        return comparator.compare(o1, o2);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy