Creating a custom strategy - TestMonkeys/jEntityTest GitHub Wiki
If you need a custom strategy, you can implement your own following this guide:
Abort Conditions
Abort conditions are meant as a mechanism to stop comparison for a field - either marking the comparison as passed or failed, depending on a combination of expected/actual values. To implement a custom abort condition - create a new class extending AbstractAbortCondition. The following example shows a custom abort condition that would work on String values, stopping further comparison if the expected value is "passThisField", for any other values - the comparison would continue using either the default or the configured comparison strategy.
public class CustomAbortCondition extends AbstractAbortCondition {
public ConditionalCheckResult runCheck(Object actual, Object expected, ComparisonContext context) {
ConditionalCheckResult result = new ConditionalCheckResult(Passed, context, actual, expected);
if ("passThisField".equals(expected.toString())) {
result.stopComparison();
}
return result;
}
}
This class can be used in a yaml configuration directly, providing the fully qualified class name as the strategy, or if you want to use this in an annotated comparison model, you need to define and bind an annotation to it:
annotation:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.FIELD})
public @interface IgnoreComparisonIfExpectedValueIsPassThisField {
}
binding:
AnnotationToComparatorDictionary.getInstance().setPreConditionalCheckForAnnotation(CustomAbortCondition.class, IgnoreComparisonIfExpectedValueIsPassThisField.class);