下面列出了org.junit.jupiter.api.extension.ExtensionContext#getDisplayName() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public Object resolveParameter(
ParameterContext parameterContext, ExtensionContext extensionContext)
throws ParameterResolutionException {
checkExtensionContext(extensionContext);
CloseableTestKit closeableTestKit =
getStore(extensionContext).get(TESTKIT_KEY, CloseableTestKit.class);
TestKit testKit;
if (closeableTestKit == null) {
testKit = buildTestKit(parameterContext, extensionContext);
getStore(extensionContext).put(TESTKIT_KEY, new CloseableTestKit(testKit));
} else {
// Throw an exception if TestKit was already instantiated in this context, but user tries to
// reconfigure it
if (annotationsUsed(parameterContext)) {
throw new ParameterResolutionException("TestKit was parameterized with annotations after"
+ " being instantiated in " + extensionContext.getDisplayName());
}
testKit = closeableTestKit.getTestKit();
}
return testKit;
}
private TestKit.Builder createTestKitBuilder(ParameterContext parameterContext,
ExtensionContext extensionContext) {
TestKit.Builder testKitBuilder = templateTestKitBuilder.shallowCopy();
Optional<Auditor> auditorAnnotation = parameterContext.findAnnotation(Auditor.class);
Optional<Validator> validatorAnnotation = parameterContext.findAnnotation(Validator.class);
if (auditorAnnotation.isPresent() && validatorAnnotation.isPresent()) {
throw new ParameterResolutionException("Both @Validator and @Auditor annotations were used"
+ " in " + extensionContext.getDisplayName());
}
auditorAnnotation.ifPresent(auditor -> testKitBuilder.withNodeType(EmulatedNodeType.AUDITOR));
validatorAnnotation.ifPresent(validator ->
testKitBuilder.withNodeType(EmulatedNodeType.VALIDATOR));
Optional<ValidatorCount> validatorCountAnnotation =
parameterContext.findAnnotation(ValidatorCount.class);
validatorCountAnnotation.ifPresent(validatorCount ->
testKitBuilder.withValidators(validatorCount.value()));
return testKitBuilder;
}
public static Path getLogsPath(ExtensionContext extensionContext, String rootFolder) {
String testMethod = extensionContext.getDisplayName();
Class<?> testClass = extensionContext.getRequiredTestClass();
Path path = Environment.getInstance().testLogDir().resolve(Paths.get(rootFolder, testClass.getName()));
if (testMethod != null) {
path = path.resolve(testMethod);
}
return path;
}