### Question:
RuleDefinitionValidator { void validateRuleDefinition(final Object rule) { checkRuleClass(rule); checkConditionMethod(rule); checkActionMethods(rule); checkPriorityMethod(rule); }    }### Answer:
@Test(expected = IllegalArgumentException.class) public void notAnnotatedRuleMustNotBeAccepted() { ruleDefinitionValidator.validateRuleDefinition(new Object()); }
@Test public void withCustomAnnotationThatIsItselfAnnotatedWithTheRuleAnnotation() { ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithMetaRuleAnnotation()); }
@Test(expected = IllegalArgumentException.class) public void conditionMethodMustBeDefined() { ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithoutConditionMethod()); }
@Test(expected = IllegalArgumentException.class) public void conditionMethodMustBePublic() { ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithNonPublicConditionMethod()); }
@Test(expected = IllegalArgumentException.class) public void whenConditionMethodHasOneNonAnnotatedParameter_thenThisParameterMustBeOfTypeFacts() { ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithConditionMethodHavingOneArgumentNotOfTypeFacts()); }
@Test(expected = IllegalArgumentException.class) public void conditionMethodMustReturnBooleanType() { ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithConditionMethodHavingNonBooleanReturnType()); }
@Test(expected = IllegalArgumentException.class) public void conditionMethodParametersShouldAllBeAnnotatedWithFactUnlessExactlyOneOfThemIsOfTypeFacts() { ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithOneParameterNotAnnotatedWithFactAndNotOfTypeFacts()); }
@Test(expected = IllegalArgumentException.class) public void actionMethodMustBeDefined() { ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithoutActionMethod()); }
@Test(expected = IllegalArgumentException.class) public void actionMethodMustBePublic() { ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithNonPublicActionMethod()); }
@Test(expected = IllegalArgumentException.class) public void actionMethodMustHaveAtMostOneArgumentOfTypeFacts() { ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithActionMethodHavingOneArgumentNotOfTypeFacts()); }
@Test(expected = IllegalArgumentException.class) public void actionMethodMustHaveExactlyOneArgumentOfTypeFactsIfAny() { ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithActionMethodHavingMoreThanOneArgumentOfTypeFacts()); }
@Test(expected = IllegalArgumentException.class) public void actionMethodMustReturnVoid() { ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithActionMethodThatReturnsNonVoidType()); }
@Test(expected = IllegalArgumentException.class) public void actionMethodParametersShouldAllBeAnnotatedWithFactUnlessExactlyOneOfThemIsOfTypeFacts() { ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithOneParameterNotAnnotatedWithFactAndNotOfTypeFacts()); }
@Test(expected = IllegalArgumentException.class) public void priorityMethodMustBeUnique() { ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithMoreThanOnePriorityMethod()); }
@Test(expected = IllegalArgumentException.class) public void priorityMethodMustBePublic() { ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithNonPublicPriorityMethod()); }
@Test(expected = IllegalArgumentException.class) public void priorityMethodMustHaveNoArguments() { ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithPriorityMethodHavingArguments()); }
@Test(expected = IllegalArgumentException.class) public void priorityMethodReturnTypeMustBeInteger() { ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithPriorityMethodHavingNonIntegerReturnType()); }
@Test public void validAnnotationsShouldBeAccepted() { try { ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithMultipleAnnotatedParametersAndOneParameterOfTypeFacts()); ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithMultipleAnnotatedParametersAndOneParameterOfSubTypeFacts()); ruleDefinitionValidator.validateRuleDefinition(new AnnotatedRuleWithActionMethodHavingOneArgumentOfTypeFacts()); } catch (Throwable throwable) { Assertions.fail("Should not throw exception for valid rule definitions"); } }