• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ConditionEvaluationResult类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.junit.jupiter.api.extension.ConditionEvaluationResult的典型用法代码示例。如果您正苦于以下问题:Java ConditionEvaluationResult类的具体用法?Java ConditionEvaluationResult怎么用?Java ConditionEvaluationResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ConditionEvaluationResult类属于org.junit.jupiter.api.extension包,在下文中一共展示了ConditionEvaluationResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: evaluateExecutionCondition

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
@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;
}
 
开发者ID:bonigarcia,项目名称:mastering-junit5,代码行数:26,代码来源:OsCondition.java


示例2: evaluate

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
private ConditionEvaluationResult evaluate(
    LinkedList<String> displayName,
    ExtensionContext context) {
  Optional<ConditionEvaluationResult> result =
      context
          .getElement()
          .flatMap(element -> evaluateElement(displayName, element));

  if (result.isPresent()) {
    return result.get();
  }

  displayName.addFirst(context.getDisplayName());
  return context.getParent()
      .map(parent -> evaluate(displayName, parent))
      .orElse(ConditionEvaluationResult.enabled(null));
}
 
开发者ID:JeffreyFalgout,项目名称:junit5-extensions,代码行数:18,代码来源:TestDisabler.java


示例3: evaluateExecutionCondition

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
@Override
public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext context) {
  return context.getElement()
                .flatMap(annotatedElement -> findAnnotation(annotatedElement, EnabledOnOperatingSystem.class))
                .map(EnabledOnOperatingSystem::value)
                .map(enabledOses -> Objects.requireNonNull(enabledOses, "OperatingSystem value must not be null"))
                .map(enabledOses -> Arrays.stream(enabledOses)
                                          .filter(OperatingSystem::isRunning)
                                          .collect(Collectors.collectingAndThen(Collectors.toList(), runningOses -> {
                      if (!runningOses.isEmpty()) {
                        return enabled("Enabled for OperatingSystem" + runningOses);
                      } else {
                        return disabled("Current supported OperatingSystem types=" + OperatingSystem.current() + " does not contain "
                                            + Arrays.toString(enabledOses));
                      }
                    }))
                ).orElse(DEFAULT);
}
 
开发者ID:mkobit,项目名称:junit5-conditional-execution-extensions,代码行数:19,代码来源:EnabledOnOperatingSystemCondition.java


示例4: evaluateExecutionCondition

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {

    // Search for the @DisabledWeekdays annotation from the TestExtensionContext
    Optional<AnnotatedElement> contextElement = context.getElement();
    AnnotatedElement annotatedElement = contextElement.orElse(null);

    if (annotatedElement == null) return null;

    DisabledWeekdays weekdayAnnotation = annotatedElement.getAnnotation(DisabledWeekdays.class);

    // Determine whether the test should be disabled
    boolean weekdayToday = IntStream.of(weekdayAnnotation.value())
            .anyMatch(day -> day == Calendar.getInstance().get(Calendar.DAY_OF_WEEK));

    // Return a ConditionEvaluationResult based on the outcome of the boolean weekdayToday
    return weekdayToday ?
            ConditionEvaluationResult.disabled("I spare you today.") :
            ConditionEvaluationResult.enabled("Don't spare you on other days though >:(");
}
 
开发者ID:msg-DAVID-GmbH,项目名称:JUnit-5-Quick-Start-Guide-with-AssertJ-Spring-TestFX-Mockito,代码行数:21,代码来源:DisabledOnWeekday.java


示例5: evaluateExecutionCondition

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:JabRef,项目名称:jabref,代码行数:22,代码来源:CIServerCondition.java


示例6: isTypeEnabled

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
ConditionEvaluationResult isTypeEnabled(GenerateVideo gv) {
    Type type = gv.value();
    if (type == ALL) return ENABLED_TYPE;
    if (!EncoderY4M.LOSSLESS && type == MAIN) return ENABLED_TYPE;
    if (EncoderY4M.LOSSLESS && type == LOSSLESS) return ENABLED_TYPE;
    return DISABLED_TYPE;
}
 
开发者ID:testing-av,项目名称:testing-video,代码行数:8,代码来源:GenerateVideoExtension.java


