(Reported initially on the old google-code site by qualidafial, aka Matt Hall)
class Foo { @Property Bar bar; }
class Bar { @Property String baz; }
Foo expected = new Foo().withBar( new Bar().withBaz("abc") );
Foo actual = new Foo().withBar( new Bar().withBaz("123") );
In the above case, calling PojomaticAssert.assertEqualsWithDiff produces a message to the effect that Foo.bar is different for each object.
java.lang.AssertionError: differences between expected and actual:
bar: {Bar{baz: {"abc"}} versus
{Bar{baz: {"123"}}
(expected:<Foo{bar: {Bar{baz:="" {"abc"}}}="">
but was:<Foo{bar: {Bar{baz:="" {"123"}}}="">)
Most of the time the differences can be sorted out by looking at toString().
However tonight I was bitten Hibernate's PersistentBag implementation, which uses instance equals despite the List interface contract. Thus the differences between my two instances was not evident from the toString() of expected and actual--they were both empty lists.
I propose enhancing Pojomatic.diff so that the description of any property difference will recurse on Pojomatic.diff, provided both property values are equals-compatible, and from pojomated classes.
I believe this change will help cut to the chase when debugging equals-related testing problems.
Anonymous
Do you have any proposals for what you would like the output to look like for nested differences?