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