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 9f3c38a14bd7843b80b3dfefc28dcce2feabb3d3 Author: Stefan Seifert <[email protected]> AuthorDate: Mon Oct 10 20:59:09 2016 +0000 SLING-6117 remove "with"/"has" prefix from ResourceMatchers method names as well add "path" to resource collection/iterator matchers git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1764180 13f79535-47bb-0310-9956-ffa450edef68 --- .../sling/hamcrest/ResourceCollectionMatchers.java | 4 +- .../sling/hamcrest/ResourceIteratorMatchers.java | 4 +- .../apache/sling/hamcrest/ResourceMatchers.java | 18 ++++---- ...her.java => ResourceCollectionPathMatcher.java} | 4 +- ...tcher.java => ResourceIteratorPathMatcher.java} | 4 +- .../sling/hamcrest/ResourceMatchersTest.java | 50 +++++++++++----------- 6 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/main/java/org/apache/sling/hamcrest/ResourceCollectionMatchers.java b/src/main/java/org/apache/sling/hamcrest/ResourceCollectionMatchers.java index ea67b37..384901b 100644 --- a/src/main/java/org/apache/sling/hamcrest/ResourceCollectionMatchers.java +++ b/src/main/java/org/apache/sling/hamcrest/ResourceCollectionMatchers.java @@ -20,7 +20,7 @@ import java.util.Arrays; import java.util.Collection; import org.apache.sling.api.resource.Resource; -import org.apache.sling.hamcrest.matchers.ResourceCollectionMatcher; +import org.apache.sling.hamcrest.matchers.ResourceCollectionPathMatcher; import org.hamcrest.Matcher; /** @@ -38,7 +38,7 @@ public final class ResourceCollectionMatchers { * @return a matcher instance */ public static Matcher<Collection<Resource>> paths(String... paths) { - return new ResourceCollectionMatcher(Arrays.asList(paths)); + return new ResourceCollectionPathMatcher(Arrays.asList(paths)); } } diff --git a/src/main/java/org/apache/sling/hamcrest/ResourceIteratorMatchers.java b/src/main/java/org/apache/sling/hamcrest/ResourceIteratorMatchers.java index fb633c8..fb650d1 100644 --- a/src/main/java/org/apache/sling/hamcrest/ResourceIteratorMatchers.java +++ b/src/main/java/org/apache/sling/hamcrest/ResourceIteratorMatchers.java @@ -20,7 +20,7 @@ import java.util.Arrays; import java.util.Iterator; import org.apache.sling.api.resource.Resource; -import org.apache.sling.hamcrest.matchers.ResourceIteratorMatcher; +import org.apache.sling.hamcrest.matchers.ResourceIteratorPathMatcher; import org.hamcrest.Matcher; /** @@ -38,7 +38,7 @@ public final class ResourceIteratorMatchers { * @return a matcher instance */ public static Matcher<Iterator<Resource>> paths(String... paths) { - return new ResourceIteratorMatcher(Arrays.asList(paths)); + return new ResourceIteratorPathMatcher(Arrays.asList(paths)); } } diff --git a/src/main/java/org/apache/sling/hamcrest/ResourceMatchers.java b/src/main/java/org/apache/sling/hamcrest/ResourceMatchers.java index ebd4cba..2455111 100644 --- a/src/main/java/org/apache/sling/hamcrest/ResourceMatchers.java +++ b/src/main/java/org/apache/sling/hamcrest/ResourceMatchers.java @@ -90,7 +90,7 @@ public final class ResourceMatchers { * @param path the resources path, not <code>null</code> or empty * @return a matcher instance */ - public static Matcher<Resource> withPath(String path) { + public static Matcher<Resource> path(String path) { return new ResourcePathMatcher(path); } @@ -104,7 +104,7 @@ public final class ResourceMatchers { * @param name the resources name, not <code>null</code> or empty * @return a matcher instance */ - public static Matcher<Resource> withName(String name) { + public static Matcher<Resource> name(String name) { return new ResourceNameMatcher(name); } @@ -117,7 +117,7 @@ public final class ResourceMatchers { * @param resourceType the resource type to match * @return a matcher instance */ - public static Matcher<Resource> ofType(String resourceType) { + public static Matcher<Resource> resourceType(String resourceType) { return new ResourcePropertiesMatcher(Collections.<String, Object> singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, resourceType)); } @@ -136,7 +136,7 @@ public final class ResourceMatchers { * @param properties the properties to match * @return a matcher instance */ - public static Matcher<Resource> withProps(Map<String, Object> properties) { + public static Matcher<Resource> props(Map<String, Object> properties) { return new ResourcePropertiesMatcher(properties); } @@ -155,8 +155,8 @@ public final class ResourceMatchers { * @param properties the properties to match * @return a matcher instance */ - public static Matcher<Resource> withProps(Object... properties) { - return withProps(MapUtil.toMap(properties)); + public static Matcher<Resource> props(Object... properties) { + return props(MapUtil.toMap(properties)); } /** @@ -175,7 +175,7 @@ public final class ResourceMatchers { * @param properties the properties to match * @return a matcher instance */ - public static Matcher<Resource> withNameAndProps(String name, Map<String, Object> properties) { + public static Matcher<Resource> nameAndProps(String name, Map<String, Object> properties) { return Matchers.allOf(new ResourceNameMatcher(name), new ResourcePropertiesMatcher(properties)); } @@ -195,8 +195,8 @@ public final class ResourceMatchers { * @param properties the properties to match * @return a matcher instance */ - public static Matcher<Resource> withNameAndProps(String name, Object... properties) { - return withNameAndProps(name, MapUtil.toMap(properties)); + public static Matcher<Resource> nameAndProps(String name, Object... properties) { + return nameAndProps(name, MapUtil.toMap(properties)); } private ResourceMatchers() { diff --git a/src/main/java/org/apache/sling/hamcrest/matchers/ResourceCollectionMatcher.java b/src/main/java/org/apache/sling/hamcrest/matchers/ResourceCollectionPathMatcher.java similarity index 93% rename from src/main/java/org/apache/sling/hamcrest/matchers/ResourceCollectionMatcher.java rename to src/main/java/org/apache/sling/hamcrest/matchers/ResourceCollectionPathMatcher.java index 1c3a312..ecdf75e 100644 --- a/src/main/java/org/apache/sling/hamcrest/matchers/ResourceCollectionMatcher.java +++ b/src/main/java/org/apache/sling/hamcrest/matchers/ResourceCollectionPathMatcher.java @@ -28,12 +28,12 @@ import org.hamcrest.TypeSafeMatcher; /** * Ensures a collection of resources has exactly the given list of paths in the given order. */ -public class ResourceCollectionMatcher extends TypeSafeMatcher<Collection<Resource>> { +public class ResourceCollectionPathMatcher extends TypeSafeMatcher<Collection<Resource>> { // this should be "Iterable<? extends Resource>" instead of "?" but cannot until https://github.com/hamcrest/JavaHamcrest/issues/107 is solved private final Matcher<?> iterarableMatcher; - public ResourceCollectionMatcher(List<String> paths) { + public ResourceCollectionPathMatcher(List<String> paths) { if ( paths == null || paths.isEmpty() ) { throw new IllegalArgumentException("names is null or empty"); } diff --git a/src/main/java/org/apache/sling/hamcrest/matchers/ResourceIteratorMatcher.java b/src/main/java/org/apache/sling/hamcrest/matchers/ResourceIteratorPathMatcher.java similarity index 94% rename from src/main/java/org/apache/sling/hamcrest/matchers/ResourceIteratorMatcher.java rename to src/main/java/org/apache/sling/hamcrest/matchers/ResourceIteratorPathMatcher.java index 37b37fd..16dfa79 100644 --- a/src/main/java/org/apache/sling/hamcrest/matchers/ResourceIteratorMatcher.java +++ b/src/main/java/org/apache/sling/hamcrest/matchers/ResourceIteratorPathMatcher.java @@ -28,12 +28,12 @@ import org.hamcrest.TypeSafeMatcher; /** * Ensures an iterator of resources has exactly the given list of paths in the given order. */ -public class ResourceIteratorMatcher extends TypeSafeMatcher<Iterator<Resource>> { +public class ResourceIteratorPathMatcher extends TypeSafeMatcher<Iterator<Resource>> { // this should be "Iterable<? extends Resource>" instead of "?" but cannot until https://github.com/hamcrest/JavaHamcrest/issues/107 is solved private final Matcher<?> iterarableMatcher; - public ResourceIteratorMatcher(List<String> paths) { + public ResourceIteratorPathMatcher(List<String> paths) { if ( paths == null || paths.isEmpty() ) { throw new IllegalArgumentException("names is null or empty"); } diff --git a/src/test/java/org/apache/sling/hamcrest/ResourceMatchersTest.java b/src/test/java/org/apache/sling/hamcrest/ResourceMatchersTest.java index 9e900ce..771d660 100644 --- a/src/test/java/org/apache/sling/hamcrest/ResourceMatchersTest.java +++ b/src/test/java/org/apache/sling/hamcrest/ResourceMatchersTest.java @@ -34,36 +34,36 @@ public class ResourceMatchersTest { public final SlingContext context = new SlingContext(); @Test - public void testOfType() { + public void testResourceType() { context.build().resource("/resource", ResourceResolver.PROPERTY_RESOURCE_TYPE, "some/type", "some other key", "some other value"); Resource resource = context.resourceResolver().getResource("/resource"); - Assert.assertThat(resource, ResourceMatchers.ofType("some/type")); - Assert.assertThat(resource, Matchers.not(ResourceMatchers.ofType("some/other/type"))); + Assert.assertThat(resource, ResourceMatchers.resourceType("some/type")); + Assert.assertThat(resource, Matchers.not(ResourceMatchers.resourceType("some/other/type"))); } @Test - public void testWithPath() { + public void testPath() { context.build().resource("/resource"); Resource resource = context.resourceResolver().getResource("/resource"); - Assert.assertThat(resource, ResourceMatchers.withPath("/resource")); - Assert.assertThat(resource, Matchers.not(ResourceMatchers.withPath("some/other/name"))); + Assert.assertThat(resource, ResourceMatchers.path("/resource")); + Assert.assertThat(resource, Matchers.not(ResourceMatchers.path("some/other/name"))); } @Test - public void testWithName() { + public void testName() { context.build().resource("/resource"); Resource resource = context.resourceResolver().getResource("/resource"); - Assert.assertThat(resource, ResourceMatchers.withName("resource")); - Assert.assertThat(resource, Matchers.not(ResourceMatchers.withName("some/other/name"))); + Assert.assertThat(resource, ResourceMatchers.name("resource")); + Assert.assertThat(resource, Matchers.not(ResourceMatchers.name("some/other/name"))); } @Test - public void testWithProps() { + public void testProps() { context.build().resource("/resource", "key1", "value1", "key2", "value2", @@ -75,24 +75,24 @@ public class ResourceMatchersTest { .build(); Resource resource = context.resourceResolver().getResource("/resource"); - Assert.assertThat(resource, ResourceMatchers.withProps(expectedProperties)); + Assert.assertThat(resource, ResourceMatchers.props(expectedProperties)); // test existing key with not matching value expectedProperties = ImmutableMap.<String, Object>builder() .put("key1", "value1") .put("key2", "value3") .build(); - Assert.assertThat(resource, Matchers.not(ResourceMatchers.withProps(expectedProperties))); + Assert.assertThat(resource, Matchers.not(ResourceMatchers.props(expectedProperties))); // test non-existing key expectedProperties = ImmutableMap.<String, Object>builder() .put("key4", "value4") .build(); - Assert.assertThat(resource, Matchers.not(ResourceMatchers.withProps(expectedProperties))); + Assert.assertThat(resource, Matchers.not(ResourceMatchers.props(expectedProperties))); } @Test - public void testWithPropsVarargs() { + public void testPropsVarargs() { context.build().resource("/resource", "key1", "value1", "key2", "value2", @@ -104,20 +104,20 @@ public class ResourceMatchersTest { }; Resource resource = context.resourceResolver().getResource("/resource"); - Assert.assertThat(resource, ResourceMatchers.withProps(expectedProperties)); + Assert.assertThat(resource, ResourceMatchers.props(expectedProperties)); // test existing key with not matching value expectedProperties = new Object[] { "key1", "value1", "key2", "value3" }; - Assert.assertThat(resource, Matchers.not(ResourceMatchers.withProps(expectedProperties))); + Assert.assertThat(resource, Matchers.not(ResourceMatchers.props(expectedProperties))); // test non-existing key expectedProperties = new Object[] { "key4", "value4" }; - Assert.assertThat(resource, Matchers.not(ResourceMatchers.withProps(expectedProperties))); + Assert.assertThat(resource, Matchers.not(ResourceMatchers.props(expectedProperties))); } @Test @@ -131,7 +131,7 @@ public class ResourceMatchersTest { } @Test - public void testWithNameAndProps() { + public void testNameAndProps() { context.build().resource("/resource", "key1", "value1", "key2", "value2", @@ -143,21 +143,21 @@ public class ResourceMatchersTest { .build(); Resource resource = context.resourceResolver().getResource("/resource"); - Assert.assertThat(resource, ResourceMatchers.withNameAndProps("resource", expectedProperties)); + Assert.assertThat(resource, ResourceMatchers.nameAndProps("resource", expectedProperties)); // test not matching name - Assert.assertThat(resource, Matchers.not(ResourceMatchers.withNameAndProps("resource1", expectedProperties))); + Assert.assertThat(resource, Matchers.not(ResourceMatchers.nameAndProps("resource1", expectedProperties))); // test existing key with not matching value expectedProperties = ImmutableMap.<String, Object>builder() .put("key1", "value1") .put("key2", "value3") .build(); - Assert.assertThat(resource, Matchers.not(ResourceMatchers.withNameAndProps("resource", expectedProperties))); + Assert.assertThat(resource, Matchers.not(ResourceMatchers.nameAndProps("resource", expectedProperties))); } @Test - public void testWithNameAndPropsVarargs() { + public void testNameAndPropsVarargs() { context.build().resource("/resource", "key1", "value1", "key2", "value2", @@ -169,17 +169,17 @@ public class ResourceMatchersTest { }; Resource resource = context.resourceResolver().getResource("/resource"); - Assert.assertThat(resource, ResourceMatchers.withNameAndProps("resource", expectedProperties)); + Assert.assertThat(resource, ResourceMatchers.nameAndProps("resource", expectedProperties)); // test not matching name - Assert.assertThat(resource, Matchers.not(ResourceMatchers.withNameAndProps("resource1", expectedProperties))); + Assert.assertThat(resource, Matchers.not(ResourceMatchers.nameAndProps("resource1", expectedProperties))); // test existing key with not matching value expectedProperties = new Object[] { "key1", "value1", "key2", "value3" }; - Assert.assertThat(resource, Matchers.not(ResourceMatchers.withNameAndProps("resource", expectedProperties))); + Assert.assertThat(resource, Matchers.not(ResourceMatchers.nameAndProps("resource", expectedProperties))); } @Test -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
