@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; }
@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); } }
/** * 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; }
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()); }
@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))); }