示例7: evaluateExecutionCondition

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
  AnnotatedElement element = extensionContext.getElement().orElseThrow(AssertionError::new);
  Disabled disabled = findAnnotation(element, Disabled.class).orElseThrow(AssertionError::new);
  String name = disabled.value();
  String reason = name + "=" + System.getProperty(name);
  boolean result = Boolean.getBoolean(name);
  if (disabled.not()) {
    result = !result;
  }
  if (result) {
    return ConditionEvaluationResult.disabled(reason);
  }
  return ConditionEvaluationResult.enabled(reason);
}
 
开发者ID:sormuras,项目名称:bach,代码行数:16,代码来源:DisabledCondition.java


示例8: evaluateElement

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
Optional<ConditionEvaluationResult> evaluateElement(
    List<String> currentDisplayName,
    AnnotatedElement element) {
  List<Disable> disabledTests = findRepeatableAnnotations(element, Disable.class);

  return disabledTests
      .stream()
      .filter(
          disabledTest -> Arrays.asList(disabledTest.value()).equals(currentDisplayName))
      .map(disabledTest -> ConditionEvaluationResult.disabled(disabledTest.reason()))
      .findFirst();
}
 
开发者ID:JeffreyFalgout,项目名称:junit5-extensions,代码行数:13,代码来源:TestDisabler.java


示例9: evaluateExecutionCondition

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
@Override
public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext context) {
  return context.getElement()
                .flatMap(annotatedElement -> findAnnotation(annotatedElement, RunOnDay.class))
                .map(RunOnDay::value)
                .map(RunOnDayCondition::evaluateIfRunningOnDay)
                .orElse(DEFAULT);
}
 
开发者ID:mkobit,项目名称:junit5-conditional-execution-extensions,代码行数:9,代码来源:RunOnDayCondition.java


示例10: evaluateIfRunningOnDay

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
private static ConditionEvaluationResult evaluateIfRunningOnDay(final DayOfWeek[] days) {
  // TODO: figure out how to inject a configurable clock instance
  final DayOfWeek currentDay = LocalDate.now().getDayOfWeek();
  final boolean runningInday = Stream.of(days).anyMatch(currentDay::equals);

  if (runningInday) {
    return enabled("Current day is " + currentDay + ", in the specified days of " + Arrays.toString(days));
  } else {
    return disabled("Current day is " + currentDay + ", not in the specified days of " + Arrays.toString(days));
  }
}
 
开发者ID:mkobit,项目名称:junit5-conditional-execution-extensions,代码行数:12,代码来源:RunOnDayCondition.java


示例11: evaluateExecutionCondition

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
@Override
public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext context) {
  return context.getElement()
         .flatMap(annotatedElement -> AnnotationSupport.findAnnotation(annotatedElement, DisabledOnJava8.class))
         .map(annotation -> evaluatedIfJava8())
         .orElse(DEFAULT);
}
 
开发者ID:mkobit,项目名称:junit5-conditional-execution-extensions,代码行数:8,代码来源:DisabledOnJava8Condition.java


示例12: evaluatedIfJava8

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
private static ConditionEvaluationResult evaluatedIfJava8() {
  final String specificationVersion = System.getProperty("java.specification.version");
  if ("1.8".equals(specificationVersion)) {
    return DISABLED;
  } else {
    return ConditionEvaluationResult.enabled("Enabled on java.specification.version=" + specificationVersion);
  }
}
 
开发者ID:mkobit,项目名称:junit5-conditional-execution-extensions,代码行数:9,代码来源:DisabledOnJava8Condition.java


示例13: evaluateExecutionCondition

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
@Override
public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext context) {
  return context.getElement()
                .flatMap(annotatedElement -> AnnotationSupport.findAnnotation(annotatedElement, DisabledOnJava9.class))
                .map(annotation -> evaluatedIfJava8())
                .orElse(DEFAULT);
}
 
开发者ID:mkobit,项目名称:junit5-conditional-execution-extensions,代码行数:8,代码来源:DisabledOnJava9Condition.java


示例14: evaluatedIfJava8

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
private static ConditionEvaluationResult evaluatedIfJava8() {
  final String specificationVersion = System.getProperty("java.specification.version");
  if ("9".equals(specificationVersion)) {
    return DISABLED;
  } else {
    return ConditionEvaluationResult.enabled("Enabled on java.specification.version=" + specificationVersion);
  }
}
 
开发者ID:mkobit,项目名称:junit5-conditional-execution-extensions,代码行数:9,代码来源:DisabledOnJava9Condition.java


