org.junit.internal.runners.statements.ExpectException Java Examples

The following examples show how to use org.junit.internal.runners.statements.ExpectException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParameterTest.java    From openCypher with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.junit.runners.BlockJUnit4ClassRunner#possiblyExpectingExceptions(FrameworkMethod, Object, Statement)
 */
private Statement possiblyExpectingExceptions( FrameworkMethod method, Statement next )
{
    Test annotation = method.getAnnotation( Test.class );
    return getExpectedException( annotation ) != null ? new ExpectException(
            next, getExpectedException( annotation ) ) : next;
}
 
Example #2
Source File: JUnit4Runner.java    From tomee with Apache License 2.0 5 votes vote down vote up
protected Statement possiblyExpectingAccessException(final Statement next, final boolean failWithAccessException) {
    if (failWithAccessException) {
        return new ExpectException(next, EJBAccessException.class);
    } else {
        return next;
    }
}
 
Example #3
Source File: EndToEndRunner.java    From buck with Apache License 2.0 5 votes vote down vote up
private Statement withExpectedExceptions(EndToEndTestDescriptor child, Statement statement) {
  FrameworkMethod verificationMethod = child.getMethod();
  Test annotation = verificationMethod.getAnnotation(Test.class);
  Class<? extends Throwable> expectedException = annotation.expected();
  // ExpectException doesn't account for the default Test.None.class, so skip expecting an
  // exception if it is Test.None.class
  if (expectedException.isAssignableFrom(Test.None.class)) {
    return statement;
  }
  return new ExpectException(statement, expectedException);
}
 
Example #4
Source File: LoadTimeWeavableTestRunner.java    From rice with Educational Community License v2.0 3 votes vote down vote up
/**
 * Returns a {@link org.junit.runners.model.Statement}: if {@code method}'s {@code @Test} annotation
 * has the {@code expecting} attribute, return normally only if {@code next}
 * throws an exception of the correct type, and throw an exception
 * otherwise.
 *
 * @deprecated Will be private soon: use Rules instead
 */
@Deprecated
protected Statement possiblyExpectingExceptions(FrameworkMethod method,
        Object test, Statement next) {
    Test annotation = method.getAnnotation(Test.class);
    return expectsException(annotation) ? new ExpectException(next,
            getExpectedException(annotation)) : next;
}
 
Example #5
Source File: SpringJUnit4ClassRunner.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Perform the same logic as
 * {@link BlockJUnit4ClassRunner#possiblyExpectingExceptions(FrameworkMethod, Object, Statement)}
 * except that the <em>expected exception</em> is retrieved using
 * {@link #getExpectedException(FrameworkMethod)}.
 */
@Override
protected Statement possiblyExpectingExceptions(FrameworkMethod frameworkMethod, Object testInstance, Statement next) {
	Class<? extends Throwable> expectedException = getExpectedException(frameworkMethod);
	return (expectedException != null ? new ExpectException(next, expectedException) : next);
}
 
Example #6
Source File: SpringJUnit4ClassRunner.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Perform the same logic as
 * {@link BlockJUnit4ClassRunner#possiblyExpectingExceptions(FrameworkMethod, Object, Statement)}
 * except that the <em>expected exception</em> is retrieved using
 * {@link #getExpectedException(FrameworkMethod)}.
 */
@Override
protected Statement possiblyExpectingExceptions(FrameworkMethod frameworkMethod, Object testInstance, Statement next) {
	Class<? extends Throwable> expectedException = getExpectedException(frameworkMethod);
	return (expectedException != null ? new ExpectException(next, expectedException) : next);
}
 
Example #7
Source File: SpringJUnit4ClassRunner.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Perform the same logic as
 * {@link BlockJUnit4ClassRunner#possiblyExpectingExceptions(FrameworkMethod, Object, Statement)}
 * except that the <em>expected exception</em> is retrieved using
 * {@link #getExpectedException(FrameworkMethod)}.
 */
@Override
protected Statement possiblyExpectingExceptions(FrameworkMethod frameworkMethod, Object testInstance, Statement next) {
	Class<? extends Throwable> expectedException = getExpectedException(frameworkMethod);
	return (expectedException != null ? new ExpectException(next, expectedException) : next);
}