From 015bfce05c0c11ff3063f0d3448656cc6d614b93 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Sun, 16 Apr 2023 15:24:23 +0200 Subject: [PATCH] Rename AlphabeticalSpecOrderer.descending to ascending Ascending sort order is the default, so instead of making 'descending' default to false, we make 'ascending' default to true, getting rid of the logical double negation of calling the default "not descending". Relates to #1443. --- .../orderer/AlphabeticalSpecOrderer.java | 40 ++++++++++--------- .../smoke/extension/OrderExtensionSpec.groovy | 2 +- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/spock-core/src/main/java/org/spockframework/runtime/extension/builtin/orderer/AlphabeticalSpecOrderer.java b/spock-core/src/main/java/org/spockframework/runtime/extension/builtin/orderer/AlphabeticalSpecOrderer.java index 2037ea82bf..877efed593 100644 --- a/spock-core/src/main/java/org/spockframework/runtime/extension/builtin/orderer/AlphabeticalSpecOrderer.java +++ b/spock-core/src/main/java/org/spockframework/runtime/extension/builtin/orderer/AlphabeticalSpecOrderer.java @@ -6,42 +6,44 @@ import java.util.concurrent.atomic.AtomicInteger; public class AlphabeticalSpecOrderer extends SpecOrderer { - private final boolean descending; + private final boolean ascending; - public AlphabeticalSpecOrderer(boolean orderSpecs, boolean orderFeatures, boolean descending) { + public AlphabeticalSpecOrderer(boolean orderSpecs, boolean orderFeatures, boolean ascending) { super(orderSpecs, orderFeatures); - this.descending = descending; + this.ascending = ascending; } public AlphabeticalSpecOrderer(boolean orderSpecs, boolean orderFeatures) { - this(orderSpecs, orderFeatures, false); + this(orderSpecs, orderFeatures, true); + } + + public AlphabeticalSpecOrderer() { + this(true, true); } @Override protected void orderSpecs(Collection specs) { AtomicInteger i = new AtomicInteger(); specs.stream() - .sorted((o1, o2) -> descending - ? o2.getDisplayName().compareTo(o1.getDisplayName()) - : o1.getDisplayName().compareTo(o2.getDisplayName()) + .sorted((o1, o2) -> ascending + ? o1.getDisplayName().compareTo(o2.getDisplayName()) + : o2.getDisplayName().compareTo(o1.getDisplayName()) ) .forEach(specInfo -> specInfo.setExecutionOrder(i.getAndIncrement())); } @Override - protected void orderFeatures(Collection specs) { - for (SpecInfo spec : specs) { - AtomicInteger i = new AtomicInteger(); - spec.getAllFeatures().stream() - .sorted((o1, o2) -> descending - ? o2.getDisplayName().compareTo(o1.getDisplayName()) - : o1.getDisplayName().compareTo(o2.getDisplayName()) - ) - .forEach(featureInfo -> featureInfo.setExecutionOrder(i.getAndIncrement())); - } + protected void orderFeatures(Collection features) { + AtomicInteger i = new AtomicInteger(); + features.stream() + .sorted((o1, o2) -> ascending + ? o1.getDisplayName().compareTo(o2.getDisplayName()) + : o2.getDisplayName().compareTo(o1.getDisplayName()) + ) + .forEach(featureInfo -> featureInfo.setExecutionOrder(i.getAndIncrement())); } - public boolean isDescending() { - return descending; + public boolean isAscending() { + return ascending; } } diff --git a/spock-specs/src/test/groovy/org/spockframework/smoke/extension/OrderExtensionSpec.groovy b/spock-specs/src/test/groovy/org/spockframework/smoke/extension/OrderExtensionSpec.groovy index ea645135ab..f2b01a61bf 100644 --- a/spock-specs/src/test/groovy/org/spockframework/smoke/extension/OrderExtensionSpec.groovy +++ b/spock-specs/src/test/groovy/org/spockframework/smoke/extension/OrderExtensionSpec.groovy @@ -266,7 +266,7 @@ class FourthSpec extends Specification { def 'descending, alphabetical spec and feature order'() { runner.configurationScript = { runner { - orderer new AlphabeticalSpecOrderer(true, true, true) + orderer new AlphabeticalSpecOrderer(true, true, false) } } runner.extensionClasses << OrderExtension