From 4c90c62b09f75fa65927d5adec50e3881ddefb27 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 3 Feb 2018 21:06:43 +0100 Subject: [PATCH] Fix logic errors in sys prop & env var @Enabled conditions Issue: #219 --- .../jupiter/api/condition/EnabledIfEnvironmentVariable.java | 5 ++--- .../api/condition/EnabledIfEnvironmentVariableCondition.java | 4 +--- .../junit/jupiter/api/condition/EnabledIfSystemProperty.java | 5 ++--- .../api/condition/EnabledIfSystemPropertyCondition.java | 4 +--- .../EnabledIfEnvironmentVariableIntegrationTests.java | 3 +-- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfEnvironmentVariable.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfEnvironmentVariable.java index cd422456409..d1ef87ba2cc 100644 --- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfEnvironmentVariable.java +++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfEnvironmentVariable.java @@ -30,9 +30,8 @@ *

When declared at the class level, the result will apply to all test methods * within that class as well. * - *

If the specified environment variable is undefined, the presence of this - * annotation will have no effect on whether or not the class or method - * is enabled. + *

If the specified environment variable is undefined, the annotated class or + * method will be disabled. * * @since 5.1 * @see DisabledIfEnvironmentVariable diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfEnvironmentVariableCondition.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfEnvironmentVariableCondition.java index ad0f59f82d4..2619bf21813 100644 --- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfEnvironmentVariableCondition.java +++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfEnvironmentVariableCondition.java @@ -51,14 +51,12 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con // Nothing to match against? if (actual == null) { - return enabled(format("Environment variable [%s] does not exist", name)); + return disabled(format("Environment variable [%s] does not exist", name)); } - if (actual.matches(regex)) { return enabled(format("Environment variable [%s] with value [%s] matches regular expression [%s]", name, actual, regex)); } - // else return disabled(format("Environment variable [%s] with value [%s] does not match regular expression [%s]", name, actual, regex)); } diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfSystemProperty.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfSystemProperty.java index 7163bf4acd9..3b1d7c6fa27 100644 --- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfSystemProperty.java +++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfSystemProperty.java @@ -30,9 +30,8 @@ *

When declared at the class level, the result will apply to all test methods * within that class as well. * - *

If the specified system property is undefined, the presence of this - * annotation will have no effect on whether or not the class or method - * is enabled. + *

If the specified system property is undefined, the annotated class or + * method will be disabled. * * @since 5.1 * @see DisabledIfSystemProperty diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfSystemPropertyCondition.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfSystemPropertyCondition.java index 644fd669954..c3526646d5f 100644 --- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfSystemPropertyCondition.java +++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfSystemPropertyCondition.java @@ -51,14 +51,12 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con // Nothing to match against? if (actual == null) { - return enabled(format("System property [%s] does not exist", name)); + return disabled(format("System property [%s] does not exist", name)); } - if (actual.matches(regex)) { return enabled( format("System property [%s] with value [%s] matches regular expression [%s]", name, actual, regex)); } - // else return disabled( format("System property [%s] with value [%s] does not match regular expression [%s]", name, actual, regex)); } diff --git a/junit-jupiter-engine/src/test/java/org/junit/jupiter/api/condition/EnabledIfEnvironmentVariableIntegrationTests.java b/junit-jupiter-engine/src/test/java/org/junit/jupiter/api/condition/EnabledIfEnvironmentVariableIntegrationTests.java index d79abb1d388..6aa2b728d2d 100644 --- a/junit-jupiter-engine/src/test/java/org/junit/jupiter/api/condition/EnabledIfEnvironmentVariableIntegrationTests.java +++ b/junit-jupiter-engine/src/test/java/org/junit/jupiter/api/condition/EnabledIfEnvironmentVariableIntegrationTests.java @@ -11,7 +11,6 @@ package org.junit.jupiter.api.condition; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.fail; import org.junit.jupiter.api.Disabled; @@ -52,7 +51,7 @@ void environmentVariableDoesNotMatch() { @Test @EnabledIfEnvironmentVariable(named = BOGUS, matches = "doesn't matter") void environmentVariableDoesNotExist() { - assertNull(System.getenv(BOGUS)); + fail("should be disabled"); } }