aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/junit/runner/manipulation/Sorter.java
diff options
context:
space:
mode:
authorPaul Duffin <paulduffin@google.com>2016-12-14 11:13:37 +0000
committerPaul Duffin <paulduffin@google.com>2016-12-15 18:53:12 +0000
commit4dd042caba6f0ee54f604a409df7152b3e8205bb (patch)
treefd9aa7f11b8c8f927c9e98fd828e60086895ca5e /src/main/java/org/junit/runner/manipulation/Sorter.java
parent50db5f5810104e1dd0b0294145e9d3e602bb2627 (diff)
downloadjunit-4dd042caba6f0ee54f604a409df7152b3e8205bb.tar.gz
Moved source to match upstream file structure
Will make it simpler to update JUnit source. Bug: 33613916 Test: make checkbuild Change-Id: I76984a6defd3e40f34eea995e6ed865d32d53da3
Diffstat (limited to 'src/main/java/org/junit/runner/manipulation/Sorter.java')
-rw-r--r--src/main/java/org/junit/runner/manipulation/Sorter.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/main/java/org/junit/runner/manipulation/Sorter.java b/src/main/java/org/junit/runner/manipulation/Sorter.java
new file mode 100644
index 0000000..242df14
--- /dev/null
+++ b/src/main/java/org/junit/runner/manipulation/Sorter.java
@@ -0,0 +1,46 @@
+package org.junit.runner.manipulation;
+
+import java.util.Comparator;
+
+import org.junit.runner.Description;
+
+/**
+ * A <code>Sorter</code> orders tests. In general you will not need
+ * to use a <code>Sorter</code> directly. Instead, use {@link org.junit.runner.Request#sortWith(Comparator)}.
+ *
+ *
+ */
+public class Sorter implements Comparator<Description> {
+ /**
+ * NULL is a <code>Sorter</code> that leaves elements in an undefined order
+ */
+ public static Sorter NULL= new Sorter(new Comparator<Description>() {
+ public int compare(Description o1, Description o2) {
+ return 0;
+ }});
+ private final Comparator<Description> fComparator;
+
+ /**
+ * Creates a <code>Sorter</code> that uses <code>comparator</code>
+ * to sort tests
+ * @param comparator the {@link Comparator} to use when sorting tests
+ */
+ public Sorter(Comparator<Description> comparator) {
+ fComparator= comparator;
+ }
+
+ /**
+ * Sorts the test in <code>runner</code> using <code>comparator</code>
+ * @param object
+ */
+ public void apply(Object object) {
+ if (object instanceof Sortable) {
+ Sortable sortable = (Sortable) object;
+ sortable.sort(this);
+ }
+ }
+
+ public int compare(Description o1, Description o2) {
+ return fComparator.compare(o1, o2);
+ }
+}