Java Code Examples for org.junit.jupiter.api.extension.ExtensionContext#getDisplayName()

The following examples show how to use org.junit.jupiter.api.extension.ExtensionContext#getDisplayName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestKitExtension.java    From exonum-java-binding with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: TestKitExtension.java    From exonum-java-binding with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: TestUtils.java    From enmasse with Apache License 2.0 5 votes vote down vote up
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;
}