From bf52691087f26ccbe19d88b0776f113af15532a9 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Thu, 11 Jan 2024 12:34:56 +0100 Subject: [PATCH] Reuse JUnit 5.7's @DisabledIfEnvironmentVariable --- .../org/jabref/support/CIServerCondition.java | 44 ------------------- .../jabref/support/DisabledOnCIServer.java | 4 +- 2 files changed, 2 insertions(+), 46 deletions(-) delete mode 100644 src/test/java/org/jabref/support/CIServerCondition.java diff --git a/src/test/java/org/jabref/support/CIServerCondition.java b/src/test/java/org/jabref/support/CIServerCondition.java deleted file mode 100644 index f4829374c25..00000000000 --- a/src/test/java/org/jabref/support/CIServerCondition.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.jabref.support; - -import java.lang.reflect.AnnotatedElement; -import java.util.Optional; - -import org.jabref.model.strings.StringUtil; - -import org.junit.jupiter.api.extension.ConditionEvaluationResult; -import org.junit.jupiter.api.extension.ExecutionCondition; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.platform.commons.support.AnnotationSupport; - -public class CIServerCondition implements ExecutionCondition { - - private static final ConditionEvaluationResult ENABLED = ConditionEvaluationResult.enabled("not on CI server"); - - private static boolean isCIServer() { - // See http://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables - // See https://circleci.com/docs/environment-variables - return Boolean.valueOf(System.getenv("CI")); - } - - /** - * Containers and tests are disabled if they are annotated with {@link DisabledOnCIServer} and the tests are run on - * the CI server. - */ - @Override - public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { - if (!isCIServer()) { - return ENABLED; - } - - Optional element = context.getElement(); - Optional disabled = AnnotationSupport.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; - } -} diff --git a/src/test/java/org/jabref/support/DisabledOnCIServer.java b/src/test/java/org/jabref/support/DisabledOnCIServer.java index f70e346d998..63cbef5c130 100644 --- a/src/test/java/org/jabref/support/DisabledOnCIServer.java +++ b/src/test/java/org/jabref/support/DisabledOnCIServer.java @@ -5,11 +5,11 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; @Target(value = {ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) -@ExtendWith(CIServerCondition.class) +@DisabledIfEnvironmentVariable(named = "CI", matches = "true") public @interface DisabledOnCIServer { String value(); }