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

org.junit.rules.ExpectedExceptionMatcherBuilder Maven / Gradle / Ivy

Go to download

A collection of tests that can certify language implementation to be compliant with most recent requirements of the Truffle infrastructure and tooling.

The newest version!
package org.junit.rules;

import static org.hamcrest.CoreMatchers.allOf;
import static org.junit.matchers.JUnitMatchers.isThrowable;

import java.util.ArrayList;
import java.util.List;

import org.hamcrest.Matcher;

/**
 * Builds special matcher used by {@link ExpectedException}.
 */
class ExpectedExceptionMatcherBuilder {

    private final List> fMatchers = new ArrayList>();

    void add(Matcher matcher) {
        fMatchers.add(matcher);
    }

    boolean expectsThrowable() {
        return !fMatchers.isEmpty();
    }

    Matcher build() {
        return isThrowable(allOfTheMatchers());
    }

    private Matcher allOfTheMatchers() {
        if (fMatchers.size() == 1) {
            return cast(fMatchers.get(0));
        }
        return allOf(castedMatchers());
    }

    @SuppressWarnings({"unchecked", "rawtypes"})
    private List> castedMatchers() {
        return new ArrayList>((List) fMatchers);
    }

    @SuppressWarnings("unchecked")
    private Matcher cast(Matcher singleMatcher) {
        return (Matcher) singleMatcher;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy