Search in sources :

Example 1 with Rule

use of org.junit.Rule in project spring-framework by spring-projects.

the class SpringClassRule method validateSpringMethodRuleConfiguration.

/**
	 * Throw an {@link IllegalStateException} if the supplied {@code testClass}
	 * does not declare a {@code public SpringMethodRule} field that is
	 * annotated with {@code @Rule}.
	 */
private static void validateSpringMethodRuleConfiguration(Class<?> testClass) {
    Field ruleField = findSpringMethodRuleField(testClass).orElseThrow(() -> new IllegalStateException(String.format("Failed to find 'public SpringMethodRule' field in test class [%s]. " + "Consult the javadoc for SpringClassRule for details.", testClass.getName())));
    Assert.state(ruleField.isAnnotationPresent(Rule.class), () -> String.format("SpringMethodRule field [%s] must be annotated with JUnit's @Rule annotation. " + "Consult the javadoc for SpringClassRule for details.", ruleField));
}
Also used : Field(java.lang.reflect.Field) TestRule(org.junit.rules.TestRule) Rule(org.junit.Rule)

Aggregations

Field (java.lang.reflect.Field)1 Rule (org.junit.Rule)1 TestRule (org.junit.rules.TestRule)1