I have started trying to get my Unit Tests as cleaner as possible and I came across with: How could I compare in a clean way a DTO and a Domain Model (DM) which contain more than 10 attributes and share some of them but not all?
Detail: There can be shared attributes but with different type or different name so reflection cannot be used in this case.
Example:
class Person {
private String id;
private String name;
private String lastName;
private Date dateOfbirth;
}
class PersonDto{
private String id;
private String name;
private String lastName;
private int dateOfBirth;
}
The DTO should not hold any kind of complex logic as it is only to transfer Data between Client - Controller - Service.
The DM to persist and provide information between Service - Repository layers. But it should not have any kind of complex logic (equals and hashcode so far).
Then I was thinking... Should I create a TestHelperComparator
to perform this operation? or implement in the DTO or DM a method to Compare to each other? or what is the best practice in this case?