diff options
author | Pete Bentley <prb@google.com> | 2021-02-24 08:57:22 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-02-24 08:57:22 +0000 |
commit | d1359663578e2a49e74ed74eb10d4b663d58cf3f (patch) | |
tree | 1331fa1b743d5d0a341f82ff555ce4c602f40ab9 /src/main/java/org/junit/runner/manipulation/Orderer.java | |
parent | e938015d2d5a2157ed20eb622fcd9750a12bb4af (diff) | |
parent | 7db56fab8af99e12a7644349d14109235ec584b9 (diff) | |
download | junit-d1359663578e2a49e74ed74eb10d4b663d58cf3f.tar.gz |
Merge changes I8f5cd126,Ifdb59336,I6abae5ae,I5ec909df
* changes:
Remove support for stuck threads
Remove DisableOnDebug (new in 4.12) as it is not supported on Android
Extra generic type information to aid certain javacs.
Upgrade external/junit to 4.13.2
Diffstat (limited to 'src/main/java/org/junit/runner/manipulation/Orderer.java')
-rw-r--r-- | src/main/java/org/junit/runner/manipulation/Orderer.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/main/java/org/junit/runner/manipulation/Orderer.java b/src/main/java/org/junit/runner/manipulation/Orderer.java new file mode 100644 index 0000000..eb13054 --- /dev/null +++ b/src/main/java/org/junit/runner/manipulation/Orderer.java @@ -0,0 +1,62 @@ +package org.junit.runner.manipulation; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.runner.Description; + +/** + * Orders tests. + * + * @since 4.13 + */ +public final class Orderer { + private final Ordering ordering; + + Orderer(Ordering delegate) { + this.ordering = delegate; + } + + /** + * Orders the descriptions. + * + * @return descriptions in order + */ + public List<Description> order(Collection<Description> descriptions) + throws InvalidOrderingException { + List<Description> inOrder = ordering.orderItems( + Collections.unmodifiableCollection(descriptions)); + if (!ordering.validateOrderingIsCorrect()) { + return inOrder; + } + + Set<Description> uniqueDescriptions = new HashSet<Description>(descriptions); + if (!uniqueDescriptions.containsAll(inOrder)) { + throw new InvalidOrderingException("Ordering added items"); + } + Set<Description> resultAsSet = new HashSet<Description>(inOrder); + if (resultAsSet.size() != inOrder.size()) { + throw new InvalidOrderingException("Ordering duplicated items"); + } else if (!resultAsSet.containsAll(uniqueDescriptions)) { + throw new InvalidOrderingException("Ordering removed items"); + } + + return inOrder; + } + + /** + * Order the tests in <code>target</code>. + * + * @throws InvalidOrderingException if ordering does something invalid (like remove or add + * children) + */ + public void apply(Object target) throws InvalidOrderingException { + if (target instanceof Orderable) { + Orderable orderable = (Orderable) target; + orderable.order(this); + } + } +} |