Skip to content

Commit

Permalink
Provide unique IDs for all node info objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Jun 10, 2023
1 parent dedede9 commit 27d05a4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class IterationInfo extends NodeInfo<FeatureInfo, AnnotatedElement> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,37 @@

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.
*
* @author Peter Niederwieser
*/
public abstract class NodeInfo<P extends NodeInfo, R extends AnnotatedElement> {
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;
}
Expand Down

0 comments on commit 27d05a4

Please sign in to comment.