1

I have this code for checking if an object is equals to another one comparing all fields recursively using JUnit 5 and AssertJ:

assertThat(financialDataContainer2.getStandardisedBooking())
    .isEqualToComparingFieldByFieldRecursively(initialBooking);

How can you have an assertion in AssertJ which is the negation of this one? Basically I want to be able to check if two objects are not equal by comparing recursively all fields.

davidxxx
  • 125,838
  • 23
  • 214
  • 215
gil.fernandes
  • 12,978
  • 5
  • 63
  • 76

1 Answers1

1

See my answer to How do I negate assertions in AssertJ?

In your case the code would be:

assertThat(Collections.singleton(actual)).noneSatisfy(actual -> 
  assertThat(actual).isEqualToComparingFieldByFieldRecursively(unexpected)
);
Joachim Lous
  • 1,316
  • 1
  • 14
  • 22