Skip to content

Commit

Permalink
Rename AlphabeticalSpecOrderer.descending to ascending
Browse files Browse the repository at this point in the history
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 spockframework#1443.
  • Loading branch information
kriegaex committed May 6, 2023
1 parent 113d4ce commit 015bfce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpecInfo> 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<SpecInfo> 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<FeatureInfo> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 015bfce

Please sign in to comment.