All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.serenitybdd.plugins.jira.TestResultTally Maven / Gradle / Ivy

The newest version!
package net.serenitybdd.plugins.jira;


import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import net.thucydides.model.domain.TestOutcome;
import net.thucydides.model.domain.TestResult;
import net.thucydides.model.domain.TestResultList;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;


public class TestResultTally {
    
    private final ConcurrentMap> testOutcomesTally;

    public TestResultTally() {
        this.testOutcomesTally = Maps.newConcurrentMap();
    }

    public synchronized void recordResult(String issueNumber, T 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);
        if ( testOutcomesForThisIssue.stream().allMatch(TestOutcome.class::isInstance)) {
            List testOutcomes = (List)testOutcomesTally.get(issueNumber);
            List results =  testOutcomes.stream().map(TestOutcome::getResult).collect(Collectors.toList());
            return TestResultList.overallResultFrom(results);
        } else {
            return TestResultList.overallResultFrom(new ArrayList<>());
        }
    }

    public Set getIssues() {
        return testOutcomesTally.keySet();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy