I know that this question has been asked before. However, none of the solutions are working for me. I have a user-defined class that is a composite of 3 classes. It looks like this:
Class compositeClass
{
UserDefinedClass1 useClass1;
UserDefinedClass2 useClass2;
UserDefinedClass3 useClass3;
}
I have a test method I need to compare Lists of these composite classes. I have tried several variations of the Assert equals like these: Hamcrest:
Assert.assertThat(mockCompositeList().getStandardLoadComposites(),
equalTo(closeRequest.getStandardLoadComposites()));
Assert.assertArrayEquals(mockCompositeList().getStandardLoadComposites().toArray(),
closeRequest.getStandardLoadComposites().toArray());
Both instances return this AssertionError:
Expected < StanardLoadComposite @ 6895a785 > but was < StandardLoadComposite @ 184f6be2 >
It seems it is comparing the reference and not the values in the objects.
Do I have to override the equals
operator to get it to compare the values in the objects of the user defined objects?