From 3db8d210b2ed985550343fdb515fe646bfb9059a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Kautler?= Date: Sat, 10 Jun 2023 16:38:02 +0200 Subject: [PATCH] Provide unique IDs for all node info objects --- .../runtime/SpecInfoBuilder.java | 2 ++ .../runtime/model/IterationInfo.java | 1 + .../spockframework/runtime/model/NodeInfo.java | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/spock-core/src/main/java/org/spockframework/runtime/SpecInfoBuilder.java b/spock-core/src/main/java/org/spockframework/runtime/SpecInfoBuilder.java index 1598389ff8..dbca9d0ce0 100644 --- a/spock-core/src/main/java/org/spockframework/runtime/SpecInfoBuilder.java +++ b/spock-core/src/main/java/org/spockframework/runtime/SpecInfoBuilder.java @@ -76,6 +76,7 @@ private void buildSpec() { SpecUtil.checkIsSpec(clazz); SpecMetadata metadata = clazz.getAnnotation(SpecMetadata.class); + spec.setUniqueId(clazz.getName()); spec.setParent(null); spec.setPackage(ReflectionUtil.getPackageName(clazz)); spec.setName(clazz.getSimpleName()); @@ -115,6 +116,7 @@ private void buildFeatures() { private FeatureInfo createFeature(Method method, FeatureMetadata featureMetadata) { FeatureInfo feature = new FeatureInfo(); + feature.setUniqueId(String.format("%s.%s", spec.getUniqueId(), method.getName())); feature.setParent(spec); feature.setName(featureMetadata.name()); feature.setLine(featureMetadata.line()); diff --git a/spock-core/src/main/java/org/spockframework/runtime/model/IterationInfo.java b/spock-core/src/main/java/org/spockframework/runtime/model/IterationInfo.java index 90835200e8..62162d3879 100644 --- a/spock-core/src/main/java/org/spockframework/runtime/model/IterationInfo.java +++ b/spock-core/src/main/java/org/spockframework/runtime/model/IterationInfo.java @@ -31,6 +31,7 @@ public class IterationInfo extends NodeInfo imple private String displayName; public IterationInfo(FeatureInfo feature, int iterationIndex, Object[] dataValues, int estimatedNumIterations) { + setUniqueId(String.format("%s[%d]", feature.getUniqueId(), iterationIndex)); setParent(feature); this.iterationIndex = iterationIndex; this.dataValues = dataValues; diff --git a/spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java b/spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java index c0840c3de8..aebbfcc51c 100644 --- a/spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java +++ b/spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java @@ -20,6 +20,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; +import java.util.UUID; /** * Base class for runtime information about an element in a Spock specification. @@ -27,12 +28,29 @@ * @author Peter Niederwieser */ public abstract class NodeInfo

{ + private String uniqueId = UUID.randomUUID().toString(); private String name; private int line = -1; private P parent; private R reflection; private Object metadata; + /** + * A unique ID for this node during the current execution. Although some subclasses might + * provide semantic IDs, and the default implementation uses UUIDs, no semantic or format + * or maximum length is guaranteed. The only thing that should be assumed is, that the ID + * is unique across all nodes during the same invocation. + * + * @return the unique ID for this node + */ + public String getUniqueId() { + return uniqueId; + } + + public void setUniqueId(String uniqueId) { + this.uniqueId = uniqueId; + } + public String getName() { return name; }