Skip to content

Commit

Permalink
Fix logic errors in sys prop & env var @enabled conditions
Browse files Browse the repository at this point in the history
Issue: #219
  • Loading branch information
sbrannen committed Feb 3, 2018
1 parent 65c8640 commit 4c90c62
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
* <p>When declared at the class level, the result will apply to all test methods
* within that class as well.
*
* <p>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.
* <p>If the specified environment variable is undefined, the annotated class or
* method will be disabled.
*
* @since 5.1
* @see DisabledIfEnvironmentVariable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
* <p>When declared at the class level, the result will apply to all test methods
* within that class as well.
*
* <p>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.
* <p>If the specified system property is undefined, the annotated class or
* method will be disabled.
*
* @since 5.1
* @see DisabledIfSystemProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,7 +51,7 @@ void environmentVariableDoesNotMatch() {
@Test
@EnabledIfEnvironmentVariable(named = BOGUS, matches = "doesn't matter")
void environmentVariableDoesNotExist() {
assertNull(System.getenv(BOGUS));
fail("should be disabled");
}

}

0 comments on commit 4c90c62

Please sign in to comment.