org.junit.jupiter.api.extension.ConditionEvaluationResult Java Examples

The following examples show how to use org.junit.jupiter.api.extension.ConditionEvaluationResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: camel-quarkus   Author: apache   File: EnabledIfPropertyCondition.java    License: Apache License 2.0 6 votes vote down vote up
private ConditionEvaluationResult map(EnabledIfProperty annotation) {
    final String name = annotation.named().trim();
    final String regex = annotation.matches();

    Preconditions.notBlank(name, () -> "The 'named' attribute must not be blank in " + annotation);
    Preconditions.notBlank(regex, () -> "The 'matches' attribute must not be blank in " + annotation);

    return ConfigProviderResolver.instance().getConfig().getOptionalValue(name, String.class)
            .map(actual -> {
                return actual.matches(regex)
                        ? enabled(
                                format("Config property [%s] with value [%s] matches regular expression [%s]",
                                        name, actual, regex))
                        : disabled(
                                format("Config property [%s] with value [%s] does not match regular expression [%s]",
                                        name, actual, regex));
            })
            .orElseGet(() -> {
                return disabled(
                        format("Config property [%s] does not exist", name));
            });
}
 
Example #2
Source Project: quarkus   Author: quarkusio   File: DisabledOnNativeImageCondition.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Containers/tests are disabled if {@code @DisabledOnNativeImage} is present on the test
 * class or method and we're running on a native image.
 */
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
    Optional<AnnotatedElement> element = context.getElement();
    Optional<DisabledOnNativeImage> disabled = findAnnotation(element, DisabledOnNativeImage.class);
    if (disabled.isPresent()) {
        // Cannot use ExtensionState here because this condition needs to be evaluated before QuarkusTestExtension
        boolean nativeImage = findAnnotation(context.getTestClass(), NativeImageTest.class).isPresent();
        if (nativeImage) {
            String reason = disabled.map(DisabledOnNativeImage::value)
                    .filter(StringUtils::isNotBlank)
                    .orElseGet(() -> element.get() + " is @DisabledOnNativeImage");
            return ConditionEvaluationResult.disabled(reason);
        }
    }
    return ENABLED;
}
 
Example #3
Source Project: dekorate   Author: dekorateio   File: ServicePresentCondition.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
 Optional<OnServicePresentCondition> annotation = context.getElement().map(e -> e.getAnnotation(OnServicePresentCondition.class));
 if (!annotation.isPresent()) {
  return ConditionEvaluationResult.enabled("Condition not found!");
 }
 OnServicePresentCondition condition = annotation.get();
  try {
    KubernetesClient client = getKubernetesClient(context);
    String namespace = Strings.isNotNullOrEmpty(condition.namespace()) ? condition.namespace() :  client.getNamespace();
    Service service = getKubernetesClient(context).services().inNamespace(namespace).withName(condition.value()).get();
    if (service != null) {
      return ConditionEvaluationResult.enabled("Found service:" + condition.value() + " in namespace:" + namespace + " .");
    } else {
      return ConditionEvaluationResult.disabled("Could not find service:" + condition.value() + " in namespace:" + namespace + " .");
    }
  } catch (Throwable t) {
    return ConditionEvaluationResult.disabled("Could not lookup for service.");
  }
}
 
Example #4
Source Project: mastering-junit5   Author: bonigarcia   File: OsCondition.java    License: Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #5
Source Project: grpc-spring-boot-starter   Author: yidongnan   File: RequireIPv6Condition.java    License: MIT License 6 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
    if (ipv6Result == null) {
        boolean result = false;
        try {
            result = hasIPv6Loopback();
        } catch (SocketException e) {
            log.warn("Could not determine presence of IPv6 loopback address", e);
        }

        if (result) {
            ipv6Result = ConditionEvaluationResult.enabled("Found IPv6 loopback");
        } else {
            ipv6Result = ConditionEvaluationResult.disabled("Could not find IPv6 loopback");
        }
    }
    return ipv6Result;
}
 
Example #6
Source Project: junit5-extensions   Author: JeffreyFalgout   File: TestDisabler.java    License: MIT License 6 votes vote down vote up
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));
}
 
Example #7
Source Project: Mastering-Software-Testing-with-JUnit-5   Author: PacktPublishing   File: OsCondition.java    License: MIT License 6 votes vote down vote up
@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;
}
 
Example #8
Source Project: status-keycard   Author: status-im   File: CapabilityCondition.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Containers/tests are disabled if {@code @Disabled} is present on the test
 * class or method.
 */
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
  Optional<AnnotatedElement> element = context.getElement();
  Optional<Capabilities> capsAnnotation = findAnnotation(element, Capabilities.class);

  if (capsAnnotation.isPresent()) {
    for (String c : capsAnnotation.get().value()) {
      if (!availableCapabilities.contains(c)) {
        return disabled("The " + c + " capability is not available on the tested target");
      }
    }

    return ENABLED;
  }

  return ENABLED_BY_DEFAULT;
}
 
Example #9
Source Project: grpc-spring-boot-starter   Author: yidongnan   File: RequireIPv6Condition.java    License: MIT License 6 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
    if (ipv6Result == null) {
        boolean result = false;
        try {
            result = hasIPv6Loopback();
        } catch (SocketException e) {
            log.warn("Could not determine presence of IPv6 loopback address", e);
        }

        if (result) {
            ipv6Result = ConditionEvaluationResult.enabled("Found IPv6 loopback");
        } else {
            ipv6Result = ConditionEvaluationResult.disabled("Could not find IPv6 loopback");
        }
    }
    return ipv6Result;
}
 
Example #10
Source Project: JUnit-5-Quick-Start-Guide-and-Framework-Support   Author: msg-DAVID-GmbH   File: DisabledOnWeekday.java    License: MIT License 6 votes vote down vote up
@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 >:(");
}
 
Example #11
Source Project: enmasse   Author: EnMasseProject   File: AssumeOpenshiftCondition.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
    Optional<OpenShift> annotation = findAnnotation(context.getElement(), OpenShift.class);
    if (annotation.isPresent()) {
        var version = annotation.get().version();
        var type = annotation.get().type();
        var multinode = type.equals(ClusterType.CRC) ? MultinodeCluster.NO : annotation.get().multinode();
        if ((Kubernetes.getInstance().getCluster().toString().equals(ClusterType.OPENSHIFT.toString().toLowerCase()) ||
                Kubernetes.getInstance().getCluster().toString().equals(ClusterType.CRC.toString().toLowerCase())) &&
                (version == OpenShiftVersion.WHATEVER || version == Kubernetes.getInstance().getOcpVersion()) &&
                (multinode == MultinodeCluster.WHATEVER || multinode == Kubernetes.getInstance().isClusterMultinode())) {
            return ConditionEvaluationResult.enabled("Test is supported on current cluster");
        } else {
            return ConditionEvaluationResult.disabled("Test is not supported on current cluster");
        }
    }
    return ConditionEvaluationResult.enabled("No rule set, test is enabled");
}
 
Example #12
Source Project: enmasse   Author: EnMasseProject   File: SupportedInstallTypeCondition.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
    Optional<SupportedInstallType> annotation = findAnnotation(context.getRequiredTestClass(), SupportedInstallType.class);
    if (annotation.isPresent()) {
        SupportedInstallType supports = annotation.get();
        io.enmasse.systemtest.platform.Kubernetes kube = io.enmasse.systemtest.platform.Kubernetes.getInstance();
        Environment env = Environment.getInstance();
        String reason = String.format("Env is supported types %s type used %s olmAvailability %s",
                supports.value().toString(), env.installType(), kube.isOLMAvailable());
        if (isTestEnabled(supports, kube.isOLMAvailable(), env.installType())) {
           return ConditionEvaluationResult.enabled(reason);
        } else {
            return ConditionEvaluationResult.disabled(reason);
        }
    }
    return ConditionEvaluationResult.enabled("No rule set, test is enabled");
}
 
