I brought this up in the hallway today, figured I'd share. What is the best practices around equals methods? I made a change to a Consumer's facts list in a test and expected the test to fail.
Consumer con1 = new Consumer("name", owner, consumerType); Consumer con2 = new Consumer(con1); con1.getFacts().put("name1", "value1"); ... assertEquals(con1, con2);
It did NOT fail. The equals of the Consumer checks only that the uuid's are equal. For the most part this makes sense, but is that really what equals should check? part of me says no it should check everything, but for the most part maybe all we care about is that the uuid's are the same for Consumers.
Thoughts?
jesus
On 03/25/2010 12:41 PM, Jesus M. Rodriguez wrote:
I brought this up in the hallway today, figured I'd share. What is the best practices around equals methods? I made a change to a Consumer's facts list in a test and expected the test to fail.
Consumer con1 = new Consumer("name", owner, consumerType); Consumer con2 = new Consumer(con1); con1.getFacts().put("name1", "value1"); ... assertEquals(con1, con2);
It did NOT fail. The equals of the Consumer checks only that the uuid's are equal. For the most part this makes sense, but is that really what equals should check? part of me says no it should check everything, but for the most part maybe all we care about is that the uuid's are the same for Consumers.
Thoughts?
jesus _______________________________________________ candlepin mailing list candlepin@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/candlepin
I think the common practice is to verify the fields that constitute object's identity. I thought that uuid was rather appropriate for that purpose.
-d
candlepin@lists.fedorahosted.org