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

io.github.olib963.javatest.matchers.internal.ThrowsExceptionMatcher Maven / Gradle / Ivy

There is a newer version: 0.2.0
Show newest version
package io.github.olib963.javatest.matchers.internal;

import io.github.olib963.javatest.matchers.CheckedRunnable;
import io.github.olib963.javatest.matchers.MatchResult;
import io.github.olib963.javatest.matchers.Matcher;

public class ThrowsExceptionMatcher implements Matcher {
    private final Matcher thrownMatcher;

    public ThrowsExceptionMatcher(Matcher thrownMatcher) {
        this.thrownMatcher = thrownMatcher;
    }

    @Override
    public MatchResult matches(CheckedRunnable value) {
        try {
            value.run();
            return MatchResult.mismatch("no exception was thrown");
        } catch (Exception e) {
            return thrownMatcher.matches(e);
        }
    }

    @Override
    public String describeExpected() {
        return "throw an exception that was expected to " + thrownMatcher.describeExpected();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy