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

net.thucydides.core.model.TestResultComparison Maven / Gradle / Ivy

There is a newer version: 4.2.1
Show newest version
package net.thucydides.core.model;

import static net.thucydides.core.model.TestResult.*;

/**
 * A list of test results, used to determine the overall test result.
 */
public class TestResultComparison {

    private final TestResult testResultA;
    private final TestResult testResultB;

    public TestResultComparison(TestResult testResultA, TestResult testResultB) {

        this.testResultA = testResultA;
        this.testResultB = testResultB;
    }

    public static TestResult overallResultFor(TestResult testResultA, TestResult testResultB) {
        if (testResultA == COMPROMISED || testResultB == COMPROMISED) {
            return COMPROMISED;
        }

        if (testResultA == ERROR || testResultB == ERROR) {
            return ERROR;
        }

        if (testResultA == FAILURE || testResultB == FAILURE) {
            return FAILURE;
        }

        if (testResultA == PENDING || testResultB == PENDING) {
            return PENDING;
        }

        if (containsOnly(testResultA, testResultB, IGNORED)) {
            return IGNORED;
        }

        if (containsOnly(testResultA, testResultB, SKIPPED)) {
            return SKIPPED;
        }

        if (containsOnly(SUCCESS, IGNORED, SKIPPED)) {
            return SUCCESS;
        }
        return SUCCESS;
    }

    private static boolean containsOnly(TestResult testResultA, TestResult testResultB, final TestResult... expectedValues) {
        for (TestResult expectedValue : expectedValues) {
            if ((testResultA != expectedValue) || (testResultB != expectedValue)) {
                return false;
            }
        }
        return true;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy