peterlck / hamcrest

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

IsArray.describeMismatchSafely() should use Matcher.describeMismatch #187

Closed GoogleCodeExporter closed 10 years ago

GoogleCodeExporter commented 10 years ago
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;
         }
       }

Original issue reported on code.google.com by halfu...@gmail.com on 29 Jun 2012 at 2:57