org.nohope.test.runner.ExpectedExceptionSkippingRunner Maven / Gradle / Ivy
package org.nohope.test.runner;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
/**
* Simple {@link org.junit.runner.Runner JUnit runner} which allows to skip
* test if particular exception type(s) was thrown by test method.
*
* Usage:
*
* @RunWith({@link ExpectedExceptionSkippingRunner NameAwareRunner.class})
* public class MyDatabaseTest {
*
* @Test
* @{@link SkipOnException SkipOnException}(ConnectionException.class)
* public void testDBConnection() {
* ...
* }
* }
*
*
* @author Ketoth Xupack
* @since 18/01/11 05:40 PM
*/
public final class ExpectedExceptionSkippingRunner extends BlockJUnit4ClassRunner {
/**
* Runner constructor.
*
* @param clazz test class
* @throws InitializationError on runner initialization error
*/
public ExpectedExceptionSkippingRunner(final Class> clazz) throws InitializationError {
super(clazz);
}
@Override
protected Statement methodBlock(final FrameworkMethod method) {
return new SkipStatement(super.methodBlock(method),
method.getAnnotation(SkipOnException.class));
}
}