hardayal / hamcrest

Automatically exported from code.google.com/p/hamcrest
0 stars 0 forks source link

array mismatch description should not just use array element toString value in mismatch description #212

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Using the 'Matchers.array' method to construct a matcher for an array like this:

    assertThat(someArrayOfObjects, array(
       myMatcher(...)
    ));

The descriptions of the failure to match leaves a lot to be desired because it 
just dumps the 'toString' value of the mismatching array element into the 
description. So you get something like this:

Expected: [myMatcher(...)]
     but: element 0 was SomeClass@10efe4ca

The description of what is expected [myMatcher(...)] is clear, but the 
description of what was actually found is very obscure since its impossible to 
tell from an object's toString value what is actually 'inside' the object being 
matched against.

This happens even though I implemented a method to specifically 
'describeMismatch' for 'myMatcher' to craft a nice and specific description of 
the mismatch, but the 'nice' description is not getting used.

This a nuisance at best, but it is *very* annoying when the objects being 
matched against do not have nice 'toString'. You could say that maybe one 
should always have a nice toString, I tend to agree, but sometimes one simply 
has no control over an object's toString implementation as the objects come 
from library code.

Original issue reported on code.google.com by kris.de....@gmail.com on 24 Mar 2015 at 5:05