This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-hamcrest.git
commit 7b14f5c822d76c3d5e76236f1e066ac5d3a0ad6e Author: Konrad Windszus <[email protected]> AuthorDate: Wed Feb 3 15:37:01 2016 +0000 SLING-5481 improve mismatch failure message for Sling Hamcrest matchers git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1728333 13f79535-47bb-0310-9956-ffa450edef68 --- .../sling/hamcrest/matchers/ResourceChildrenMatcher.java | 12 +++++++++++- .../org/apache/sling/hamcrest/matchers/ResourceMatcher.java | 13 +++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/sling/hamcrest/matchers/ResourceChildrenMatcher.java b/src/main/java/org/apache/sling/hamcrest/matchers/ResourceChildrenMatcher.java index 9dc4465..4415a8c 100644 --- a/src/main/java/org/apache/sling/hamcrest/matchers/ResourceChildrenMatcher.java +++ b/src/main/java/org/apache/sling/hamcrest/matchers/ResourceChildrenMatcher.java @@ -16,6 +16,7 @@ */ package org.apache.sling.hamcrest.matchers; +import java.util.ArrayList; import java.util.List; import org.apache.sling.api.resource.Resource; @@ -48,5 +49,14 @@ public class ResourceChildrenMatcher extends TypeSafeMatcher<Resource> { } return true; } - + + @Override + protected void describeMismatchSafely(Resource item, Description mismatchDescription) { + List<String> actualChildNames = new ArrayList<String>(); + for (Resource child : item.getChildren()) { + actualChildNames.add(child.getName()); + } + mismatchDescription.appendText("was Resource with children ").appendValueList("[", ",", "]", actualChildNames).appendText(" (resource: ").appendValue(item).appendText(")"); + } + } \ No newline at end of file diff --git a/src/main/java/org/apache/sling/hamcrest/matchers/ResourceMatcher.java b/src/main/java/org/apache/sling/hamcrest/matchers/ResourceMatcher.java index ed25bd6..4f8ec2c 100644 --- a/src/main/java/org/apache/sling/hamcrest/matchers/ResourceMatcher.java +++ b/src/main/java/org/apache/sling/hamcrest/matchers/ResourceMatcher.java @@ -16,6 +16,9 @@ */ package org.apache.sling.hamcrest.matchers; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Map; import org.apache.sling.api.resource.Resource; @@ -54,4 +57,14 @@ public class ResourceMatcher extends TypeSafeMatcher<Resource> { return true; } + @Override + protected void describeMismatchSafely(Resource item, Description mismatchDescription) { + Map<String, Object> actualProperties = item.adaptTo(ValueMap.class); + if (actualProperties == null) { + mismatchDescription.appendText("was Resource which does not expose a value map via adaptTo"); + return; + } + mismatchDescription.appendText("was Resource with properties ").appendValueList("[", ",", "]", actualProperties.entrySet()).appendText(" (resource: ").appendValue(item).appendText(")"); + } + } \ No newline at end of file -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
