Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.amazonaws.services.simpleworkflow.flow.junit;
 
 import java.util.List;
 
 import  org.junit.Test;
 import  org.junit.rules.MethodRule;
 import  org.junit.runners.BlockJUnit4ClassRunner;
 import  org.junit.runners.model.FrameworkMethod;
 import  org.junit.runners.model.InitializationError;
import  org.junit.runners.model.Statement;

To be used instead of BlockJUnit4ClassRunner when testing asynchronous code. Requires WorkflowTest rule (annotated with

Author(s):
fateev
Rule:
to be present in the tested class.
public class FlowBlockJUnit4ClassRunner extends BlockJUnit4ClassRunner {
    private long timeout;
    private Class<? extends ThrowableexpectedException;
    public FlowBlockJUnit4ClassRunner(Class<?> klassthrows InitializationError {
        super(klass);
    }
    @Override
    protected Statement withPotentialTimeout(FrameworkMethod methodfinal Object test, Statement next) {
        Test annotation = method.getAnnotation(Test.class);
         = annotation.timeout();
        if ( > 0 &&  != null) {
        }
        return next;
    }
    @Override
    protected List<MethodRule> rules(Object test) {
        List<MethodRule> result = super.rules(test);
        for (MethodRule methodRule : result) {
            if (WorkflowTestBase.class.isAssignableFrom(methodRule.getClass())) {
                 = (WorkflowTestBasemethodRule;
                .setFlowTestRunner(true);
                if ( > 0) {
                    .setTestTimeoutActualTimeMilliseconds();
                }
                if ( != null) {
                    .setExpectedException();
                }
            }
        }
        return result;
    }
    @Override
    protected Statement possiblyExpectingExceptions(FrameworkMethod methodObject test, Statement next) {
        Test annotation = method.getAnnotation(Test.class);
        Class<? extends Throwableexpected = annotation.expected();
        if (expected != Test.None.class) {
             = expected;
            if ( != null) {
            }
        }
        return next;
    }
New to GrepCode? Check out our FAQ X