I just want to know if there is a best practice or a common way to test equals implementation in objects. I mean test method that has been overridden.
public boolean equals(Object o)
I did using some logic like this. (Suppose number and name need to be equals to obtain true)
Dog d1 = new Dog(1,"Alvin");
Dog d2 = new Dog(2,"Alvin");
Assert.assertFalse(d1.equals(null));
Assert.assertFalse(d1.equals(d2));
d2.setId(1);
d2.setName("Kelvin");
Assert.assertFalse(d1.equals(d2));
d2.setName("Alvin");
Assert.assertTrue(d1.equals(d2));
Assert.assertTrue(d1.equals(d1));
But when there are a lot of fields this task is very large and boring, so my question is if there is any framework, tool, option, anything that makes this easier and can proof that method has been overridden correctly. thanks.
I know that override the method equals depends on the logic that you need, but also test case creation is, so looking for an standard way to test the method avoiding large codes in test cases, if there is exists obviously or any suggestion you might have.