Skip to content

Commit 4c90c62

Browse files
committed
Fix logic errors in sys prop & env var @enabled conditions
Issue: #219
1 parent 65c8640 commit 4c90c62

File tree

5 files changed

+7
-14
lines changed

5 files changed

+7
-14
lines changed

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfEnvironmentVariable.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030
* <p>When declared at the class level, the result will apply to all test methods
3131
* within that class as well.
3232
*
33-
* <p>If the specified environment variable is undefined, the presence of this
34-
* annotation will have no effect on whether or not the class or method
35-
* is enabled.
33+
* <p>If the specified environment variable is undefined, the annotated class or
34+
* method will be disabled.
3635
*
3736
* @since 5.1
3837
* @see DisabledIfEnvironmentVariable

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfEnvironmentVariableCondition.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
5151

5252
// Nothing to match against?
5353
if (actual == null) {
54-
return enabled(format("Environment variable [%s] does not exist", name));
54+
return disabled(format("Environment variable [%s] does not exist", name));
5555
}
56-
5756
if (actual.matches(regex)) {
5857
return enabled(format("Environment variable [%s] with value [%s] matches regular expression [%s]", name,
5958
actual, regex));
6059
}
61-
// else
6260
return disabled(format("Environment variable [%s] with value [%s] does not match regular expression [%s]", name,
6361
actual, regex));
6462
}

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfSystemProperty.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030
* <p>When declared at the class level, the result will apply to all test methods
3131
* within that class as well.
3232
*
33-
* <p>If the specified system property is undefined, the presence of this
34-
* annotation will have no effect on whether or not the class or method
35-
* is enabled.
33+
* <p>If the specified system property is undefined, the annotated class or
34+
* method will be disabled.
3635
*
3736
* @since 5.1
3837
* @see DisabledIfSystemProperty

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/EnabledIfSystemPropertyCondition.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
5151

5252
// Nothing to match against?
5353
if (actual == null) {
54-
return enabled(format("System property [%s] does not exist", name));
54+
return disabled(format("System property [%s] does not exist", name));
5555
}
56-
5756
if (actual.matches(regex)) {
5857
return enabled(
5958
format("System property [%s] with value [%s] matches regular expression [%s]", name, actual, regex));
6059
}
61-
// else
6260
return disabled(
6361
format("System property [%s] with value [%s] does not match regular expression [%s]", name, actual, regex));
6462
}

junit-jupiter-engine/src/test/java/org/junit/jupiter/api/condition/EnabledIfEnvironmentVariableIntegrationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
package org.junit.jupiter.api.condition;
1212

1313
import static org.junit.jupiter.api.Assertions.assertEquals;
14-
import static org.junit.jupiter.api.Assertions.assertNull;
1514
import static org.junit.jupiter.api.Assertions.fail;
1615

1716
import org.junit.jupiter.api.Disabled;
@@ -52,7 +51,7 @@ void environmentVariableDoesNotMatch() {
5251
@Test
5352
@EnabledIfEnvironmentVariable(named = BOGUS, matches = "doesn't matter")
5453
void environmentVariableDoesNotExist() {
55-
assertNull(System.getenv(BOGUS));
54+
fail("should be disabled");
5655
}
5756

5857
}

0 commit comments

Comments
 (0)