From 4e3b7405cc2bad7eb1c34601ba19d0b7b410ebfa Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Thu, 27 Aug 2020 12:40:27 +0200 Subject: [PATCH] Add a new AssertJ template that does not produce deprecated warnings. --- .../has_assertion_template.txt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 etc/assertj-templates/has_assertion_template.txt diff --git a/etc/assertj-templates/has_assertion_template.txt b/etc/assertj-templates/has_assertion_template.txt new file mode 100644 index 00000000..e3493927 --- /dev/null +++ b/etc/assertj-templates/has_assertion_template.txt @@ -0,0 +1,23 @@ + + /** + * Verifies that the actual ${class_to_assert}'s ${property} is equal to the given one. + * @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 not equal to the given one.${throws_javadoc} + */ + public ${self_type} has${Property}(${propertyType} ${property_safe}) ${throws}{ + // 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 be:\n <%s>\nbut was:\n <%s>"; + + // null safe check + ${propertyType} actual${Property} = actual.${getter}(); + if (!java.util.Objects.deepEquals(actual${Property}, ${property_safe})) { + failWithMessage(assertjErrorMessage, actual, ${property_safe}, actual${Property}); + } + + // return the current assertion for method chaining + return ${myself}; + }