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:22 UTC

[sling-org-apache-sling-testing-hamcrest] 02/18: SLING-5063 - Create a set of Hamcrest matchers for JUnit tests

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 01f41ef2855aa6a8693749be3df5b9bd61c66123
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri Sep 25 13:32:45 2015 +0000

    SLING-5063 - Create a set of Hamcrest matchers for JUnit tests
    
    Add javadoc for ResourceMatchers
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/hamcrest@1705299 13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/sling/hamcrest/ResourceMatchers.java    | 36 ++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/src/main/java/org/apache/sling/hamcrest/ResourceMatchers.java b/src/main/java/org/apache/sling/hamcrest/ResourceMatchers.java
index 7950a2b..dea43d8 100644
--- a/src/main/java/org/apache/sling/hamcrest/ResourceMatchers.java
+++ b/src/main/java/org/apache/sling/hamcrest/ResourceMatchers.java
@@ -32,14 +32,50 @@ import org.hamcrest.Matcher;
  */
 public final class ResourceMatchers {
     
+    /**
+     * Matches resources which have amongst their children the specified <tt>children</tt>.
+     * 
+     * Child resources not contained in the specified <tt>children</tt> are not validated.
+     * 
+     * <pre>
+     * assertThat(resource, hasChildren('child1', 'child2'));
+     * </pre>
+     * 
+     * @param children the expected children, not <code>null</code> or empty
+     * @return a matcher instance
+     */
     public static Matcher<Resource> hasChildren(String... children) {
         return new ResourceChildrenMatcher(Arrays.asList(children));
     }
     
+    /**
+     * Matches resources with a resource type set to the specified <tt>resourceType</tt>
+     * 
+     * <pre>
+     * assertThat(resource, resourceOfType('my/app'));
+     * </pre>
+     * @param resourceType the resource type to match
+     * @return a matcher instance
+     */
     public static Matcher<Resource> resourceOfType(String resourceType) {
         return new ResourceMatcher(Collections.<String, Object> singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, resourceType));
     }
 
+    /**
+     * Matches resources which has at least the specified <tt>properties</tt> defined with matching values
+     * 
+     * <p>Values not declared in the the <tt>properties</tt> parameter are not validated.</p>
+     * <pre>
+     * Map<String, Object> expectedProperties = new HashMap<>();
+     * expectedProperties.put("jcr:title", "Node title");
+     * expectedProperties.put("jcr:text",  "Some long text");
+     * 
+     * assertThat(resource, resourceWithProps(expectedProperties));
+     * </pre>
+     * 
+     * @param resourceType the resource type to match
+     * @return a matcher instance
+     */    
     public static Matcher<Resource> resourceWithProps(Map<String, Object> properties) {
         return new ResourceMatcher(properties);
     }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.