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

de.bechte.junit.runners.context.statements.builder.ExpectExceptionStatementBuilder Maven / Gradle / Ivy

Go to download

This is a runner implementation that supports context hierarchies in JUnit. For more details please visit: https://github.com/bechte/junit-hierarchicalcontextrunner/wiki

There is a newer version: 4.12.2
Show newest version
package de.bechte.junit.runners.context.statements.builder;

import org.junit.Test;
import org.junit.internal.runners.statements.ExpectException;
import org.junit.runner.Description;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
import org.junit.runners.model.TestClass;

/**
 * The {@link ExpectExceptionStatementBuilder} creates a {@link ExpectException} statement that verifies that the
 * expected {@link Exception} within the {@code @Test} annotation has been thrown. If no {@link Exception} is expected,
 * the builder returns the provided next {@link Statement}.
 *
 * @deprecated The {@code expected} field of the {@code @Test} annotation is deprecated. Therefore, this builder is
 * also marked as deprecated. Please make use of the {@code @Rule} annotation.
 */
@Deprecated
public class ExpectExceptionStatementBuilder implements MethodStatementBuilder {
    public Statement createStatement(final TestClass testClass, final FrameworkMethod method, final Object target,
                                     final Statement next, final Description description, final RunNotifier notifier) {
        final Test annotation = method.getAnnotation(Test.class);
        return annotation.expected() == Test.None.class ? next : new ExpectException(next, annotation.expected());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy