Skip to content

Commit 5c9ac8c

Browse files
committed
Provide unique IDs for all node info objects
1 parent 538f3e7 commit 5c9ac8c

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

spock-core/src/main/java/org/spockframework/runtime/SpecInfoBuilder.java

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ private void buildSpec() {
7676
SpecUtil.checkIsSpec(clazz);
7777

7878
SpecMetadata metadata = clazz.getAnnotation(SpecMetadata.class);
79+
spec.setUniqueId(clazz.getName());
7980
spec.setParent(null);
8081
spec.setPackage(ReflectionUtil.getPackageName(clazz));
8182
spec.setName(clazz.getSimpleName());
@@ -115,6 +116,7 @@ private void buildFeatures() {
115116

116117
private FeatureInfo createFeature(Method method, FeatureMetadata featureMetadata) {
117118
FeatureInfo feature = new FeatureInfo();
119+
feature.setUniqueId(String.format("%s.%s", spec.getUniqueId(), method.getName()));
118120
feature.setParent(spec);
119121
feature.setName(featureMetadata.name());
120122
feature.setLine(featureMetadata.line());

spock-core/src/main/java/org/spockframework/runtime/model/IterationInfo.java

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class IterationInfo extends NodeInfo<FeatureInfo, AnnotatedElement> imple
3131
private String displayName;
3232

3333
public IterationInfo(FeatureInfo feature, int iterationIndex, Object[] dataValues, int estimatedNumIterations) {
34+
setUniqueId(String.format("%s[%d]", feature.getUniqueId(), iterationIndex));
3435
setParent(feature);
3536
this.iterationIndex = iterationIndex;
3637
this.dataValues = dataValues;

spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java

+18
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,37 @@
2020

2121
import java.lang.annotation.Annotation;
2222
import java.lang.reflect.AnnotatedElement;
23+
import java.util.UUID;
2324

2425
/**
2526
* Base class for runtime information about an element in a Spock specification.
2627
*
2728
* @author Peter Niederwieser
2829
*/
2930
public abstract class NodeInfo<P extends NodeInfo, R extends AnnotatedElement> {
31+
private String uniqueId = UUID.randomUUID().toString();
3032
private String name;
3133
private int line = -1;
3234
private P parent;
3335
private R reflection;
3436
private Object metadata;
3537

38+
/**
39+
* A unique ID for this node during the current execution. Although some subclasses might
40+
* provide semantic IDs, and the default implementation uses UUIDs, no semantic or format
41+
* or maximum length is guaranteed. The only thing that should be assumed is, that the ID
42+
* is unique across all nodes during the same invocation.
43+
*
44+
* @return the unique ID for this node
45+
*/
46+
public String getUniqueId() {
47+
return uniqueId;
48+
}
49+
50+
public void setUniqueId(String uniqueId) {
51+
this.uniqueId = uniqueId;
52+
}
53+
3654
public String getName() {
3755
return name;
3856
}

0 commit comments

Comments
 (0)