Example #13
Source Project: sarl   Author: sarl   File: JavaVersionCheckExtension.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
	// Check if the minimal version of Java is used for running the tests.
	final JavaVersion cVersion = JavaVersion.fromQualifier(System.getProperty("java.specification.version"));
	if (cVersion == null) {
		return ConditionEvaluationResult.disabled("You must use JDK " + SARLVersion.MINIMAL_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT + " or higher for running the tests.");
	}
	final JavaVersion mVersion = JavaVersion.fromQualifier(SARLVersion.MINIMAL_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT);
	if (mVersion == null || !cVersion.isAtLeast(mVersion)) {
		return ConditionEvaluationResult.disabled("You must use JDK " + SARLVersion.MINIMAL_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT + " or higher for running the tests.");
	}
	final JavaVersion xVersion = JavaVersion.fromQualifier(SARLVersion.INCOMPATIBLE_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT);
	// If null the max version that is specified into the SARL configuration is not yey supported by Xtext enumeration
	if (xVersion != null && cVersion.isAtLeast(xVersion)) {
		return ConditionEvaluationResult.disabled("You must use JDK strictly below " + SARLVersion.INCOMPATIBLE_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT + " for running the tests.");
	}
	return ConditionEvaluationResult.enabled("supported version of JDK");
}
 
Example #14
Source Project: gocd   Author: gocd   File: EnabledOnGitVersionCondition.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
    Optional<EnabledOnGitVersions> maybe = findAnnotation(context.getElement(), EnabledOnGitVersions.class);
    if (maybe.isPresent()) {
        final EnabledOnGitVersions annotation = maybe.get();
        final Version gitVersion = fetchGitVersion();

        if (noneSpecified(annotation)) {
            return ConditionEvaluationResult.enabled("Version requirements not provided. Running by default.");
        }

        if (atLeast(annotation.from(), gitVersion) && atMost(annotation.through(), gitVersion)) {
            return ConditionEvaluationResult.enabled(
                    format("Git version %s satisfies %s", gitVersion, criteria(annotation))
            );
        } else {
            return ConditionEvaluationResult.disabled(
                    format("Git version %s does not satisfy %s", gitVersion, criteria(annotation))
            );
        }
    }

    return ConditionEvaluationResult.enabled("Version requirements not provided. Running by default.");
}
 
Example #15
Source Project: tutorials   Author: eugenp   File: DisabledOnQAEnvironmentExtension.java    License: MIT License 6 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
    Properties properties = new Properties();
    try {
        properties.load(DisabledOnQAEnvironmentExtension.class.getClassLoader()
            .getResourceAsStream("application.properties"));
        if ("qa".equalsIgnoreCase(properties.getProperty("env"))) {
            String reason = String.format("The test '%s' is disabled on QA environment", context.getDisplayName());
            System.out.println(reason);
            return ConditionEvaluationResult.disabled(reason);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return ConditionEvaluationResult.enabled("Test enabled");
}
 
Example #16
Source Project: tutorials   Author: eugenp   File: DisabledOnEnvironmentCondition.java    License: MIT License 6 votes vote down vote up
@Override
public ConditionEvaluationResult evaluate(TestExtensionContext context) {
    Properties props = new Properties();
    String env = "";
    try {
        props.load(ConnectionUtil.class.getResourceAsStream("/application.properties"));
        env = props.getProperty("env");
    } catch (IOException e) {
        e.printStackTrace();
    }
    Optional<DisabledOnEnvironment> disabled = AnnotationSupport.findAnnotation(context.getElement().get(), DisabledOnEnvironment.class);
    if (disabled.isPresent()) {
        String[] envs = disabled.get().value();
        if (Arrays.asList(envs).contains(env)) {
            return ConditionEvaluationResult.disabled("Disabled on environment " + env);
        }
    }

    return ConditionEvaluationResult.enabled("Enabled on environment "+env);
}
 
Example #17
Source Project: camel-quarkus   Author: apache   File: EnabledIfCondition.java    License: Apache License 2.0 5 votes vote down vote up
private ConditionEvaluationResult map(EnabledIf annotation) {
    for (Class<? extends BooleanSupplier> type : annotation.value()) {
        try {
            if (!type.newInstance().getAsBoolean()) {
                return disabled(format("Condition %s is false", type.getName()));
            }
        } catch (InstantiationException | IllegalAccessException e) {
            return disabled(format("Unable to evaluate condition: %s", type.getName()));
        }
    }
    return enabled("All conditions match");
}
 
Example #18
Source Project: spring-analysis-note   Author: Vip-Augus   File: DisabledIfConditionTests.java    License: MIT License 5 votes vote down vote up
private void assertResult(ConditionEvaluationResult result, boolean disabled, Matcher<String> matcher) {
	assertNotNull(result);

	if (disabled) {
		assertTrue(result.isDisabled());
	}
	else {
		assertFalse(result.isDisabled());
	}

	Optional<String> reason = result.getReason();
	assertTrue(reason.isPresent());
	assertThat(reason.get(), matcher);
}
 
Example #19
Source Project: skara   Author: openjdk   File: DisableAllBotsTestsOnWindows.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
    if (!OS.WINDOWS.isCurrentOs()) {
        return enabled("Non-Windows OS");
    }
    var test = context.getRequiredTestClass();
    var bots = test.getPackageName().startsWith("org.openjdk.skara.bots.");
    return bots ? disabled("All bots tests are disabled on Windows") : enabled("Non-bots test");
}
 
Example #20
Source Project: java-technology-stack   Author: codeEngraver   File: DisabledIfConditionTests.java    License: MIT License 5 votes vote down vote up
private void assertResult(ConditionEvaluationResult result, boolean disabled, Matcher<String> matcher) {
	assertNotNull(result);

	if (disabled) {
		assertTrue(result.isDisabled());
	}
	else {
		assertFalse(result.isDisabled());
	}

	Optional<String> reason = result.getReason();
	assertTrue(reason.isPresent());
	assertThat(reason.get(), matcher);
}
 
Example #21
Source Project: herd-mdl   Author: FINRAOS   File: DisableWithoutAuthenticationCondition.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
    boolean isAuthEnabled = Boolean.valueOf(TestProperties.get(StackInputParameterKeyEnum.ENABLE_SSL_AUTH));
    if (isAuthEnabled) {
        return ConditionEvaluationResult.enabled("Test enabled");
    }
    else {
        return ConditionEvaluationResult.disabled("Bdsql Sync Tests disabled as authentication is disabled");
    }
}
 
Example #22
Source Project: Lavalink-Client   Author: FredBoat   File: RequireSystemPropertyExists.java    License: MIT License 5 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
    Optional<RequireSystemProperty> annotation = AnnotationSupport.findAnnotation(context.getElement(), RequireSystemProperty.class);
    if (annotation.isPresent()) {
        for (String propertyKey : annotation.get().value()) {
            String propertyValue = System.getProperty(propertyKey);
            if (propertyValue == null || propertyValue.isEmpty()) {
                return ConditionEvaluationResult.disabled(String.format("System property '%s' not set. Skipping test.", propertyKey));
            }
        }
        return ConditionEvaluationResult.enabled("All required system properties present. Continuing test.");
    }
    return ConditionEvaluationResult.enabled("No RequireSystemProperty annotation found. Continuing test.");
}
 
Example #23
Source Project: quarkus   Author: quarkusio   File: EnabledIfTest.java    License: Apache License 2.0 5 votes vote down vote up
private ConditionEvaluationResult map(EnabledIf annotation) {
    for (Class<? extends BooleanSupplier> type : annotation.value()) {
        try {
            if (!type.newInstance().getAsBoolean()) {
                return disabled(format("Condition %s is false", type.getName()));
            }
        } catch (InstantiationException | IllegalAccessException e) {
            return disabled(format("Unable to evaluate condition: %s", type.getName()));
        }
    }
    return enabled("All conditions match");
}
 
Example #24
Source Project: dekorate   Author: dekorateio   File: KubernetesExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
  try {
    VersionInfo version = getKubernetesClient(context).getVersion();
    String message = "Found version:" + version.getMajor() + "." + version.getMinor();
    LOGGER.info(message);
    return ConditionEvaluationResult.enabled(message);
  } catch (Throwable t) {
    String reason = "Could not communicate with KubernetesExtension API server.";
    LOGGER.error(reason);
    return ConditionEvaluationResult.disabled(reason);
  }
}
 
Example #25
Source Project: testing-video   Author: testing-av   File: GenerateVideoExtension.java    License: GNU General Public License v3.0 5 votes vote down vote up
ConditionEvaluationResult isTypeEnabled(GenerateVideo gv) {
    Type type = gv.value();
    if (type == ALL) return ENABLED_TYPE;
    if (!GeneratorFactory.LOSSLESS && type == MAIN) return ENABLED_TYPE;
    if (GeneratorFactory.LOSSLESS && type == LOSSLESS) return ENABLED_TYPE;
    return DISABLED_TYPE;
}
 
Example #26
Source Project: junit5-extensions   Author: JeffreyFalgout   File: InjectExtensionsTest.java    License: MIT License 5 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
  if (context.getRequiredTestMethod().getName().equals(testMethodToSkip)) {
    return ConditionEvaluationResult.disabled("Disabled by InjectableExtension.");
  }

  return ConditionEvaluationResult.enabled("");
}
 
Example #27
Source Project: junit5-extensions   Author: JeffreyFalgout   File: TestDisabler.java    License: MIT License 5 votes vote down vote up
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();
}
 
Example #28
Source Project: code-examples   Author: thombergs   File: AssumeConnectionCondition.java    License: MIT License 5 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
  Optional<AssumeConnection> annotation = findAnnotation(context.getElement(), AssumeConnection.class);
  if (annotation.isPresent()) {
    String uri = annotation.get().uri();
    ConnectionChecker checker = new ConnectionChecker(uri);
    if (!checker.connect()) {
      return ConditionEvaluationResult.disabled(String.format("Could not connect to '%s'. Skipping test!", uri));
    } else {
      return ConditionEvaluationResult.enabled(String.format("Successfully connected to '%s'. Continuing test!", uri));
    }
  }
  return ConditionEvaluationResult.enabled("No AssumeConnection annotation found. Continuing test.");
}
 
Example #29
Source Project: junit5-demo   Author: sbrannen   File: EnabledOnDayOfWeekCondition.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
	Optional<EnabledOnDayOfWeek> optional = findAnnotation(context.getElement(), EnabledOnDayOfWeek.class);

	if (!optional.isPresent()) {
		return ENABLED_BY_DEFAULT;
	}

	DayOfWeek today = LocalDate.now().getDayOfWeek();
	return Arrays.stream(optional.get().value()).anyMatch(today::equals) ? //
			enabled("Enabled on " + today) : //
			disabled("Disabled on " + today);
}
 
Example #30
Source Project: junit5-demo   Author: sbrannen   File: DisabledOnDayOfWeekCondition.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
	Optional<DisabledOnDayOfWeek> optional = findAnnotation(context.getElement(), DisabledOnDayOfWeek.class);

	if (!optional.isPresent()) {
		return ENABLED_BY_DEFAULT;
	}

	DayOfWeek today = LocalDate.now().getDayOfWeek();
	return Arrays.stream(optional.get().value()).anyMatch(today::equals) ? //
			disabled("Disabled on " + today) : //
			enabled("Enabled on " + today);
}