private Collection<TestTag> parentRequirementsOf(TestTag requirementTag) { List<TestTag> matchingTags = new ArrayList<>(); java.util.Optional<Requirement> matchingRequirement = getMatchingRequirementFor(requirementTag); java.util.Optional<Requirement> parent = parentRequirementsOf(matchingRequirement.get()); while (parent.isPresent()) { matchingTags.add(parent.get().asTag()); parent = parentRequirementsOf(parent.get()); } return matchingTags; }
public Set<TestTag> getTagsFor(final TestOutcome testOutcome) { // // For the FileSystemRequirements tag provider, the test outcome provides a path, which might be: // - a feature file for Cucumber ("add_an_item.feature"), // - a story file with a path (JBehave) ("stories/manage_items/add_an_item.story") // Set<TestTag> tags = new HashSet<>(); if (testOutcome.getPath() != null) { java.util.Optional<Requirement> matchingRequirement = requirementWithMatchingFeatureFile(testOutcome); if (matchingRequirement.isPresent()) { tags.add(matchingRequirement.get().asTag()); tags.addAll(parentRequirementsOf(matchingRequirement.get().asTag())); } // Strategy used if a full path is provided List<String> storyPathElements = stripRootFrom(pathElements(stripRootPathFrom(testOutcome.getPath()))); tags.addAll(getMatchingCapabilities(getRequirements(), stripStorySuffixFrom(storyPathElements))); if (tags.isEmpty() && storyOrFeatureDescribedIn(storyPathElements).isPresent()) { java.util.Optional<TestTag> matchingRequirementTag = getMatchingRequirementTagsFor(storyOrFeatureDescribedIn(storyPathElements).get()); if (matchingRequirementTag.isPresent()) { tags.add(matchingRequirementTag.get()); tags.addAll(parentRequirementsOf(matchingRequirementTag.get())); } } } return tags; }