Skip to content

Commit

Permalink
Added improved feature coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Oct 14, 2018
1 parent 46c91e6 commit 0e712b1
Show file tree
Hide file tree
Showing 17 changed files with 4,368 additions and 12,291 deletions.
16,166 changes: 4,003 additions & 12,163 deletions CHANGELOG.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.UUID;

public class ReportData {
private final String title;
private final String contents;
private final String path;
private Boolean isEvidence;
private String id;

public ReportData(String title, String contents, String path) {

this.title = title;
this.contents = contents;
this.path = path;
this.isEvidence = false;
this.id = "report-data-" + UUID.randomUUID().toString();
}

public static ReportDataBuilder withTitle(String title) {
Expand All @@ -34,6 +37,8 @@ public String getContents() {

public String getPath() { return path; }

public String getId() { return id; }

public static class ReportDataBuilder {
private final String title;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import static java.util.Collections.EMPTY_LIST;
import static net.thucydides.core.reports.html.ReportNameProvider.NO_CONTEXT;
Expand Down Expand Up @@ -206,7 +207,7 @@ public List<String> getRequirementTypes() {
return requirementTypes;
}

private Collection<? extends String> requirementTypesDefinedIn(List<Requirement> requirements) {
private Collection<String> requirementTypesDefinedIn(List<Requirement> requirements) {
List<String> requirementTypes = new ArrayList<>();
for(Requirement requirement : requirements) {
if (!requirementTypes.contains(requirement.getType())) {
Expand All @@ -219,6 +220,17 @@ private Collection<? extends String> requirementTypesDefinedIn(List<Requirement>
return requirementTypes;
}

private Collection<TestTag> requirementTagsOfType(List<Requirement> requirements, List<String> tagTypes) {
Set<TestTag> requirementTypes = new HashSet<>();
for(Requirement requirement : AllRequirements.in(requirements)) {
List<TestTag> matchingTags = requirement.getTags().stream()
.filter( tag -> tagTypes.contains(tag.getType()))
.collect(Collectors.toList());

requirementTypes.addAll(matchingTags);
}
return requirementTypes;
}

@Override
public List<String> getReleaseVersionsFor(TestOutcome testOutcome) {
Expand All @@ -244,4 +256,8 @@ public boolean isRequirementsTag(TestTag tag) {
return getRequirementTypes().contains(tag.getType());
}

@Override
public Collection<TestTag> getTagsOfType(List<String> tagTypes) {
return requirementTagsOfType(getRequirements(), tagTypes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,8 @@ private Requirement leafRequirementWithNarrative(String shortName, String path,
.withType(type)
.withNarrative(requirementNarrative.getText())
.withPath(relativeDirectoryOf(path))
.withReleaseVersions(releaseVersions);
.withReleaseVersions(releaseVersions)
.withTags(requirementNarrative.getTags());
}

private Requirement requirementWithNarrative(File requirementDirectory, String shortName, Narrative requirementNarrative) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public List<Requirement> merge(Iterable<Requirement> baseRequirements, Iterable<
mergeNewRequirement(newRequirement, mergedRequirements);
}

return NewList.copyOf(mergedRequirements);
return new ArrayList<>(mergedRequirements);
}

private void mergeNewRequirement(Requirement newRequirement, List<Requirement> existingRequirements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.thucydides.core.model.TestTag;
import net.thucydides.core.requirements.model.Requirement;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

Expand All @@ -27,4 +28,6 @@ public interface RequirementsService extends ParentRequirementProvider {
List<Release> getReleasesFromRequirements();

List<String> getRequirementTypes();

Collection<TestTag> getTagsOfType(List<String> tagTypes);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package net.thucydides.core.requirements.model;

import com.google.common.base.Splitter;
import net.thucydides.core.model.TestTag;
import org.apache.commons.lang3.StringUtils;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

Expand All @@ -30,12 +32,16 @@ public java.util.Optional<Narrative> fromFile(File narrativeFile, String default
}
String text = readNarrativeFrom(lines);
reader.close();

List<TestTag> tags = Arrays.asList(TestTag.withName(title).andType("story"));

return java.util.Optional.of(new Narrative(Optional.ofNullable(title),
Optional.of(narrativeFile.getPath()),
Optional.ofNullable(cardNumber),
versionNumbers,
type,
text));
text,
tags));
} catch (IOException ex) {
ex.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import com.google.common.base.Preconditions;
import net.serenitybdd.core.collect.NewList;
import net.thucydides.core.model.TestTag;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;

Expand All @@ -14,6 +17,7 @@ public class Narrative {
private final List<String> versionNumbers;
private final String text;
private String type;
private List<TestTag> tags;

public Narrative(Optional<String> title, Optional<String> id, Optional<String> cardNumber, List<String> versionNumbers, String type, String text) {
Preconditions.checkNotNull(type);
Expand All @@ -24,12 +28,34 @@ public Narrative(Optional<String> title, Optional<String> id, Optional<String> c
this.versionNumbers = versionNumbers;
this.type = type;
this.text = text;
this.tags = new ArrayList<>();
}

public Narrative(Optional<String> title,
Optional<String> id,
Optional<String> cardNumber,
List<String> versionNumbers,
String type,
String text,
List<TestTag> tags) {
Preconditions.checkNotNull(type);
Preconditions.checkNotNull(text);
this.title = title;
this.id = id;
this.cardNumber = cardNumber;
this.versionNumbers = versionNumbers;
this.type = type;
this.text = text;
this.tags = new ArrayList<>(tags);
}
public Narrative(String type, String text) {
this(Optional.<String>empty(), Optional.<String>empty(), Optional.<String>empty(), NewList.<String>of(), type, text);
}

public List<TestTag> getTags() {
return tags;
}

public Optional<String> getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Requirement implements Comparable {
private List<Example> examples;
private List<String> releaseVersions;
private List<CustomFieldValue> customFields;
private List<TestTag> tags = new ArrayList<>();

public Requirement() {
// Used by Jackson
Expand Down Expand Up @@ -74,6 +75,31 @@ protected Requirement(String name, String id, String displayName, String cardNum
this.releaseVersions = NewList.copyOf(releaseVersions);
this.customFields = NewList.copyOf(customFields);
this.featureFileName = featureFileName;
this.tags = new ArrayList<>();
}

protected Requirement(String name, String id, String displayName, String cardNumber, String parent, String type, String path, CustomFieldValue narrative,
List<Requirement> children, List<Example> examples,
List<String> releaseVersions,
List<CustomFieldValue> customFields,
String featureFileName,
List<TestTag> tags) {
Preconditions.checkNotNull(name);
Preconditions.checkNotNull(type);
this.name = name;
this.id = id;
this.displayName = (displayName != null) ? displayName : name;
this.cardNumber = cardNumber;
this.type = type;
this.path = path;
this.parent = parent;
this.narrative = narrative;
this.children = new ArrayList<>(children);
this.examples = new ArrayList<>(examples);
this.releaseVersions = NewList.copyOf(releaseVersions);
this.customFields = NewList.copyOf(customFields);
this.featureFileName = featureFileName;
this.tags = tags;
}

protected Requirement(String name, String id, String displayName, String cardNumber, String parent, String type, String path,
Expand All @@ -96,6 +122,7 @@ protected Requirement(String name, String id, String displayName, String cardNum
this.releaseVersions = NewList.copyOf(releaseVersions);
this.customFields = NewList.copyOf(customFields);
this.path = path;
this.tags = new ArrayList<>();
}

public String getName() {
Expand Down Expand Up @@ -164,55 +191,55 @@ public static RequirementBuilderNameStep named(String name) {

public Requirement definedInFile(File featureFile) {
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, this.parent, this.type, this.path, this.narrative,
this.children, this.examples, this.releaseVersions, this.customFields, featureFile.getName());
this.children, this.examples, this.releaseVersions, this.customFields, featureFile.getName(), this.tags);
}

public Requirement withChildren(List<Requirement> children) {
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, this.parent, this.type, this.path, this.narrative, children, examples, releaseVersions, customFields, featureFileName);
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, this.parent, this.type, this.path, this.narrative, children, examples, releaseVersions, customFields, featureFileName, this.tags);
}

public void setChildren(List<Requirement> children) {
this.children = NewList.copyOf(children);
}

public Requirement withParent(String parent) {
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, parent, this.type, this.path, this.narrative, children, examples, releaseVersions, customFields, featureFileName);
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, parent, this.type, this.path, this.narrative, children, examples, releaseVersions, customFields, featureFileName, this.tags);
}


public Requirement withType(String type) {
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, this.parent, type, this.path, this.narrative, children, examples, releaseVersions, customFields, featureFileName);
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, this.parent, type, this.path, this.narrative, children, examples, releaseVersions, customFields, featureFileName, this.tags);
}

public Requirement withDisplayName(String displayName) {
return new Requirement(this.name, this.id, displayName, this.cardNumber, this.parent, type, this.path, this.narrative, children, examples, releaseVersions, customFields, featureFileName);
return new Requirement(this.name, this.id, displayName, this.cardNumber, this.parent, type, this.path, this.narrative, children, examples, releaseVersions, customFields, featureFileName, this.tags);
}

public Requirement withFeatureFileyName(String featureFileName) {
return new Requirement(this.name, this.id, displayName, this.cardNumber, this.parent, type, this.path, this.narrative, children, examples, releaseVersions, customFields, featureFileName);
return new Requirement(this.name, this.id, displayName, this.cardNumber, this.parent, type, this.path, this.narrative, children, examples, releaseVersions, customFields, featureFileName, this.tags);
}

public Requirement withExample(Example example) {
List<Example> updatedExamples = new ArrayList<>(examples);
updatedExamples.add(example);
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, this.parent, this.type, this.path, this.narrative, children, updatedExamples, releaseVersions, customFields, featureFileName);
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, this.parent, this.type, this.path, this.narrative, children, updatedExamples, releaseVersions, customFields, featureFileName, this.tags);
}

public Requirement withExamples(List<Example> examples) {
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, this.parent, this.type, this.path, this.narrative, children, examples, releaseVersions, customFields, featureFileName);
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, this.parent, this.type, this.path, this.narrative, children, examples, releaseVersions, customFields, featureFileName, this.tags);
}

public Requirement withReleaseVersions(List<String> releaseVersions) {
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, this.parent, this.type, this.path, this.narrative, children, examples, releaseVersions, customFields, featureFileName);
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, this.parent, this.type, this.path, this.narrative, children, examples, releaseVersions, customFields, featureFileName, this.tags);
}

public Requirement withCustomFields(List<CustomFieldValue> customFields) {
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, this.parent, this.type, this.path, this.narrative, children, examples, releaseVersions, customFields, featureFileName);
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, this.parent, this.type, this.path, this.narrative, children, examples, releaseVersions, customFields, featureFileName, this.tags);
}


public Requirement withPath(String path) {
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, this.parent, this.type, path, this.narrative, children, examples, releaseVersions, customFields, featureFileName);
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, this.parent, this.type, path, this.narrative, children, examples, releaseVersions, customFields, featureFileName, this.tags);
}

