Skip to content

Commit

Permalink
Use actual and expected in the order that is expected by AssertJ (#…
Browse files Browse the repository at this point in the history
…28600)

This mainly corrects the error messages in case of test failures, where currently the actual value is showing as the expected value and vice versa.

assertThat() takes the actual value as parameter instead of the expected value, see https://www.javadoc.io/doc/org.assertj/assertj-core/latest/org/assertj/core/api/Assertions.html#assertThat(boolean)
  • Loading branch information
floscher authored Feb 4, 2025
1 parent b3ec8b5 commit f3b8eac
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ public class <%= persistClass %>Asserts {
*/
public static void assert<%- persistClass %>AutoGeneratedPropertiesEquals(<%- persistClass %> expected, <%- persistClass %> actual) {
<%_ if (fields.some(field => !field.transient && field.autoGenerate)) { _%>
assertThat(expected)
assertThat(actual)
.as("Verify <%- persistClass %> auto generated properties")
<%_ for (const field of fields.filter(field => !field.transient && field.autoGenerate)) { _%>
.satisfies(e -> assertThat(e.get<%- field.fieldInJavaBeanMethod %>()).as("check <%- field.propertyName %>").isEqualTo(actual.get<%- field.fieldInJavaBeanMethod %>()))
.satisfies(a -> assertThat(a.get<%- field.fieldInJavaBeanMethod %>()).as("check <%- field.propertyName %>").isEqualTo(expected.get<%- field.fieldInJavaBeanMethod %>()))
<%_ } _%>
<%_ for (const relationship of relationships.filter(relationship => (!embedded || relationship.otherEntity.embedded) && relationship.autoGenerate && !relationship.otherEntity.builtInUser)) { _%>
.satisfies(e -> assertThat(e.get<%- relationship.propertyJavaBeanName %>()).as("check <%- relationship.propertyName %>").isEqualTo(actual.get<%- relationship.propertyJavaBeanName %>()))
.satisfies(a -> assertThat(a.get<%- relationship.propertyJavaBeanName %>()).as("check <%- relationship.propertyName %>").isEqualTo(expected.get<%- relationship.propertyJavaBeanName %>()))
<%_ } _%>
;
<%_ } else { _%>
Expand All @@ -95,17 +95,17 @@ public class <%= persistClass %>Asserts {
*/
public static void assert<%- persistClass %>UpdatableFieldsEquals(<%- persistClass %> expected, <%- persistClass %> actual) {
<%_ if (fields.some(field => !field.transient && !field.autoGenerate)) { _%>
assertThat(expected)
assertThat(actual)
.as("Verify <%- persistClass %> relevant properties")
<%_ for (const field of fields.filter(field => !field.transient && !field.autoGenerate)) { _%>
<%_ if (field.fieldTypeZonedDateTime) { _%>
.satisfies(e -> assertThat(e.get<%- field.fieldInJavaBeanMethod %>()).as("check <%- field.propertyName %>").usingComparator(zonedDataTimeSameInstant).isEqualTo(actual.get<%- field.fieldInJavaBeanMethod %>()))
.satisfies(a -> assertThat(a.get<%- field.fieldInJavaBeanMethod %>()).as("check <%- field.propertyName %>").usingComparator(zonedDataTimeSameInstant).isEqualTo(expected.get<%- field.fieldInJavaBeanMethod %>()))
<%_ } else if (field.fieldTypeBigDecimal) { _%>
.satisfies(e -> assertThat(e.get<%- field.fieldInJavaBeanMethod %>()).as("check <%- field.propertyName %>").usingComparator(bigDecimalCompareTo).isEqualTo(actual.get<%- field.fieldInJavaBeanMethod %>()))
.satisfies(a -> assertThat(a.get<%- field.fieldInJavaBeanMethod %>()).as("check <%- field.propertyName %>").usingComparator(bigDecimalCompareTo).isEqualTo(expected.get<%- field.fieldInJavaBeanMethod %>()))
<%_ } else { _%>
.satisfies(e -> assertThat(e.get<%- field.fieldInJavaBeanMethod %>()).as("check <%- field.propertyName %>").isEqualTo(actual.get<%- field.fieldInJavaBeanMethod %>()))
.satisfies(a -> assertThat(a.get<%- field.fieldInJavaBeanMethod %>()).as("check <%- field.propertyName %>").isEqualTo(expected.get<%- field.fieldInJavaBeanMethod %>()))
<%_ if (field.fieldTypeBinary && !field.blobContentTypeText) { _%>
.satisfies(e -> assertThat(e.get<%- field.fieldInJavaBeanMethod %>ContentType()).as("check <%- field.propertyName %> contenty type").isEqualTo(actual.get<%- field.fieldInJavaBeanMethod %>ContentType()))
.satisfies(a -> assertThat(a.get<%- field.fieldInJavaBeanMethod %>ContentType()).as("check <%- field.propertyName %> contenty type").isEqualTo(expected.get<%- field.fieldInJavaBeanMethod %>ContentType()))
<%_ } -%>
<%_ } -%>
<%_ } -%>
Expand All @@ -124,10 +124,10 @@ public class <%= persistClass %>Asserts {
*/
public static void assert<%- persistClass %>UpdatableRelationshipsEquals(<%- persistClass %> expected, <%- persistClass %> actual) {
<%_ if (relationships.some(relationship => relationship.persistableRelationship && !relationship.id && !relationship.autoGenerate && !relationship.otherEntity.builtInUser)) { _%>
assertThat(expected)
assertThat(actual)
.as("Verify <%- persistClass %> relationships")
<%_ for (const relationship of relationships.filter(relationship => (!embedded || relationship.otherEntity.embedded) && relationship.persistableRelationship && !relationship.id && !relationship.autoGenerate && !relationship.otherEntity.builtInUser)) { _%>
.satisfies(e -> assertThat(e.get<%- relationship.propertyJavaBeanName %>()).as("check <%- relationship.propertyName %>").isEqualTo(actual.get<%- relationship.propertyJavaBeanName %>()))
.satisfies(a -> assertThat(a.get<%- relationship.propertyJavaBeanName %>()).as("check <%- relationship.propertyName %>").isEqualTo(expected.get<%- relationship.propertyJavaBeanName %>()))
<%_ } _%>
;
<%_ } else { _%>
Expand Down

0 comments on commit f3b8eac

Please sign in to comment.