下面列出了org.junit.internal.runners.statements.RunAfters#org.junit.internal.runners.statements.RunBefores 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected Statement withBeforeClasses(final Statement statement) {
// add test environment setup
try {
final Method setupMethod = GeoWaveITRunner.class.getDeclaredMethod("setup");
setupMethod.setAccessible(true);
return super.withBeforeClasses(
new RunBefores(
statement,
Collections.singletonList(new FrameworkMethod(setupMethod)),
this));
} catch (NoSuchMethodException | SecurityException e) {
LOGGER.warn("Unable to find setup method", e);
}
return super.withBeforeClasses(statement);
}
@Override
protected Statement withBeforeClasses(Statement statement) {
List<FrameworkMethod> befores = wrapInWebTauTestEntry(getTestClass()
.getAnnotatedMethods(BeforeClass.class));
return befores.isEmpty() ? statement :
new RunBefores(statement, befores, null);
}
protected Statement withColaBefores(FrameworkMethod method, Object target,
Statement statement) {
List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(
ColaBefore.class);
return befores.isEmpty() ? statement : new RunBefores(statement,
befores, target);
}
protected Statement withColaBefores(FrameworkMethod method, Object target,
Statement statement) {
List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(
ColaBefore.class);
return befores.isEmpty() ? statement : new RunBefores(statement,
befores, target);
}
private Statement withEnvironment(Statement statement) {
List<FrameworkMethod> environment = super.getTestClass().getAnnotatedMethods(Environment.class);
if (environment.isEmpty()) {
log.error("@Environment annotation not used for system test , {}", getTestClass().getName());
return statement;
} else {
return new RunBefores(statement, environment, null);
}
}
/**
* Adds any @BeforeAll methods to be run before the normal @Before annotated methods for the first test method only.
* <p>
* {@inheritDoc}
*/
@Override
protected Statement withBefores(final FrameworkMethod method, final Object target, final Statement stmt) {
ensureInitialized();
Statement statement = super.withBefores(method, target, stmt); // NOPMD.CloseResource
if (method.equals(expectedMethods.get(0))) {
// reverse BeforeAll method order to get a 'runs top to bottom' order
final List<FrameworkMethod> befores = Lists.reverse(getTestClass().getAnnotatedMethods(BeforeAll.class));
statement = befores.isEmpty() ? statement : new RunBefores(statement, befores, target);
}
return statement;
}
/**
* Returns a {@link org.junit.runners.model.Statement}: run all non-overridden {@code @BeforeClass} methods on this class
* and superclasses before executing {@code statement}; if any throws an
* Exception, stop execution and pass the exception on.
*/
protected Statement withBeforeClasses(Statement statement) {
List<FrameworkMethod> befores = getTestClass()
.getAnnotatedMethods(BeforeClass.class);
return befores.isEmpty() ? statement :
new RunBefores(statement, befores, null);
}
/**
* Returns a {@link org.junit.runners.model.Statement}: run all non-overridden {@code @Before}
* methods on this class and superclasses before running {@code next}; if
* any throws an Exception, stop execution and pass the exception on.
*
* @deprecated Will be private soon: use Rules instead
*/
@Deprecated
protected Statement withBefores(FrameworkMethod method, Object target,
Statement statement) {
List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(Before.class);
return befores.isEmpty() ? statement : new RunBefores(statement,
befores, target);
}
/**
* @see org.junit.runners.BlockJUnit4ClassRunner#withBefores(FrameworkMethod, Object, Statement)
*/
private Statement withBefores( Object target, Statement statement )
{
List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods( Before.class );
return befores.isEmpty() ? statement : new RunBefores( statement, befores, target );
}
public static RunBeforesContiPerfAdapter create(RunBefores runBefores, Statement next)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
List<FrameworkMethod> befores = ReflectionUtils.getObjectByField(runBefores, runBefores.getClass(), "befores");
Object target = ReflectionUtils.getObjectByField(runBefores, runBefores.getClass(), "target");
return new RunBeforesContiPerfAdapter(next, befores, target);
}
private Statement withBeforeClasses(final Statement base) {
List<FrameworkMethod> befores = getBeforeClassMethods();
return befores.isEmpty() ? base : new RunBefores(base, befores, null);
}
@Override
protected Statement withBeforeClasses(Statement statement) {
List<FrameworkMethod> befores= getTestClass().getAnnotatedMethods(BeforePinpointPluginTest.class);
return befores.isEmpty() ? statement : new RunBefores(statement, befores, null);
}
private Statement withBefores(Object target, Statement statement) {
List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(Before.class);
return befores.isEmpty() ? statement : new RunBefores(statement, befores, target);
}