/** * Containers and tests are disabled if {@code @DisabledIf} is present on the * corresponding test class or test method and the configured expression evaluates * to {@code true}. */ @Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { return evaluateAnnotation(DisabledIf.class, DisabledIf::expression, DisabledIf::reason, DisabledIf::loadContext, false, context); }
private void assertExpressionIsBlank(String methodName) { IllegalStateException exception = assertThrows(IllegalStateException.class, () -> condition.evaluateExecutionCondition(buildExtensionContext(methodName))); assertThat(exception.getMessage(), containsString("must not be blank")); }
@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\""))); }
/** * Containers and tests are disabled if {@code @DisabledIf} is present on the * corresponding test class or test method and the configured expression evaluates * to {@code true}. */ @Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { return evaluateAnnotation(DisabledIf.class, DisabledIf::expression, DisabledIf::reason, DisabledIf::loadContext, false, context); }
@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"))); }
/** * Containers and tests are disabled if {@code @DisabledIf} is present on the * corresponding test class or test method and the configured expression evaluates * to {@code true}. */ @Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { return evaluateAnnotation(DisabledIf.class, DisabledIf::expression, DisabledIf::reason, DisabledIf::loadContext, false, context); }
@Test void disabledWithCustomReason() { assertResult(condition.evaluateExecutionCondition(buildExtensionContext("customReason")), true, is(equalTo("Because... 42!"))); }
@Test void notDisabledWithDefaultReason() { assertResult(condition.evaluateExecutionCondition(buildExtensionContext("neverDisabledWithDefaultReason")), false, endsWith( "neverDisabledWithDefaultReason() is enabled because @DisabledIf(\"false\") did not evaluate to true")); }
@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")); }