public boolean hasChildren() {
Expand All @@ -228,6 +255,10 @@ public List<Requirement> getNestedChildren() {
return NewList.copyOf(nestedChildren);
}

public List<TestTag> getTags() {
return new ArrayList<>(tags);
}

public TestTag asTag() {
return TestTag.withName(qualifiedName()).andType(getType());
}
Expand Down Expand Up @@ -280,7 +311,7 @@ public Requirement withChild(Requirement child) {
List<Requirement> newChildren = new ArrayList(children);
newChildren.remove(child);
newChildren.add(child);
return new Requirement(name, id, displayName,cardNumber,parent, type, narrative, newChildren, examples,releaseVersions);
return new Requirement(name, id, displayName,cardNumber,parent, type, narrative, newChildren, examples,releaseVersions).withTags(this.tags);
}

public CustomFieldSetter withCustomField(String fieldName) {
Expand Down Expand Up @@ -350,7 +381,8 @@ public Requirement merge(Requirement newRequirement) {
.withExamples(mergedExamples)
.withCustomFields(mergedCustomFields)
.withFeatureFileyName(mergedFeatureFileName)
.withChildren(mergedChildren);
.withChildren(mergedChildren)
.withTags(tags);
}

private List<Requirement> mergeRequirementLists(List<Requirement> existingChilden, List<Requirement> newChildren) {
Expand All @@ -368,13 +400,18 @@ private List<Requirement> mergeRequirementLists(List<Requirement> existingChilde

public Requirement withNarrative(String narrativeText) {
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, parent, this.type, this.path, new CustomFieldValue("Narrative", narrativeText),
children, examples, releaseVersions, customFields, featureFileName);
children, examples, releaseVersions, customFields, featureFileName, tags);
}

public String getPath() {
return path;
}

public Requirement withTags(List<TestTag> tags) {
return new Requirement(this.name, this.id, this.displayName, this.cardNumber, parent, this.type, this.path, this.narrative,
children, examples, releaseVersions, customFields, featureFileName, tags);
}

public static class CustomFieldSetter {

Requirement requirement;
Expand All @@ -391,7 +428,7 @@ public Requirement setTo(String value, String renderedValue) {
return new Requirement(requirement.name, requirement.id, requirement.displayName,
requirement.cardNumber, requirement.parent, requirement.type, requirement.path, requirement.narrative,
requirement.children, requirement.examples, requirement.releaseVersions,
customFields);
customFields).withTags(requirement.tags);
}

public Requirement setTo(String value) {
Expand Down
Loading

0 comments on commit 0e712b1

Please sign in to comment.