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 2015/09/25 15:32:45 UTC
svn commit: r1705299 -
/sling/trunk/testing/hamcrest/src/main/java/org/apache/sling/hamcrest/ResourceMatchers.java
Author: rombert
Date: Fri Sep 25 13:32:45 2015
New Revision: 1705299
URL: http://svn.apache.org/viewvc?rev=1705299&view=rev
Log:
SLING-5063 - Create a set of Hamcrest matchers for JUnit tests
Add javadoc for ResourceMatchers
Modified:
sling/trunk/testing/hamcrest/src/main/java/org/apache/sling/hamcrest/ResourceMatchers.java
Modified: sling/trunk/testing/hamcrest/src/main/java/org/apache/sling/hamcrest/ResourceMatchers.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/hamcrest/src/main/java/org/apache/sling/hamcrest/ResourceMatchers.java?rev=1705299&r1=1705298&r2=1705299&view=diff
==============================================================================
--- sling/trunk/testing/hamcrest/src/main/java/org/apache/sling/hamcrest/ResourceMatchers.java (original)
+++ sling/trunk/testing/hamcrest/src/main/java/org/apache/sling/hamcrest/ResourceMatchers.java Fri Sep 25 13:32:45 2015
@@ -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);
}