You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:17:27 UTC
[sling-org-apache-sling-testing-hamcrest] 07/18: SLING-5481 improve
mismatch failure message for Sling Hamcrest matchers
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.testing.hamcrest-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-hamcrest.git
commit 9930901946de8688a40350af59b600f0d5d0cec0
Author: Konrad Windszus <kw...@apache.org>
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/testing/hamcrest@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
"commits@sling.apache.org" <co...@sling.apache.org>.