本文整理汇总了Java中org.junit.jupiter.api.extension.ConditionEvaluationResult类的典型用法代码示例。如果您正苦于以下问题:Java ConditionEvaluationResult类的具体用法?Java ConditionEvaluationResult怎么用?Java ConditionEvaluationResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConditionEvaluationResult类属于org.junit.jupiter.api.extension包,在下文中一共展示了ConditionEvaluationResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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));
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
示例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));
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}