Export to GitHub

hamcrest - issue #187

IsArray.describeMismatchSafely() should use Matcher.describeMismatch


Posted on Jun 29, 2012 by Grumpy Monkey

IsArray.describeMismatchSafely() currently appends the offending object's .toString(), which can make to figure out which comparison failed. For example hasPropery() has different error messages depending if the method exists or returns the wrong value.

It would be nice to change it so the failing matcher could describe the mismatch. Something like this:

diff --git a/IsArray.java b/IsArray.java index fa5a765..24bdea2 100644 --- a/IsArray.java +++ b/IsArray.java @@ -6,7 +6,8 @@ } for (int i = 0; i < actual.length; i++) { if (!elementMatchers[i].matches(actual[i])) { - mismatchDescription.appendText("element " + i + " was ").appendValue(actual[i]); + mismatchDescription.appendText("in element " + i + " "); + elementMatchers[i].describeMismatch(actual[i], mismatchDescription); return; } }

Comment #1

Posted on Jul 9, 2012 by Massive Hippo

(No comment was entered for this change.)

Comment #2

Posted on Jul 18, 2012 by Massive Hippo

(No comment was entered for this change.)

Comment #3

Posted on Jul 18, 2012 by Massive Hippo

should be addressed by commit: https://github.com/hamcrest/JavaHamcrest/commit/6f59fa88b4923064b2a5a41afd9ad508ec0cc602

Status: Fixed

Labels:
Java