示例15: evaluateExecutionCondition

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
@Override
public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext context) {
  return context.getElement()
                .flatMap(annotatedElement -> findAnnotation(annotatedElement, DisabledWhen.class))
                .map(DisabledWhen::value)
                .map(supplierClass -> ReflectionSupport.newInstance(supplierClass))
                .map(Supplier::get)
                .map(result -> Objects.requireNonNull(result, "Supplier result must not be null"))
                .map(shouldDisable -> shouldDisable
                    ? disabled(DisabledWhen.class + " evaluated to true")
                    : enabled(DisabledWhen.class + " evaluated to false"))
                .orElse(DEFAULT);
}
 
开发者ID:mkobit,项目名称:junit5-conditional-execution-extensions,代码行数:14,代码来源:DisabledWhenExtension.java


示例16: evaluateExecutionCondition

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
@Override
public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext context) {
  return context.getElement()
                .flatMap(annotatedElement -> findAnnotation(annotatedElement, EnabledWhen.class))
                .map(EnabledWhen::value)
                .map(supplierClass -> ReflectionSupport.newInstance(supplierClass))
                .map(Supplier::get)
                .map(result -> Objects.requireNonNull(result, "Result must not be null"))
                .map(shouldEnable -> shouldEnable
                    ? enabled(EnabledWhen.class + " evaluated to false")
                    : disabled(EnabledWhen.class + " evaluated to true"))
                .orElse(DEFAULT);
}
 
开发者ID:mkobit,项目名称:junit5-conditional-execution-extensions,代码行数:14,代码来源:EnabledWhenExtension.java


示例17: evaluateIfAnnotated

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
private ConditionEvaluationResult evaluateIfAnnotated(Optional<AnnotatedElement> element) {
	Optional<DisabledOnOs> disabled = element.flatMap(el -> findAnnotation(el, DisabledOnOs.class));
	if (disabled.isPresent())
		return disabledIfOn(disabled.get().value());

	Optional<TestExceptOnOs> testExcept = element.flatMap(el -> findAnnotation(el, TestExceptOnOs.class));
	if (testExcept.isPresent())
		return disabledIfOn(testExcept.get().value());

	return ConditionEvaluationResult.enabled("");
}
 
开发者ID:CodeFX-org,项目名称:demo-junit-5,代码行数:12,代码来源:OsCondition.java


示例18: disabledIfOn

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
private ConditionEvaluationResult disabledIfOn(OS[] disabledOnOs) {
	OS os = OS.determine();
	if (Arrays.asList(disabledOnOs).contains(os))
		return ConditionEvaluationResult.disabled("Test is disabled on " + os + ".");
	else
		return ConditionEvaluationResult.enabled("Test is not disabled in " + os + ".");
}
 
开发者ID:CodeFX-org,项目名称:demo-junit-5,代码行数:8,代码来源:OsCondition.java


示例19: evaluate

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
@Override
public ConditionEvaluationResult evaluate(TestExtensionContext context) {
	Class<? extends Exception>[] exceptionTypes = context.getTestClass()
			.flatMap(testClass -> findAnnotation(testClass, DisabledIfTestFailedWith.class))
			.orElseThrow(() -> new IllegalStateException("The extension should not be executed "
					+ "unless the test class is annotated with @DisabledIfTestFailedWith."))
			.value();

	return disableIfExceptionWasThrown(context, exceptionTypes);
}
 
开发者ID:CodeFX-org,项目名称:demo-junit-5,代码行数:11,代码来源:DisabledIfTestFailedCondition.java


示例20: disableIfExceptionWasThrown

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入依赖的package包/类
private ConditionEvaluationResult disableIfExceptionWasThrown(
		ExtensionContext context,
		Class<? extends Exception>[] exceptions) {
	return Arrays.stream(exceptions)
			.filter(ex -> wasThrown(context, ex))
			.findAny()
			.map(thrown -> ConditionEvaluationResult.disabled(thrown.getSimpleName() + " was thrown."))
			.orElseGet(() -> ConditionEvaluationResult.enabled(""));
}
 
开发者ID:CodeFX-org,项目名称:demo-junit-5,代码行数:10,代码来源:DisabledIfTestFailedCondition.java



注:本文中的org.junit.jupiter.api.extension.ConditionEvaluationResult类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CompoundComparator类代码示例发布时间:2022-05-22
下一篇:
Java RayCastOutput类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap