net.thucydides.core.model.TestOutcomeAnnotationReader Maven / Gradle / Ivy
package net.thucydides.core.model;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import net.thucydides.core.annotations.TestAnnotations;
import net.thucydides.core.reports.html.Formatter;
import java.util.Arrays;
import java.util.List;
class TestOutcomeAnnotationReader {
private final TestOutcome testOutcome;
public static TestOutcomeAnnotationReader forTestOutcome(TestOutcome testOutcome) {
return new TestOutcomeAnnotationReader(testOutcome);
}
TestOutcomeAnnotationReader(TestOutcome testOutcome) {
this.testOutcome = testOutcome;
}
public static List readIssuesIn(TestOutcome testOutcome) {
List taggedIssues = Lists.newArrayList();
if (testOutcome.getTestCase() != null) {
addMethodLevelIssuesTo(testOutcome, taggedIssues);
addClassLevelIssuesTo(testOutcome, taggedIssues);
}
addTitleLevelIssuesTo(testOutcome, taggedIssues);
return taggedIssues;
}
public static List readVersionsIn(TestOutcome testOutcome) {
List taggedVersions = Lists.newArrayList();
if (testOutcome.getTestCase() != null) {
addMethodLevelVersionsTo(testOutcome, taggedVersions);
addClassLevelVersionsTo(testOutcome, taggedVersions);
}
return taggedVersions;
}
private static void addClassLevelIssuesTo(TestOutcome testOutcome, List issues) {
String classIssue = TestAnnotations.forClass(testOutcome.getTestCase()).getAnnotatedIssueForTestCase(testOutcome.getTestCase());
if (classIssue != null) {
issues.add(classIssue);
}
String[] classIssues = TestAnnotations.forClass(testOutcome.getTestCase()).getAnnotatedIssuesForTestCase(testOutcome.getTestCase());
if (classIssues != null) {
issues.addAll(Arrays.asList(classIssues));
}
}
private static void addMethodLevelIssuesTo(TestOutcome testOutcome, List issues) {
Optional issue = TestAnnotations.forClass(testOutcome.getTestCase()).getAnnotatedIssueForMethod(testOutcome.getName());
if (issue.isPresent()) {
issues.add(issue.get());
}
String[] multipleIssues = TestAnnotations.forClass(testOutcome.getTestCase()).getAnnotatedIssuesForMethod(testOutcome.getName());
issues.addAll(Arrays.asList(multipleIssues));
}
private static void addTitleLevelIssuesTo(TestOutcome testOutcome, List issues) {
List titleIssues = Formatter.issuesIn(testOutcome.getTitle());
if (!titleIssues.isEmpty()) {
issues.addAll(titleIssues);
}
}
private static void addClassLevelVersionsTo(TestOutcome testOutcome, List versions) {
String classVersion = TestAnnotations.forClass(testOutcome.getTestCase()).getAnnotatedVersionForTestCase(testOutcome.getTestCase());
if (classVersion != null) {
versions.add(classVersion);
}
}
private static void addMethodLevelVersionsTo(TestOutcome testOutcome, List versions) {
Optional version = TestAnnotations.forClass(testOutcome.getTestCase()).getAnnotatedVersionForMethod(testOutcome.getName());
if (version.isPresent()) {
versions.add(version.get());
}
}
}