-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
HierarchicalTestExecutor.java
64 lines (55 loc) · 2.39 KB
/
HierarchicalTestExecutor.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
/*
* Copyright 2015-2018 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* http://www.eclipse.org/legal/epl-v20.html
*/
package org.junit.platform.engine.support.hierarchical;
import java.util.concurrent.Future;
import org.junit.platform.engine.EngineExecutionListener;
import org.junit.platform.engine.ExecutionRequest;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.TestEngine;
/**
* Implementation core of all {@link TestEngine TestEngines} that wish to
* use the {@link Node} abstraction as the driving principle for structuring
* and executing test suites.
*
* <p>A {@code HierarchicalTestExecutor} is instantiated by a concrete
* implementation of {@link HierarchicalTestEngine} and takes care of
* executing nodes in the hierarchy in the appropriate order as well as
* firing the necessary events in the {@link EngineExecutionListener}.
*
* @param <C> the type of {@code EngineExecutionContext} used by the
* {@code HierarchicalTestEngine}
* @since 1.0
*/
class HierarchicalTestExecutor<C extends EngineExecutionContext> {
private final ExecutionRequest request;
private final C rootContext;
private final HierarchicalTestExecutorService executorService;
private final ThrowableCollector.Factory throwableCollectorFactory;
HierarchicalTestExecutor(ExecutionRequest request, C rootContext, HierarchicalTestExecutorService executorService,
ThrowableCollector.Factory throwableCollectorFactory) {
this.request = request;
this.rootContext = rootContext;
this.executorService = executorService;
this.throwableCollectorFactory = throwableCollectorFactory;
}
Future<Void> execute() {
NodeTestTask<C> rootTestTask = prepareNodeTestTaskTree();
rootTestTask.setParentContext(this.rootContext);
return this.executorService.submit(rootTestTask);
}
NodeTestTask<C> prepareNodeTestTaskTree() {
TestDescriptor rootTestDescriptor = this.request.getRootTestDescriptor();
EngineExecutionListener executionListener = this.request.getEngineExecutionListener();
NodeTestTask<C> rootTestTask = new NodeTestTask<>(rootTestDescriptor, executionListener, this.executorService,
this.throwableCollectorFactory);
new NodeTestTaskWalker().walk(rootTestTask);
return rootTestTask;
}
}