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@1705299 13f79535-47bb-0310-9956-ffa450edef68
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 @@
*/
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);
}