Skip to content

Commit

Permalink
Improve API of SpecOrderer.orderFeatures
Browse files Browse the repository at this point in the history
Use Collection<FeatureInfo> method parameter instead of
Collection<SpecInfo>, streamlining method implementations by factoring
out looping over SpecInfos into SpecOrderer.process.

Relates to spockframework#1443.
  • Loading branch information
kriegaex committed Apr 16, 2023
1 parent 7cf5419 commit 81a9307
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import spock.lang.Order;

import java.util.Collection;
import java.util.concurrent.atomic.AtomicInteger;

public class AnnotatationBasedSpecOrderer extends SpecOrderer {
public AnnotatationBasedSpecOrderer() {
Expand All @@ -21,12 +20,10 @@ protected void orderSpecs(Collection<SpecInfo> specs) {
}

@Override
protected void orderFeatures(Collection<SpecInfo> specs) {
for (SpecInfo spec : specs) {
for (FeatureInfo feature : spec.getAllFeatures()) {
Order orderAnnotation = feature.getFeatureMethod().getAnnotation(Order.class);
feature.setExecutionOrder(orderAnnotation == null ? 0 : orderAnnotation.value());
}
protected void orderFeatures(Collection<FeatureInfo> features) {
for (FeatureInfo feature : features) {
Order orderAnnotation = feature.getFeatureMethod().getAnnotation(Order.class);
feature.setExecutionOrder(orderAnnotation == null ? 0 : orderAnnotation.value());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.spockframework.runtime.extension.builtin.orderer;

import org.spockframework.runtime.model.FeatureInfo;
import org.spockframework.runtime.model.SpecInfo;

import java.util.Collection;
Expand All @@ -13,5 +14,5 @@ public DefaultSpecOrderer() {
protected void orderSpecs(Collection<SpecInfo> specs) { }

@Override
protected void orderFeatures(Collection<SpecInfo> specs) { }
protected void orderFeatures(Collection<FeatureInfo> features) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import java.util.Collection;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

public class RandomSpecOrderer extends SpecOrderer {
private final Random random;
Expand All @@ -30,10 +29,8 @@ protected void orderSpecs(Collection<SpecInfo> specs) {
}

@Override
protected void orderFeatures(Collection<SpecInfo> specs) {
for (SpecInfo spec : specs) {
for (FeatureInfo feature : spec.getAllFeatures())
feature.setExecutionOrder(random.nextInt());
}
protected void orderFeatures(Collection<FeatureInfo> features) {
for (FeatureInfo feature : features)
feature.setExecutionOrder(random.nextInt());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ public SpecOrderer(boolean orderSpecs, boolean orderFeatures) {
public void process(Collection<SpecInfo> specs) {
if (orderSpecs)
orderSpecs(specs);
if (orderFeatures)
orderFeatures(specs);
if (!orderFeatures)
return;
for (SpecInfo spec : specs)
orderFeatures(spec.getAllFeatures());
}

protected abstract void orderSpecs(Collection<SpecInfo> specs);
protected abstract void orderFeatures(Collection<SpecInfo> specs);

protected abstract void orderFeatures(Collection<FeatureInfo> features);

public boolean isOrderSpecs() {
return orderSpecs;
Expand Down

0 comments on commit 81a9307

Please sign in to comment.