|
|
|
|
@ -21,22 +21,21 @@ import java.lang.reflect.Method;
@@ -21,22 +21,21 @@ import java.lang.reflect.Method;
|
|
|
|
|
import org.junit.jupiter.api.extension.ExtensionContext; |
|
|
|
|
import org.junit.jupiter.api.extension.InvocationInterceptor; |
|
|
|
|
import org.junit.jupiter.api.extension.ReflectiveInvocationContext; |
|
|
|
|
import org.junit.platform.engine.discovery.DiscoverySelectors; |
|
|
|
|
import org.junit.platform.launcher.EngineFilter; |
|
|
|
|
import org.junit.platform.launcher.Launcher; |
|
|
|
|
import org.junit.platform.launcher.LauncherDiscoveryRequest; |
|
|
|
|
import org.junit.platform.launcher.TestPlan; |
|
|
|
|
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder; |
|
|
|
|
import org.junit.platform.launcher.core.LauncherFactory; |
|
|
|
|
import org.junit.platform.launcher.listeners.SummaryGeneratingListener; |
|
|
|
|
import org.junit.platform.launcher.listeners.TestExecutionSummary; |
|
|
|
|
|
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
import org.springframework.util.ReflectionUtils; |
|
|
|
|
|
|
|
|
|
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod; |
|
|
|
|
import static org.junit.platform.launcher.EngineFilter.includeEngines; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* JUnit {@link InvocationInterceptor} to support |
|
|
|
|
* JUnit Jupiter {@link InvocationInterceptor} to support |
|
|
|
|
* {@link CompileWithTargetClassAccess @CompileWithTargetClassAccess}. |
|
|
|
|
* |
|
|
|
|
* @author Christoph Dreis |
|
|
|
|
@ -129,22 +128,20 @@ class CompileWithTargetClassAccessExtension implements InvocationInterceptor {
@@ -129,22 +128,20 @@ class CompileWithTargetClassAccessExtension implements InvocationInterceptor {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void runTest(ClassLoader classLoader, String testClassName, |
|
|
|
|
String testMethodName) throws Throwable { |
|
|
|
|
private void runTest(ClassLoader classLoader, String testClassName, String testMethodName) |
|
|
|
|
throws Throwable { |
|
|
|
|
|
|
|
|
|
Class<?> testClass = classLoader.loadClass(testClassName); |
|
|
|
|
Method testMethod = findMethod(testClass, testMethodName); |
|
|
|
|
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request() |
|
|
|
|
.selectors(DiscoverySelectors.selectMethod(testClass, testMethod)) |
|
|
|
|
.filters(EngineFilter.includeEngines("junit-jupiter")) |
|
|
|
|
.selectors(selectMethod(testClass, testMethod)) |
|
|
|
|
.filters(includeEngines("junit-jupiter")) |
|
|
|
|
.build(); |
|
|
|
|
Launcher launcher = LauncherFactory.create(); |
|
|
|
|
TestPlan testPlan = launcher.discover(request); |
|
|
|
|
SummaryGeneratingListener listener = new SummaryGeneratingListener(); |
|
|
|
|
launcher.registerTestExecutionListeners(listener); |
|
|
|
|
launcher.execute(testPlan); |
|
|
|
|
Launcher launcher = LauncherFactory.create(); |
|
|
|
|
launcher.execute(request, listener); |
|
|
|
|
TestExecutionSummary summary = listener.getSummary(); |
|
|
|
|
if (!CollectionUtils.isEmpty(summary.getFailures())) { |
|
|
|
|
if (summary.getTotalFailureCount() > 0) { |
|
|
|
|
throw summary.getFailures().get(0).getException(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -167,8 +164,7 @@ class CompileWithTargetClassAccessExtension implements InvocationInterceptor {
@@ -167,8 +164,7 @@ class CompileWithTargetClassAccessExtension implements InvocationInterceptor {
|
|
|
|
|
@FunctionalInterface |
|
|
|
|
interface Action { |
|
|
|
|
|
|
|
|
|
static Action NONE = () -> { |
|
|
|
|
}; |
|
|
|
|
Action NONE = () -> {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void run() throws Throwable; |
|
|
|
|
|