Java 类org.junit.jupiter.api.extension.ConditionEvaluationResult 实例源码

项目: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;
}
项目:junit5-extensions    文件:TestDisabler.java   
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));
}
项目: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;
}
项目:junit5-conditional-execution-extensions    文件:EnabledOnOperatingSystemCondition.java   
@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);
}
项目:JUnit-5-Quick-Start-Guide-with-AssertJ-Spring-TestFX-Mockito    文件:DisabledOnWeekday.java   
@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 >:(");
}
项目: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;
}
项目:testing-video    文件:GenerateVideoExtension.java   
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;
}
项目:bach    文件:DisabledCondition.java   
@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);
}
项目:junit5-extensions    文件:TestDisabler.java   
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();
}
项目:junit5-conditional-execution-extensions    文件:RunOnDayCondition.java   
@Override
public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext context) {
  return context.getElement()
                .flatMap(annotatedElement -> findAnnotation(annotatedElement, RunOnDay.class))
                .map(RunOnDay::value)
                .map(RunOnDayCondition::evaluateIfRunningOnDay)
                .orElse(DEFAULT);
}
项目:junit5-conditional-execution-extensions    文件:RunOnDayCondition.java   
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));
  }
}
项目:junit5-conditional-execution-extensions    文件:DisabledOnJava8Condition.java   
@Override
public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext context) {
  return context.getElement()
         .flatMap(annotatedElement -> AnnotationSupport.findAnnotation(annotatedElement, DisabledOnJava8.class))
         .map(annotation -> evaluatedIfJava8())
         .orElse(DEFAULT);
}
项目:junit5-conditional-execution-extensions    文件:DisabledOnJava8Condition.java   
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);
  }
}
项目:junit5-conditional-execution-extensions    文件:DisabledOnJava9Condition.java   
@Override
public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext context) {
  return context.getElement()
                .flatMap(annotatedElement -> AnnotationSupport.findAnnotation(annotatedElement, DisabledOnJava9.class))
                .map(annotation -> evaluatedIfJava8())
                .orElse(DEFAULT);
}
项目:junit5-conditional-execution-extensions    文件:DisabledOnJava9Condition.java   
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);
  }
}
项目:junit5-conditional-execution-extensions    文件:DisabledWhenExtension.java   
@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);
}
项目:junit5-conditional-execution-extensions    文件:EnabledWhenExtension.java   
@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);
}
项目:demo-junit-5    文件:OsCondition.java   
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("");
}
项目:demo-junit-5    文件:OsCondition.java   
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 + ".");
}
项目:demo-junit-5    文件:DisabledIfTestFailedCondition.java   
@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);
}
项目:demo-junit-5    文件:DisabledIfTestFailedCondition.java   
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(""));
}
项目:junit-pioneer    文件:OsCondition.java   
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);
}
项目:junit-pioneer    文件:OsCondition.java   
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));
    }
}
项目:junit-pioneer    文件:OsConditionTests.java   
@Test
void evaluateContainer_notAnnotated_enabled() throws Exception {
    ExtensionContext context = createContextReturning(UnconditionalTestCase.class);
    OsCondition condition = new OsCondition();

    ConditionEvaluationResult result = condition.evaluateExecutionCondition(context);

    assertThat(result.isDisabled()).isFalse();
    assertThat(result.getReason()).contains(OsCondition.NO_CONDITION_PRESENT);
}
项目:junit-pioneer    文件:OsConditionTests.java   
@Test
void evaluateContainer_disabledOnOtherOs_enabled() throws Exception {
    ExtensionContext context = createContextReturning(DisabledOnLinuxTestCase.class);
    OsCondition conditionOnWindows = new OsCondition(() -> OS.WINDOWS);

    ConditionEvaluationResult result = conditionOnWindows.evaluateExecutionCondition(context);

    assertEnabledOn(result, OS.WINDOWS);
}
项目:junit-pioneer    文件:OsConditionTests.java   
@Test
void evaluateContainer_disabledOnRunningOs_disabled() throws Exception {
    ExtensionContext context = createContextReturning(DisabledOnLinuxTestCase.class);
    OsCondition conditionOnWindows = new OsCondition(() -> OS.LINUX);

    ConditionEvaluationResult result = conditionOnWindows.evaluateExecutionCondition(context);

    assertDisabledOn(result, OS.LINUX);
}
项目:junit-pioneer    文件:OsConditionTests.java   
@Test
void evaluateContainer_enabledOnOtherOs_disabled() throws Exception {
    ExtensionContext context = createContextReturning(EnabledOnLinuxTestCase.class);
    OsCondition conditionOnWindows = new OsCondition(() -> OS.WINDOWS);

    ConditionEvaluationResult result = conditionOnWindows.evaluateExecutionCondition(context);

    assertDisabledOn(result, OS.WINDOWS);
}
项目:junit-pioneer    文件:OsConditionTests.java   
@Test
void evaluateContainer_enabledOnRunningOs_enabled() throws Exception {
    ExtensionContext context = createContextReturning(EnabledOnLinuxTestCase.class);
    OsCondition conditionOnWindows = new OsCondition(() -> OS.LINUX);

    ConditionEvaluationResult result = conditionOnWindows.evaluateExecutionCondition(context);

    assertEnabledOn(result, OS.LINUX);
}
项目:junit-pioneer    文件:OsConditionTests.java   
@Test
void evaluateMethod_notAnnotated_enabled() throws Exception {
    ExtensionContext context = createContextReturning(UnconditionalTestCase.class, "unconditionalTest");
    OsCondition condition = new OsCondition();

    ConditionEvaluationResult result = condition.evaluateExecutionCondition(context);

    assertThat(result.isDisabled()).isFalse();
    assertThat(result.getReason()).contains(OsCondition.NO_CONDITION_PRESENT);
}
项目:junit-pioneer    文件:OsConditionTests.java   
@Test
void evaluateMethod_disabledOnOtherOs_enabled() throws Exception {
    ExtensionContext context = createContextReturning(EnabledAndDisabledTestMethods.class, "disabledOnLinuxTest");
    OsCondition condition = new OsCondition(() -> OS.WINDOWS);

    ConditionEvaluationResult result = condition.evaluateExecutionCondition(context);

    assertEnabledOn(result, OS.WINDOWS);
}
项目:junit-pioneer    文件:OsConditionTests.java   
@Test
void evaluateMethod_disabledOnRunningOs_disabled() throws Exception {
    ExtensionContext context = createContextReturning(EnabledAndDisabledTestMethods.class, "disabledOnLinuxTest");
    OsCondition condition = new OsCondition(() -> OS.LINUX);

    ConditionEvaluationResult result = condition.evaluateExecutionCondition(context);

    assertDisabledOn(result, OS.LINUX);
}
项目:junit-pioneer    文件:OsConditionTests.java   
@Test
void evaluateMethod_enabledOnOtherOs_disabled() throws Exception {
    ExtensionContext context = createContextReturning(EnabledAndDisabledTestMethods.class, "enabledOnLinuxTest");
    OsCondition condition = new OsCondition(() -> OS.WINDOWS);

    ConditionEvaluationResult result = condition.evaluateExecutionCondition(context);

    assertDisabledOn(result, OS.WINDOWS);
}
项目:junit-pioneer    文件:OsConditionTests.java   
@Test
void evaluateMethod_enabledOnRunningOs_enabled() throws Exception {
    ExtensionContext context = createContextReturning(EnabledAndDisabledTestMethods.class, "enabledOnLinuxTest");
    OsCondition condition = new OsCondition(() -> OS.LINUX);

    ConditionEvaluationResult result = condition.evaluateExecutionCondition(context);

    assertEnabledOn(result, OS.LINUX);
}
项目:JUnit-5-Quick-Start-Guide-with-AssertJ-Spring-TestFX-Mockito    文件:DisabledOnMonday.java   
@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 >:(");
}
项目:testing-video    文件:GenerateVideoExtension.java   
@Override
public ConditionEvaluationResult evaluateExecutionCondition(
        ExtensionContext context) {
    return findAnnotation(context.getElement(), GenerateVideo.class)
            .map(this::isTypeEnabled).orElse(ENABLED_NO_ANNOTATION);
}
项目:junit5-extensions    文件:TestDisabler.java   
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
  return evaluate(new LinkedList<>(), context);
}
项目:demo-junit-5    文件:DisabledCondition.java   
@Override
public ConditionEvaluationResult evaluate(ContainerExtensionContext context) {
    return evaluateIfAnnotated(context.getElement());
}
项目:demo-junit-5    文件:DisabledCondition.java   
@Override
public ConditionEvaluationResult evaluate(TestExtensionContext context) {
    return evaluateIfAnnotated(context.getElement());
}
项目:demo-junit-5    文件:DisabledCondition.java   
private ConditionEvaluationResult evaluateIfAnnotated(Optional<AnnotatedElement> element) {
    return element.filter(el -> isAnnotated(el, Disabled.class))
            .map(el -> ConditionEvaluationResult.disabled(el + " is @Disabled"))
            .orElse(ENABLED);
}
项目:demo-junit-5    文件:OsCondition.java   
@Override
public ConditionEvaluationResult evaluate(ContainerExtensionContext context) {
    return evaluateIfAnnotated(context.getElement());
}