0

I need to compare a JPA Entity with expected value ignoring IDs. AssertJ has this method

assertThat(actualEntity).isEqualToIgnoringGivenFields(expectedEntity, "id");

which compares two objects ignoring ID, but my actualEntity has a list of inner entities, that have IDs too. Is there a method that would recursively ignore field id in the inner objects as well?

I saw there is this method

assertThat(actuactualEntitya).isEqualToComparingFieldByFieldRecursively(expectedEntity);

but I don't see an option how to tell that I want to ignore id recursively. Is there any way, how to achieve that using AssertJ?

Michal Krasny
  • 5,434
  • 7
  • 36
  • 64

1 Answers1

1

Yes it can, use the recursive comparison for that https://assertj.github.io/doc/#assertj-core-recursive-comparison which lets you specify fields to ignore by name or regex: https://assertj.github.io/doc/#assertj-core-recursive-comparison-ignoring-fields

Joel Costigliola
  • 6,308
  • 27
  • 35
  • Thanks, I probably have too old version of AssertJ and this method is not there. I'll check int the team if upgrade is possible. – Michal Krasny Mar 13 '23 at 22:20