net.thucydides.plugins.jira.TestResultTally Maven / Gradle / Ivy
package net.thucydides.plugins.jira;
import ch.lambdaj.function.convert.Converter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import net.thucydides.core.model.TestOutcome;
import net.thucydides.core.model.TestResult;
import net.thucydides.core.model.TestResultList;
import java.util.List;
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.ConcurrentMap;
import static ch.lambdaj.Lambda.convert;
public class TestResultTally {
private final ConcurrentMap> testOutcomesTally;
public TestResultTally() {
this.testOutcomesTally = Maps.newConcurrentMap();
}
public synchronized void recordResult(String issueNumber, TestOutcome outcome) {
getTestOutcomeListForIssue(issueNumber).add(outcome);
}
public List getTestOutcomesForIssue(String issueNumber) {
return ImmutableList.copyOf(getTestOutcomeListForIssue(issueNumber));
}
protected List getTestOutcomeListForIssue(final String issueNumber) {
List resultTallyForIssue = testOutcomesTally.get(issueNumber);
if (resultTallyForIssue == null) {
testOutcomesTally.putIfAbsent(issueNumber, new Vector());
}
return testOutcomesTally.get(issueNumber);
}
public TestResult getResultForIssue(final String issueNumber) {
List testOutcomesForThisIssue = testOutcomesTally.get(issueNumber);
TestResultList overallResults = TestResultList.of(convert(testOutcomesForThisIssue, toTestResults()));
return overallResults.getOverallResult();
}
private Converter toTestResults() {
return new Converter() {
public TestResult convert(TestOutcome from) {
return from.getResult();
}
};
}
public Set getIssues() {
return testOutcomesTally.keySet();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy