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

org.junit.internal.runners.statements.ExpectException Maven / Gradle / Ivy

Go to download

JUnit is a regression testing framework written by Erich Gamma and Kent Beck. It is used by the developer who implements unit tests in Java.

There is a newer version: 4.13.2
Show newest version
package org.junit.internal.runners.statements;

import org.junit.internal.AssumptionViolatedException;
import org.junit.runners.model.Statement;

public class ExpectException extends Statement {
    private Statement fNext;
    private final Class fExpected;

    public ExpectException(Statement next, Class expected) {
        fNext = next;
        fExpected = expected;
    }

    @Override
    public void evaluate() throws Exception {
        boolean complete = false;
        try {
            fNext.evaluate();
            complete = true;
        } catch (AssumptionViolatedException e) {
            throw e;
        } catch (Throwable e) {
            if (!fExpected.isAssignableFrom(e.getClass())) {
                String message = "Unexpected exception, expected<"
                        + fExpected.getName() + "> but was<"
                        + e.getClass().getName() + ">";
                throw new Exception(message, e);
            }
        }
        if (complete) {
            throw new AssertionError("Expected exception: "
                    + fExpected.getName());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy