Given the following class...
public class UserAccount {
private Long id;
private String email;
private String activationCode;
private Date createDate;
}
... I need to compare the actual object with an expected object using AssertJ. However the fields id, activationCode and createDate have dynamic value which I can't hard-code into the assertion.
So the following assertion would fail:
assertThat(actualUserAccount).isEqualTo(expectedUserAccount);
Then I found the following which would ignore certain fields:
assertThat(actualUserAccount)
.usingRecursiveComparison()
.ignoringFields("id", "activationCode", "createDate")
.isEqualTo(expectedUserAccount);
But what I'm actually looking for is to assert for the objects being equal with the following special checks on certain fields:
- Is there an
idwith anyLongvalue? - Is there an
activationCodewith anyStringvalue? - Is there an
createDatewith anyDatevalue?
Or is there no other way than to write one assertion for each field?