-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
MethodExtensionContext.java
87 lines (69 loc) · 2.61 KB
/
MethodExtensionContext.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
85
86
87
/*
* Copyright 2015-2024 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
*
* https://www.eclipse.org/legal/epl-v20.html
*/
package org.junit.jupiter.engine.descriptor;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.Optional;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.jupiter.api.extension.ExecutableInvoker;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestInstances;
import org.junit.jupiter.engine.config.JupiterConfiguration;
import org.junit.platform.engine.EngineExecutionListener;
import org.junit.platform.engine.support.hierarchical.Node;
import org.junit.platform.engine.support.hierarchical.ThrowableCollector;
/**
* @since 5.0
*/
final class MethodExtensionContext extends AbstractExtensionContext<TestMethodTestDescriptor> {
private final ThrowableCollector throwableCollector;
private TestInstances testInstances;
MethodExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener,
TestMethodTestDescriptor testDescriptor, JupiterConfiguration configuration,
ThrowableCollector throwableCollector, ExecutableInvoker executableInvoker) {
super(parent, engineExecutionListener, testDescriptor, configuration, executableInvoker);
this.throwableCollector = throwableCollector;
}
@Override
public Optional<AnnotatedElement> getElement() {
return Optional.of(getTestDescriptor().getTestMethod());
}
@Override
public Optional<Class<?>> getTestClass() {
return Optional.of(getTestDescriptor().getTestClass());
}
@Override
public Optional<Lifecycle> getTestInstanceLifecycle() {
return getParent().flatMap(ExtensionContext::getTestInstanceLifecycle);
}
@Override
public Optional<Object> getTestInstance() {
return getTestInstances().map(TestInstances::getInnermostInstance);
}
@Override
public Optional<TestInstances> getTestInstances() {
return Optional.ofNullable(this.testInstances);
}
void setTestInstances(TestInstances testInstances) {
this.testInstances = testInstances;
}
@Override
public Optional<Method> getTestMethod() {
return Optional.of(getTestDescriptor().getTestMethod());
}
@Override
public Optional<Throwable> getExecutionException() {
return Optional.ofNullable(this.throwableCollector.getThrowable());
}
@Override
protected Node.ExecutionMode getPlatformExecutionMode() {
return getTestDescriptor().getExecutionMode();
}
}