当前位置: 首页>>代码示例>>Java>>正文


Java ConditionEvaluationResult.enabled方法代码示例

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


在下文中一共展示了ConditionEvaluationResult.enabled方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: evaluateIfAnnotated

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入方法依赖的package包/类
private ConditionEvaluationResult evaluateIfAnnotated(Optional<AnnotatedElement> element) {
	// @formatter:off
	Optional<ConditionEvaluationResult> disabledResult = element
			.flatMap(el -> findAnnotation(el, DisabledOnOs.class))
			.map(DisabledOnOs::value)
			.map(this::disabledIfOn);
	// @formatter:on
	if (disabledResult.isPresent()) {
		return disabledResult.get();
	}

	// @formatter:off
	Optional<ConditionEvaluationResult> enabledResult = element
			.flatMap(el -> findAnnotation(el, EnabledOnOs.class))
			.map(EnabledOnOs::value)
			// invert the selection to disable the test
			// if it NOT one of those given to the annotation
			.map(OS::except)
			.map(this::disabledIfOn);
	// @formatter:on
	if (enabledResult.isPresent()) {
		return enabledResult.get();
	}

	// if both annotations are missing, the container/test is enabled
	return ConditionEvaluationResult.enabled(NO_CONDITION_PRESENT);
}
 
开发者ID:junit-pioneer,项目名称:junit-pioneer,代码行数:28,代码来源:OsCondition.java

示例9: disabledIfOn

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入方法依赖的package包/类
private ConditionEvaluationResult disabledIfOn(OS[] disabledOnOs) {
	OS os = osDetector.get();
	if (Arrays.asList(disabledOnOs).contains(os)) {
		return ConditionEvaluationResult.disabled(format(TEST_DISABLED, os));
	}
	else {
		return ConditionEvaluationResult.enabled(format(TEST_ENABLED, os));
	}
}
 
开发者ID:junit-pioneer,项目名称:junit-pioneer,代码行数:10,代码来源:OsCondition.java

示例10: evaluateExecutionCondition

import org.junit.jupiter.api.extension.ConditionEvaluationResult; //导入方法依赖的package包/类
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
    boolean monday = Calendar.getInstance().get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY;

    return monday ?
            ConditionEvaluationResult.disabled("I spare you on Mondays.") :
            ConditionEvaluationResult.enabled("Don't spare you on other days though >:(");
}
 
开发者ID:msg-DAVID-GmbH,项目名称:JUnit-5-Quick-Start-Guide-with-AssertJ-Spring-TestFX-Mockito,代码行数:9,代码来源:DisabledOnMonday.java


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