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

net.thucydides.core.matchers.TestOutcomeResultsMatcher Maven / Gradle / Ivy

package net.thucydides.core.matchers;

import net.thucydides.core.model.TestOutcome;
import net.thucydides.core.model.TestResult;
import net.thucydides.core.model.TestStep;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;

import java.util.Arrays;
import java.util.List;

import static ch.lambdaj.Lambda.extract;
import static ch.lambdaj.Lambda.on;

/**
 * Does a test outcome contain a given list of results, in the specified order?
 */
public class TestOutcomeResultsMatcher extends TypeSafeMatcher {

    private final List expectedTestResults;

    public TestOutcomeResultsMatcher(TestResult... expectedTestResults) {
        this.expectedTestResults = Arrays.asList(expectedTestResults);
    }

    @Override
    public boolean matchesSafely(TestOutcome testOutcome) {
        List allSteps = testOutcome.getFlattenedTestSteps();
        List allTestResults = extract(allSteps, on(TestStep.class).getResult());
        return allTestResults.equals(expectedTestResults);
    }

    @Override
    public void describeTo(Description description) {
        description.appendText("a test outcome with results " + Arrays.toString(expectedTestResults.toArray()));
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy