提交 b6220cc1 编写于 作者: S Sam Brannen

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
上级 d6d05e8c
......@@ -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(
......
......@@ -50,6 +50,12 @@ class DisabledIfTestCase {
fail("This test must be disabled");
}
@Test
@DisabledIf(" true ")
void disabledByStringTrueWithSurroundingWhitespace() {
fail("This test must be disabled");
}
@Test
@DisabledIf("TrUe")
void disabledByStringTrueIgnoreCase() {
......@@ -62,12 +68,24 @@ class DisabledIfTestCase {
fail("This test must be disabled");
}
@Test
@DisabledIf("\t${foo} ")
void disabledByPropertyPlaceholderWithSurroundingWhitespace() {
fail("This test must be disabled");
}
@Test
@DisabledIf("#{T(java.lang.Boolean).TRUE}")
void disabledBySpelBoolean() {
fail("This test must be disabled");
}
@Test
@DisabledIf(" #{T(java.lang.Boolean).TRUE} ")
void disabledBySpelBooleanWithSurroundingWhitespace() {
fail("This test must be disabled");
}
@Test
@DisabledIf("#{'tr' + 'ue'}")
void disabledBySpelStringConcatenation() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册