/
RunIAfterTestExtensions.java
84 lines (74 loc) · 2.65 KB
/
RunIAfterTestExtensions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*******************************************************************************
* Copyright (c) 2017 Red Hat, Inc and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc - initial API and implementation
*******************************************************************************/
package org.eclipse.reddeer.junit.internal.runner.statement;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.reddeer.common.logging.Logger;
import org.eclipse.reddeer.junit.extensionpoint.IAfterTest;
import org.eclipse.reddeer.junit.screenshot.ScreenshotCapturer;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.MultipleFailureException;
import org.junit.runners.model.Statement;
import org.junit.runners.model.TestClass;
/**
*
* Statement which runs methods of defined extensions. Upon failure a screenshot is captured.
*
* @author Lucia Jelinkova
*
*/
public class RunIAfterTestExtensions extends AbstractStatementWithScreenshot {
private static final Logger log = Logger.getLogger(RunIAfterTestExtensions.class);
private final List<IAfterTest> afters;
/**
* Instantiates a new run i after test extensions.
*
* @param config the config
* @param next the next
* @param testClass the test class
* @param method the method
* @param target the target
* @param afters the afters
*/
public RunIAfterTestExtensions(String config, Statement next, TestClass testClass, FrameworkMethod method,
Object target, List<IAfterTest> afters) {
super(config, next, testClass, method, target);
this.afters = afters;
}
@Override
public void evaluate() throws Throwable {
List<Throwable> errors = new ArrayList<Throwable>();
try {
nextStatement.evaluate();
} catch (Throwable e) {
errors.add(e);
}
IAfterTest after = null;
log.debug("Run after test extensions for test class " + testClass.getJavaClass().getName());
for (IAfterTest each : afters) {
try {
after = each;
if (after.hasToRun()){
log.debug("Run method runAfterTest() of class " + after.getClass().getCanonicalName());
after.runAfterTest(config, target, frameworkMethod);
}
} catch (Throwable e) {
if(ScreenshotCapturer.shouldCaptureScreenshotOnException(e)){
log.error("Run method runAfterTest() of class " + after.getClass().getCanonicalName() + " failed", e);
createScreenshot("AfterTestExt", after.getClass());
}
errors.add(e);
}
}
MultipleFailureException.assertEmpty(errors);
}
}