From 48d05e83c1ed35553a14298b428d54f11a58f79d Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Sun, 16 Apr 2023 11:41:44 +0200 Subject: [PATCH] Introduce SpecProcessor interface and SpecOrderer, implementing it SpecProcessor is designed to generically process a Collection, which e.g. is available to global extensions using the recently introduced lifecycle method initSpecs(Collection). New abstract class SpecOrderer is meant to be extended by other orderers wishing to assign run orders to specs/features via - SpecInfo.setExecutionOrder, - FeatureInfo.setExecutionOrder. Relates to #1443. --- .../spockframework/runtime/SpecProcessor.java | 9 +++++ .../builtin/orderer/SpecOrderer.java | 35 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 spock-core/src/main/java/org/spockframework/runtime/SpecProcessor.java create mode 100644 spock-core/src/main/java/org/spockframework/runtime/extension/builtin/orderer/SpecOrderer.java diff --git a/spock-core/src/main/java/org/spockframework/runtime/SpecProcessor.java b/spock-core/src/main/java/org/spockframework/runtime/SpecProcessor.java new file mode 100644 index 0000000000..b575c857ed --- /dev/null +++ b/spock-core/src/main/java/org/spockframework/runtime/SpecProcessor.java @@ -0,0 +1,9 @@ +package org.spockframework.runtime; + +import org.spockframework.runtime.model.SpecInfo; + +import java.util.Collection; + +public interface SpecProcessor { + void process(Collection specs); +} diff --git a/spock-core/src/main/java/org/spockframework/runtime/extension/builtin/orderer/SpecOrderer.java b/spock-core/src/main/java/org/spockframework/runtime/extension/builtin/orderer/SpecOrderer.java new file mode 100644 index 0000000000..70bff7262a --- /dev/null +++ b/spock-core/src/main/java/org/spockframework/runtime/extension/builtin/orderer/SpecOrderer.java @@ -0,0 +1,35 @@ +package org.spockframework.runtime.extension.builtin.orderer; + +import org.spockframework.runtime.SpecProcessor; +import org.spockframework.runtime.model.SpecInfo; + +import java.util.Collection; + +public abstract class SpecOrderer implements SpecProcessor { + protected final boolean orderSpecs; + protected final boolean orderFeatures; + + public SpecOrderer(boolean orderSpecs, boolean orderFeatures) { + this.orderSpecs = orderSpecs; + this.orderFeatures = orderFeatures; + } + + @Override + public void process(Collection specs) { + if (orderSpecs) + orderSpecs(specs); + if (orderFeatures) + orderFeatures(specs); + } + + protected abstract void orderSpecs(Collection specs); + protected abstract void orderFeatures(Collection specs); + + public boolean isOrderSpecs() { + return orderSpecs; + } + + public boolean isOrderFeatures() { + return orderFeatures; + } +}