Trim expressions supplied to @DisabledIf

Prior to this commit, the DisabledIfCondition did not trim whitespace
from expressions configured via @DisabledIf. Consequently, results such
as "  true  " would evaluate to "false".

This commit fixes this problem by trimming all expressions configured
via @DisabledIf.

Issue: SPR-14614
This commit is contained in:
Sam Brannen
2016-08-29 15:47:38 +02:00
parent d6d05e8ca0
commit b6220cc19d
2 changed files with 23 additions and 3 deletions

View File

@@ -82,9 +82,11 @@ public class DisabledIfCondition implements ContainerExecutionCondition, TestExe
Optional<DisabledIf> disabledIf = findMergedAnnotation(element, DisabledIf.class);
Assert.state(disabledIf.isPresent(), () -> "@DisabledIf must be present on " + element);
String expression = disabledIf.map(DisabledIf::expression).filter(StringUtils::hasText).orElseThrow(
() -> new IllegalStateException(
String.format("The expression in @DisabledIf on [%s] must not be blank", element)));
// @formatter:off
String expression = disabledIf.map(DisabledIf::expression).map(String::trim).filter(StringUtils::hasLength)
.orElseThrow(() -> new IllegalStateException(String.format(
"The expression in @DisabledIf on [%s] must not be blank", element)));
// @formatter:on
if (isDisabled(expression, extensionContext)) {
String reason = disabledIf.map(DisabledIf::reason).filter(StringUtils::hasText).orElseGet(