@Test void disabledByEmptyExpression() { // @formatter:off assertAll( () -> assertExpressionIsBlank("emptyExpression"), () -> assertExpressionIsBlank("blankExpression") ); // @formatter:on }
@Test void disabledWithCustomReason() { assertResult(condition.evaluateExecutionCondition(buildExtensionContext("customReason")), true, is(equalTo("Because... 42!"))); }
@Test void unsupportedStringEvaluationValue() { String methodName = "stringExpressionThatIsNeitherTrueNorFalse"; IllegalStateException exception = assertThrows(IllegalStateException.class, () -> condition.evaluateExecutionCondition(buildExtensionContext(methodName))); Method method = ReflectionUtils.findMethod(getClass(), methodName); assertThat(exception.getMessage(), is(equalTo("@DisabledIf(\"#{'enigma'}\") on " + method + " must evaluate to \"true\" or \"false\", not \"enigma\""))); }
private void assertExpressionIsBlank(String methodName) { IllegalStateException exception = assertThrows(IllegalStateException.class, () -> condition.evaluateExecutionCondition(buildExtensionContext(methodName))); assertThat(exception.getMessage(), containsString("must not be blank")); }
@Test void notDisabledWithDefaultReason() { assertResult(condition.evaluateExecutionCondition(buildExtensionContext("neverDisabledWithDefaultReason")), false, endsWith( "neverDisabledWithDefaultReason() is enabled because @DisabledIf(\"false\") did not evaluate to true")); }
@Test void invalidExpressionEvaluationType() { String methodName = "nonBooleanOrStringExpression"; IllegalStateException exception = assertThrows(IllegalStateException.class, () -> condition.evaluateExecutionCondition(buildExtensionContext(methodName))); Method method = ReflectionUtils.findMethod(getClass(), methodName); assertThat(exception.getMessage(), is(equalTo("@DisabledIf(\"#{6 * 7}\") on " + method + " must evaluate to a String or a Boolean, not java.lang.Integer"))); }
@Test void disabledWithDefaultReason() { assertResult(condition.evaluateExecutionCondition(buildExtensionContext("defaultReason")), true, endsWith("defaultReason() is disabled because @DisabledIf(\"#{1 + 1 eq 2}\") evaluated to true")); }
@Test void missingDisabledIf() { assertResult(condition.evaluateExecutionCondition(buildExtensionContext("missingDisabledIf")), false, endsWith("missingDisabledIf() is enabled since @DisabledIf is not present")); }