I have created a value object MarketVO and two instances of this value object have same elements and same value for each element.
My value object class is:
public class MarketVO {
private double floatAmt;
private Date marketDate;
private long marketCap;
}
Here are the values:
returnedData:
FloatAmt: 247657.5418618201, MarketCap: 5249164,
MarketDate: 2011-07-29 00:00:00.0
expectedData:
FloatAmt: 247657.5418618201, MarketCap: 5249164,
MarketDate: 2011-07-29 00:00:00.0
Now in my unit test class, I want to assert that my returned and expected type is same containing same value in same order so am doing something like
assertTrue(returnedData.equals(expectedData)), now this is returning false value but if I do
assertEquals(testObject.getfloatAmt(), testObject2.getfloatAmt());
assertEquals(testObject.getmarketCap(), testObject2.getmarketCap());
assertEquals(testObject.getmarketDate(), testObject2.getmarketDate());
this test passes and so am not sure as to why .equals method is not working in here? Any suggestions?
Update: I want to put emphasize here that we are using this for doing Unit Testing.
The default implementation of
.equalscompares object references, not object content.You probably want to override the equals (and hashCode) methods. Something like this: