Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide unique IDs for all node info objects #1696

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading