Java 类org.junit.platform.commons.util.AnnotationUtils 实例源码

项目:mastering-junit5    文件:OsCondition.java   
@Override
public ConditionEvaluationResult evaluateExecutionCondition(
        ExtensionContext context) {

    Optional<AnnotatedElement> element = context.getElement();
    ConditionEvaluationResult out = ConditionEvaluationResult
            .enabled("@DisabledOnOs is not present");

    Optional<DisabledOnOs> disabledOnOs = AnnotationUtils
            .findAnnotation(element, DisabledOnOs.class);

    if (disabledOnOs.isPresent()) {
        Os myOs = Os.determine();
        if (Arrays.asList(disabledOnOs.get().value()).contains(myOs)) {
            out = ConditionEvaluationResult
                    .disabled("Test is disabled on " + myOs);
        } else {
            out = ConditionEvaluationResult
                    .enabled("Test is not disabled on " + myOs);
        }
    }

    System.out.println("--> " + out.getReason().get());
    return out;
}
项目:autotest    文件:AutoTestParameterResolver.java   
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
        throws ParameterResolutionException {
    Object argument = arguments[parameterContext.getIndex()];
    Parameter parameter = parameterContext.getParameter();
    Optional<ConvertWith> annotation = AnnotationUtils.findAnnotation(parameter, ConvertWith.class);
    // @formatter:off
    ArgumentConverter argumentConverter = annotation.map(ConvertWith::value)
            .map(clazz -> (ArgumentConverter) ReflectionUtils.newInstance(clazz))
            .map(converter -> AnnotationConsumerInitializer.initialize(parameter, converter))
            .orElse(DefaultArgumentConverter.INSTANCE);
    // @formatter:on
    try {
        return argumentConverter.convert(argument, parameterContext);
    } catch (Exception ex) {
        throw new ParameterResolutionException("参数转换出错:" + parameter.getType().getName(),
                ex);
    }
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:OsCondition.java   
@Override
public ConditionEvaluationResult evaluateExecutionCondition(
        ExtensionContext context) {

    Optional<AnnotatedElement> element = context.getElement();
    ConditionEvaluationResult out = ConditionEvaluationResult
            .enabled("@DisabledOnOs is not present");

    Optional<DisabledOnOs> disabledOnOs = AnnotationUtils
            .findAnnotation(element, DisabledOnOs.class);

    if (disabledOnOs.isPresent()) {
        Os myOs = Os.determine();
        if (Arrays.asList(disabledOnOs.get().value()).contains(myOs)) {
            out = ConditionEvaluationResult
                    .disabled("Test is disabled on " + myOs);
        } else {
            out = ConditionEvaluationResult
                    .enabled("Test is not disabled on " + myOs);
        }
    }

    System.out.println("--> " + out.getReason().get());
    return out;
}
项目:jabref    文件:CIServerCondition.java   
/**
 * Containers and tests are disabled if they are annotated with {@link DisabledOnCIServer} and they tests are run on
 * the CI server.
 */
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
    if (!isCIServer()) {
        return ENABLED;
    }

    Optional<AnnotatedElement> element = context.getElement();
    Optional<DisabledOnCIServer> disabled = AnnotationUtils.findAnnotation(element, DisabledOnCIServer.class);
    if (disabled.isPresent()) {
        String reason = disabled.map(DisabledOnCIServer::value)
                .filter(StringUtil::isNotBlank)
                .orElseGet(() -> element.get() + " is disabled on CI server");
        return ConditionEvaluationResult.disabled(reason);
    }

    return ENABLED;
}
项目:video-recorder-java    文件:VideoExtension.java   
private boolean videoDisabled(Method testMethod) {
  Optional<com.automation.remarks.video.annotations.Video> video = AnnotationUtils.findAnnotation(testMethod, com.automation.remarks.video.annotations.Video.class);

  return video.map(v -> !videoEnabled(v))
          .orElseGet(() -> true);

  //return !video.isPresent() && !videoEnabled(video.get());
}
项目:junit-dataprovider    文件:AbstractDataProviderInvocationContextProvider.java   
@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
    Method testMethod = context.getRequiredTestMethod();

    return AnnotationUtils.findAnnotation(testMethod, testAnnotationClass)
            .map(annotation -> provideInvocationContexts(context, annotation))
            .orElseThrow(() -> new ExtensionConfigurationException(String.format(
                    "Could not find annotation '%s' on test method '%s'.", testAnnotationClass, testMethod)));
}