diff --git a/src/main/resources/templates/has_any_assertion_template.txt b/src/main/resources/templates/has_any_assertion_template.txt new file mode 100644 index 00000000..5e13bcf6 --- /dev/null +++ b/src/main/resources/templates/has_any_assertion_template.txt @@ -0,0 +1,23 @@ + + /** + * Verifies that ${class_to_assert}'s ${property} is not null. + * @param ${property_safe} the given ${property} to compare the actual ${class_to_assert}'s ${property} to. + * @return this assertion object. + * @throws AssertionError - if the actual ${class_to_assert}'s ${property} is null.${throws_javadoc} + */ + public ${self_type} has${Property}() { + // check that actual ${class_to_assert} we want to make assertions on is not null. + isNotNull(); + + // overrides the default error message with a more explicit one + String assertjErrorMessage = "\nExpecting ${property} of:\n <%s>\nto not be null"; + + // null safe check + ${propertyType} actual${Property} = actual.${getter}(); + if (actual${Property} == null) { + failWithMessage(assertjErrorMessage, actual); + } + + // return the current assertion for method chaining + return ${myself}; + }