This is an automated email from the ASF dual-hosted git repository. kwin pushed a commit to branch feature/parent62 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-hamcrest.git
commit 5e5f869ee0460f99c3b9299d4f01bce529c0fdc3 Author: Konrad Windszus <[email protected]> AuthorDate: Fri Jun 20 14:47:26 2025 +0200 SLING-12835 Reformat with spotless --- pom.xml | 18 +- .../java/org/apache/sling/hamcrest/MapUtil.java | 9 +- .../sling/hamcrest/ResourceCollectionMatchers.java | 29 +-- .../sling/hamcrest/ResourceIteratorMatchers.java | 29 +-- .../apache/sling/hamcrest/ResourceMatchers.java | 89 ++++----- .../hamcrest/matchers/ResourceChildrenMatcher.java | 40 ++-- .../matchers/ResourceCollectionPathMatcher.java | 32 ++-- .../matchers/ResourceIteratorPathMatcher.java | 34 ++-- .../hamcrest/matchers/ResourceNameMatcher.java | 33 ++-- .../hamcrest/matchers/ResourcePathMatcher.java | 34 ++-- .../matchers/ResourcePropertiesMatcher.java | 93 +++++----- .../hamcrest/matchers/ResourceTypeMatcher.java | 34 ++-- .../org/apache/sling/hamcrest/MapUtilTest.java | 29 ++- .../hamcrest/ResourceCollectionMatchersTest.java | 41 ++-- .../hamcrest/ResourceIteratorMatchersTest.java | 43 ++--- .../sling/hamcrest/ResourceMatchersTest.java | 206 ++++++++++----------- 16 files changed, 386 insertions(+), 407 deletions(-) diff --git a/pom.xml b/pom.xml index 420822f..b228bc0 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="ISO-8859-1"?> +<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -33,17 +33,17 @@ <name>Apache Sling Testing Hamcrest</name> <description>Hamcrest matchers tailored for Apache Sling</description> - <properties> - <sling.java.version>11</sling.java.version> - <project.build.outputTimestamp>1</project.build.outputTimestamp> - </properties> - <scm> <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-hamcrest.git</connection> <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-hamcrest.git</developerConnection> <url>https://github.com/apache/sling-org-apache-sling-testing-hamcrest.git</url> </scm> - + + <properties> + <sling.java.version>11</sling.java.version> + <project.build.outputTimestamp>1</project.build.outputTimestamp> + </properties> + <dependencies> <dependency> @@ -58,7 +58,7 @@ <version>2.25.4</version> <scope>provided</scope> </dependency> - + <!-- testing dependencies --> <dependency> <groupId>junit</groupId> @@ -77,6 +77,6 @@ <version>1.0.0</version> <scope>test</scope> </dependency> - + </dependencies> </project> diff --git a/src/main/java/org/apache/sling/hamcrest/MapUtil.java b/src/main/java/org/apache/sling/hamcrest/MapUtil.java index e09339e..356a310 100644 --- a/src/main/java/org/apache/sling/hamcrest/MapUtil.java +++ b/src/main/java/org/apache/sling/hamcrest/MapUtil.java @@ -27,7 +27,7 @@ import java.util.Map; * Map util methods. */ final class MapUtil { - + private MapUtil() { // static methods only } @@ -43,16 +43,15 @@ final class MapUtil { return Collections.emptyMap(); } if (args.length == 1 && args[0] instanceof Map) { - return (Map<String, Object>)args[0]; + return (Map<String, Object>) args[0]; } if (args.length % 2 != 0) { throw new IllegalArgumentException("args must be an even number of name/values:" + Arrays.asList(args)); } final Map<String, Object> result = new HashMap<String, Object>(); - for (int i=0 ; i < args.length; i+=2) { - result.put(args[i].toString(), args[i+1]); + for (int i = 0; i < args.length; i += 2) { + result.put(args[i].toString(), args[i + 1]); } return result; } - } diff --git a/src/main/java/org/apache/sling/hamcrest/ResourceCollectionMatchers.java b/src/main/java/org/apache/sling/hamcrest/ResourceCollectionMatchers.java index b63b27a..1fd1a5f 100644 --- a/src/main/java/org/apache/sling/hamcrest/ResourceCollectionMatchers.java +++ b/src/main/java/org/apache/sling/hamcrest/ResourceCollectionMatchers.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.hamcrest; @@ -27,7 +29,7 @@ import org.hamcrest.Matcher; * A collection of {@code Matcher}s for resource collections. */ public final class ResourceCollectionMatchers { - + private ResourceCollectionMatchers() { // static methods only } @@ -40,5 +42,4 @@ public final class ResourceCollectionMatchers { public static Matcher<Collection<Resource>> paths(String... 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 df45826..fe9f425 100644 --- a/src/main/java/org/apache/sling/hamcrest/ResourceIteratorMatchers.java +++ b/src/main/java/org/apache/sling/hamcrest/ResourceIteratorMatchers.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.hamcrest; @@ -27,7 +29,7 @@ import org.hamcrest.Matcher; * A collection of {@code Matcher}s for resource iterators. */ public final class ResourceIteratorMatchers { - + private ResourceIteratorMatchers() { // static methods only } @@ -40,5 +42,4 @@ public final class ResourceIteratorMatchers { public static Matcher<Iterator<Resource>> paths(String... 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 e8055c6..44f4138 100644 --- a/src/main/java/org/apache/sling/hamcrest/ResourceMatchers.java +++ b/src/main/java/org/apache/sling/hamcrest/ResourceMatchers.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.hamcrest; @@ -33,59 +35,58 @@ import org.hamcrest.Matchers; * */ public final class ResourceMatchers { - + /** * Matches resources which have amongst their children the specified {@code children}. - * + * * Child resources not contained in the specified {@code children} are not validated. The order of the children does not matter. - * + * * <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), false, false); } - + /** * Matches resources which have exactly the children with the names given in {@code children}. The order is validated as well. - * + * * <pre> * assertThat(resource, containsChildren('child1', 'child2')); * </pre> - * + * * @param children the expected children, not <code>null</code> or empty * @return a matcher instance */ public static Matcher<Resource> containsChildren(String... children) { return new ResourceChildrenMatcher(Arrays.asList(children), true, true); } - - + /** * Matches resources which have exactly the children with the names given in {@code children}. The order is not validated. - * + * * <pre> * assertThat(resource, containsChildrenInAnyOrder('child1', 'child2')); * </pre> - * + * * @param children the expected children, not <code>null</code> or empty * @return a matcher instance */ public static Matcher<Resource> containsChildrenInAnyOrder(String... children) { return new ResourceChildrenMatcher(Arrays.asList(children), true, false); } - + /** * Matches only if the resource has the given path - * + * * <pre> * assertThat(resource, hasName('/a/b/c')); * </pre> - * + * * @param path the resources path, not <code>null</code> or empty * @return a matcher instance */ @@ -95,11 +96,11 @@ public final class ResourceMatchers { /** * Matches only if the resource has the given name - * + * * <pre> * assertThat(resource, resourceWithName('resource1')); * </pre> - * + * * @param name the resources name, not <code>null</code> or empty * @return a matcher instance */ @@ -110,7 +111,7 @@ public final class ResourceMatchers { /** * Matches resources with a resource type set to the specified {@code resourceType} (exactly). * In order to check for resource types allowing more specific ones use {@link #resourceTypeOrDerived(String)}. - * + * * <pre> * assertThat(resource, resourceType('my/app')); * </pre> @@ -124,7 +125,7 @@ public final class ResourceMatchers { /** * Matches resources with a resource type set to the specified {@code resourceType} or one of its sub types. * In order to check for exact resource types only use {@link #resourceType(String)}. - * + * * <pre> * assertThat(resource, resourceTypeOrDerived('my/app')); * </pre> @@ -140,54 +141,54 @@ public final class ResourceMatchers { /** * Matches resources which has at least the specified {@code properties} defined with matching values - * + * * <p>Values not declared in the the {@code properties} 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 properties the properties to match * @return a matcher instance - */ + */ public static Matcher<Resource> props(Map<String, Object> properties) { return new ResourcePropertiesMatcher(properties); } /** * Matches resources which has at least the specified {@code properties} defined with matching values - * + * * <p>Values not declared in the the {@code properties} 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 properties the properties to match * @return a matcher instance - */ + */ public static Matcher<Resource> props(Object... properties) { return props(MapUtil.toMap(properties)); } /** * Matches resources which has the given name and at least the specified {@code properties} defined with matching values - * + * * <p>Values not declared in the the {@code properties} 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 name the expected name of the resource * @param properties the properties to match * @return a matcher instance @@ -198,16 +199,16 @@ public final class ResourceMatchers { /** * Matches resources which has the given name and at least the specified {@code properties} defined with matching values - * + * * <p>Values not declared in the the {@code properties} 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 name the expected name of the resource * @param properties the properties to match * @return a matcher instance 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 2b57af2..126fb39 100644 --- a/src/main/java/org/apache/sling/hamcrest/matchers/ResourceChildrenMatcher.java +++ b/src/main/java/org/apache/sling/hamcrest/matchers/ResourceChildrenMatcher.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.hamcrest.matchers; @@ -32,11 +34,12 @@ import org.hamcrest.TypeSafeMatcher; */ public class ResourceChildrenMatcher extends TypeSafeMatcher<Resource> { - // this should be "Iterable<? extends Resource>" instead of "?" but cannot until https://github.com/hamcrest/JavaHamcrest/issues/107 is solved + // 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 ResourceChildrenMatcher(List<String> childNames, boolean exactMatch, boolean validateOrder) { - if ( childNames == null || childNames.isEmpty() ) { + if (childNames == null || childNames.isEmpty()) { throw new IllegalArgumentException("childNames is null or empty"); } @@ -53,10 +56,12 @@ public class ResourceChildrenMatcher extends TypeSafeMatcher<Resource> { if (validateOrder) { this.iterarableMatcher = org.hamcrest.collection.IsIterableContainingInOrder.contains(resourceMatchers); } else { - this.iterarableMatcher = org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder(resourceMatchers); + this.iterarableMatcher = + org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder(resourceMatchers); } } else { - this.iterarableMatcher = org.hamcrest.core.IsIterableContaining.hasItems(resourceMatchers.toArray(new ResourceNameMatcher[0])); + this.iterarableMatcher = org.hamcrest.core.IsIterableContaining.hasItems( + resourceMatchers.toArray(new ResourceNameMatcher[0])); } } @@ -76,5 +81,4 @@ public class ResourceChildrenMatcher extends TypeSafeMatcher<Resource> { // use the iterable matcher here instead iterarableMatcher.describeMismatch(item.getChildren(), mismatchDescription); } - -} \ No newline at end of file +} diff --git a/src/main/java/org/apache/sling/hamcrest/matchers/ResourceCollectionPathMatcher.java b/src/main/java/org/apache/sling/hamcrest/matchers/ResourceCollectionPathMatcher.java index ecdf75e..c984df0 100644 --- a/src/main/java/org/apache/sling/hamcrest/matchers/ResourceCollectionPathMatcher.java +++ b/src/main/java/org/apache/sling/hamcrest/matchers/ResourceCollectionPathMatcher.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.hamcrest.matchers; @@ -30,11 +32,12 @@ import org.hamcrest.TypeSafeMatcher; */ 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 + // 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 ResourceCollectionPathMatcher(List<String> paths) { - if ( paths == null || paths.isEmpty() ) { + if (paths == null || paths.isEmpty()) { throw new IllegalArgumentException("names is null or empty"); } @@ -60,5 +63,4 @@ public class ResourceCollectionPathMatcher extends TypeSafeMatcher<Collection<Re protected void describeMismatchSafely(Collection<Resource> items, Description mismatchDescription) { iterarableMatcher.describeMismatch(items, mismatchDescription); } - } diff --git a/src/main/java/org/apache/sling/hamcrest/matchers/ResourceIteratorPathMatcher.java b/src/main/java/org/apache/sling/hamcrest/matchers/ResourceIteratorPathMatcher.java index 16dfa79..6c1d877 100644 --- a/src/main/java/org/apache/sling/hamcrest/matchers/ResourceIteratorPathMatcher.java +++ b/src/main/java/org/apache/sling/hamcrest/matchers/ResourceIteratorPathMatcher.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.hamcrest.matchers; @@ -30,11 +32,12 @@ import org.hamcrest.TypeSafeMatcher; */ 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 + // 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 ResourceIteratorPathMatcher(List<String> paths) { - if ( paths == null || paths.isEmpty() ) { + if (paths == null || paths.isEmpty()) { throw new IllegalArgumentException("names is null or empty"); } @@ -60,7 +63,7 @@ public class ResourceIteratorPathMatcher extends TypeSafeMatcher<Iterator<Resour protected void describeMismatchSafely(Iterator<Resource> items, Description mismatchDescription) { iterarableMatcher.describeMismatch(toList(items), mismatchDescription); } - + private List<Resource> toList(Iterator<Resource> items) { List<Resource> list = new ArrayList<Resource>(); while (items.hasNext()) { @@ -68,5 +71,4 @@ public class ResourceIteratorPathMatcher extends TypeSafeMatcher<Iterator<Resour } return list; } - } diff --git a/src/main/java/org/apache/sling/hamcrest/matchers/ResourceNameMatcher.java b/src/main/java/org/apache/sling/hamcrest/matchers/ResourceNameMatcher.java index c67331a..1ccd6e7 100644 --- a/src/main/java/org/apache/sling/hamcrest/matchers/ResourceNameMatcher.java +++ b/src/main/java/org/apache/sling/hamcrest/matchers/ResourceNameMatcher.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.hamcrest.matchers; @@ -44,6 +46,11 @@ public class ResourceNameMatcher extends TypeSafeMatcher<Resource> { @Override protected void describeMismatchSafely(Resource resource, Description mismatchDescription) { - mismatchDescription.appendText("was Resource with name ").appendValue(resource.getName()).appendText(" (resource: ").appendValue(resource).appendText(")"); + mismatchDescription + .appendText("was Resource with name ") + .appendValue(resource.getName()) + .appendText(" (resource: ") + .appendValue(resource) + .appendText(")"); } } diff --git a/src/main/java/org/apache/sling/hamcrest/matchers/ResourcePathMatcher.java b/src/main/java/org/apache/sling/hamcrest/matchers/ResourcePathMatcher.java index f76cb70..a12be1c 100644 --- a/src/main/java/org/apache/sling/hamcrest/matchers/ResourcePathMatcher.java +++ b/src/main/java/org/apache/sling/hamcrest/matchers/ResourcePathMatcher.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.hamcrest.matchers; @@ -43,7 +45,11 @@ public class ResourcePathMatcher extends TypeSafeMatcher<Resource> { @Override protected void describeMismatchSafely(Resource resource, Description mismatchDescription) { - mismatchDescription.appendText("was Resource with path ").appendValue(resource.getPath()).appendText(" (resource: ").appendValue(resource).appendText(")"); + mismatchDescription + .appendText("was Resource with path ") + .appendValue(resource.getPath()) + .appendText(" (resource: ") + .appendValue(resource) + .appendText(")"); } - } diff --git a/src/main/java/org/apache/sling/hamcrest/matchers/ResourcePropertiesMatcher.java b/src/main/java/org/apache/sling/hamcrest/matchers/ResourcePropertiesMatcher.java index 461e449..7f3a26f 100644 --- a/src/main/java/org/apache/sling/hamcrest/matchers/ResourcePropertiesMatcher.java +++ b/src/main/java/org/apache/sling/hamcrest/matchers/ResourcePropertiesMatcher.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.hamcrest.matchers; @@ -41,8 +43,10 @@ public class ResourcePropertiesMatcher extends TypeSafeMatcher<Resource> { @Override public void describeTo(Description description) { - description.appendText("Resource with properties ") - .appendValueList("[", ",", "]", convertArraysToStrings(expectedProps).entrySet()); + description + .appendText("Resource with properties ") + .appendValueList( + "[", ",", "]", convertArraysToStrings(expectedProps).entrySet()); } @Override @@ -51,14 +55,15 @@ public class ResourcePropertiesMatcher extends TypeSafeMatcher<Resource> { for (Map.Entry<String, Object> prop : expectedProps.entrySet()) { Object givenValue = givenProps.get(prop.getKey()); Object expectedValue = prop.getValue(); - if (givenValue != null && expectedValue != null - && givenValue.getClass().isArray() && expectedValue.getClass().isArray()) { + if (givenValue != null + && expectedValue != null + && givenValue.getClass().isArray() + && expectedValue.getClass().isArray()) { if (!arrayEquals(expectedValue, givenValue)) { firstMismatchPropertyName = prop.getKey(); return false; } - } - else { + } else { if (!objectEquals(expectedValue, givenValue)) { firstMismatchPropertyName = prop.getKey(); return false; @@ -67,26 +72,24 @@ public class ResourcePropertiesMatcher extends TypeSafeMatcher<Resource> { } return true; } - + private boolean objectEquals(Object value1, Object value2) { if (value1 == null) { return (value2 == null); - } - else if (value2 == null) { + } else if (value2 == null) { return (value1 == null); - } - else { + } else { return value1.equals(value2); } } - + private boolean arrayEquals(Object array1, Object array2) { int length1 = Array.getLength(array1); int length2 = Array.getLength(array2); if (length1 != length2) { return false; } - for (int i=0; i<length1; i++) { + for (int i = 0; i < length1; i++) { if (!objectEquals(Array.get(array1, i), Array.get(array2, i))) { return false; } @@ -97,18 +100,21 @@ public class ResourcePropertiesMatcher extends TypeSafeMatcher<Resource> { @Override protected void describeMismatchSafely(Resource item, Description mismatchDescription) { Map<String, Object> actualProperties = item.getValueMap(); - mismatchDescription.appendText("was Resource with properties ") - .appendValueList("[", ",", "]", convertArraysToStrings(actualProperties).entrySet()) - .appendText(" (resource: ") - .appendValue(item) - .appendText(")"); + mismatchDescription + .appendText("was Resource with properties ") + .appendValueList( + "[", ",", "]", convertArraysToStrings(actualProperties).entrySet()) + .appendText(" (resource: ") + .appendValue(item) + .appendText(")"); if (firstMismatchPropertyName != null) { Object expectedValue = expectedProps.get(firstMismatchPropertyName); Object actualValue = actualProperties.get(firstMismatchPropertyName); mismatchDescription.appendText(System.lineSeparator()); - mismatchDescription.appendText(" First mismatch in property ") - .appendValue(firstMismatchPropertyName) - .appendText(": expected "); + mismatchDescription + .appendText(" First mismatch in property ") + .appendValue(firstMismatchPropertyName) + .appendText(": expected "); appendValueAndType(mismatchDescription, expectedValue); mismatchDescription.appendText(" but was "); appendValueAndType(mismatchDescription, actualValue); @@ -119,10 +125,11 @@ public class ResourcePropertiesMatcher extends TypeSafeMatcher<Resource> { if (value == null) { mismatchDescription.appendText("null"); } else { - mismatchDescription.appendText("value ") - .appendValue(value) - .appendText(" of type ") - .appendValue(value.getClass().getName()); + mismatchDescription + .appendText("value ") + .appendValue(value) + .appendText(" of type ") + .appendValue(value.getClass().getName()); } } @@ -131,22 +138,21 @@ public class ResourcePropertiesMatcher extends TypeSafeMatcher<Resource> { * @param props Properties * @return Properties with array values converted to strings */ - private Map<String,Object> convertArraysToStrings(Map<String,Object> props) { - SortedMap<String,Object> transformedProps = new TreeMap<String,Object>(); + private Map<String, Object> convertArraysToStrings(Map<String, Object> props) { + SortedMap<String, Object> transformedProps = new TreeMap<String, Object>(); for (Map.Entry<String, Object> entry : props.entrySet()) { Object value = entry.getValue(); if (value != null && value.getClass().isArray()) { StringBuilder sb = new StringBuilder(); sb.append("["); - for (int i=0; i<Array.getLength(value); i++) { + for (int i = 0; i < Array.getLength(value); i++) { if (i > 0) { sb.append(","); } Object item = Array.get(value, i); if (item == null) { sb.append("null"); - } - else { + } else { sb.append(item.toString()); } } @@ -157,5 +163,4 @@ public class ResourcePropertiesMatcher extends TypeSafeMatcher<Resource> { } return transformedProps; } - -} \ No newline at end of file +} diff --git a/src/main/java/org/apache/sling/hamcrest/matchers/ResourceTypeMatcher.java b/src/main/java/org/apache/sling/hamcrest/matchers/ResourceTypeMatcher.java index 0d239c4..9ee0f05 100644 --- a/src/main/java/org/apache/sling/hamcrest/matchers/ResourceTypeMatcher.java +++ b/src/main/java/org/apache/sling/hamcrest/matchers/ResourceTypeMatcher.java @@ -1,18 +1,20 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.hamcrest.matchers; @@ -49,7 +51,11 @@ public class ResourceTypeMatcher extends TypeSafeMatcher<Resource> { @Override protected void describeMismatchSafely(Resource resource, Description mismatchDescription) { - mismatchDescription.appendText("was Resource with type ").appendValue(resource.getResourceType()).appendText(" (resource: ").appendValue(resource).appendText(")"); + mismatchDescription + .appendText("was Resource with type ") + .appendValue(resource.getResourceType()) + .appendText(" (resource: ") + .appendValue(resource) + .appendText(")"); } - } diff --git a/src/test/java/org/apache/sling/hamcrest/MapUtilTest.java b/src/test/java/org/apache/sling/hamcrest/MapUtilTest.java index 6ea1a34..a7e0427 100644 --- a/src/test/java/org/apache/sling/hamcrest/MapUtilTest.java +++ b/src/test/java/org/apache/sling/hamcrest/MapUtilTest.java @@ -18,53 +18,52 @@ */ package org.apache.sling.hamcrest; -import static org.junit.Assert.assertEquals; - import java.util.Collections; import java.util.Map; +import com.google.common.collect.ImmutableMap; import org.junit.Test; -import com.google.common.collect.ImmutableMap; +import static org.junit.Assert.assertEquals; public class MapUtilTest { - private static final ImmutableMap<String, Object> EXPECTED_MAP = ImmutableMap.<String, Object>of("param1", "var1", "param2", 123, "param3", true); + private static final ImmutableMap<String, Object> EXPECTED_MAP = + ImmutableMap.<String, Object>of("param1", "var1", "param2", 123, "param3", true); - @Test + @Test public void testMapObjectVarargs() { Map<String, Object> convertedMap = MapUtil.toMap("param1", "var1", "param2", 123, "param3", true); - + assertEquals(EXPECTED_MAP, convertedMap); } - + @Test public void testMapObjectMap() { Map<String, Object> convertedMap = MapUtil.toMap(EXPECTED_MAP); - + assertEquals(EXPECTED_MAP, convertedMap); } - @Test(expected = IllegalArgumentException.class) public void testMapObjectVarArgs_NotMap() { MapUtil.toMap("param1", "var1", "param2", 123, "param3"); } - + @Test public void testMapObjectVarargs_EmptyArgs() { Map<String, Object> convertedMap = MapUtil.toMap(); - + assertEquals(Collections.emptyMap(), convertedMap); } - + @Test public void testMapObjectVarargs_Null() { - Map<String, Object> convertedMap = MapUtil.toMap((Object[])null); - + Map<String, Object> convertedMap = MapUtil.toMap((Object[]) null); + assertEquals(Collections.emptyMap(), convertedMap); } - + @Test(expected = IllegalArgumentException.class) public void testMapObjectVarArgs_OddNumberOfArgs() { MapUtil.toMap("param1", "var1", "param2", 123, "param3"); diff --git a/src/test/java/org/apache/sling/hamcrest/ResourceCollectionMatchersTest.java b/src/test/java/org/apache/sling/hamcrest/ResourceCollectionMatchersTest.java index 4d7f35a..ce5cb83 100644 --- a/src/test/java/org/apache/sling/hamcrest/ResourceCollectionMatchersTest.java +++ b/src/test/java/org/apache/sling/hamcrest/ResourceCollectionMatchersTest.java @@ -18,61 +18,42 @@ */ package org.apache.sling.hamcrest; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.MatcherAssert.assertThat; - import java.util.List; +import com.google.common.collect.ImmutableList; import org.apache.sling.api.resource.Resource; import org.apache.sling.testing.mock.sling.junit.SlingContext; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import com.google.common.collect.ImmutableList; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.not; public class ResourceCollectionMatchersTest { @Rule public final SlingContext context = new SlingContext(); - + private List<Resource> list; - + @Before public void setUp() { list = ImmutableList.of( context.create().resource("/content/1"), context.create().resource("/content/2"), - context.create().resource("/content/3") - ); + context.create().resource("/content/3")); } - + @Test public void testMatch() { - assertThat(list, ResourceCollectionMatchers.paths( - "/content/1", - "/content/2", - "/content/3" - )); + assertThat(list, ResourceCollectionMatchers.paths("/content/1", "/content/2", "/content/3")); } @Test public void testMisMatch() { - assertThat(list, not(ResourceCollectionMatchers.paths( - "/content/1", - "/content/2", - "/content/3", - "/content/4" - ))); - assertThat(list, not(ResourceCollectionMatchers.paths( - "/content/1", - "/content/2" - ))); - assertThat(list, not(ResourceCollectionMatchers.paths( - "/content/1", - "/content/3", - "/content/2" - ))); + assertThat(list, not(ResourceCollectionMatchers.paths("/content/1", "/content/2", "/content/3", "/content/4"))); + assertThat(list, not(ResourceCollectionMatchers.paths("/content/1", "/content/2"))); + assertThat(list, not(ResourceCollectionMatchers.paths("/content/1", "/content/3", "/content/2"))); } - } diff --git a/src/test/java/org/apache/sling/hamcrest/ResourceIteratorMatchersTest.java b/src/test/java/org/apache/sling/hamcrest/ResourceIteratorMatchersTest.java index b1c54d4..e7bf476 100644 --- a/src/test/java/org/apache/sling/hamcrest/ResourceIteratorMatchersTest.java +++ b/src/test/java/org/apache/sling/hamcrest/ResourceIteratorMatchersTest.java @@ -18,61 +18,44 @@ */ package org.apache.sling.hamcrest; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.MatcherAssert.assertThat; - import java.util.List; +import com.google.common.collect.ImmutableList; import org.apache.sling.api.resource.Resource; import org.apache.sling.testing.mock.sling.junit.SlingContext; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import com.google.common.collect.ImmutableList; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.not; public class ResourceIteratorMatchersTest { @Rule public final SlingContext context = new SlingContext(); - + private List<Resource> list; - + @Before public void setUp() { list = ImmutableList.of( context.create().resource("/content/1"), context.create().resource("/content/2"), - context.create().resource("/content/3") - ); + context.create().resource("/content/3")); } - + @Test public void testMatch() { - assertThat(list.iterator(), ResourceIteratorMatchers.paths( - "/content/1", - "/content/2", - "/content/3" - )); + assertThat(list.iterator(), ResourceIteratorMatchers.paths("/content/1", "/content/2", "/content/3")); } @Test public void testMisMatch() { - assertThat(list.iterator(), not(ResourceIteratorMatchers.paths( - "/content/1", - "/content/2", - "/content/3", - "/content/4" - ))); - assertThat(list.iterator(), not(ResourceIteratorMatchers.paths( - "/content/1", - "/content/2" - ))); - assertThat(list.iterator(), not(ResourceIteratorMatchers.paths( - "/content/1", - "/content/3", - "/content/2" - ))); + assertThat( + list.iterator(), + not(ResourceIteratorMatchers.paths("/content/1", "/content/2", "/content/3", "/content/4"))); + assertThat(list.iterator(), not(ResourceIteratorMatchers.paths("/content/1", "/content/2"))); + assertThat(list.iterator(), not(ResourceIteratorMatchers.paths("/content/1", "/content/3", "/content/2"))); } - } diff --git a/src/test/java/org/apache/sling/hamcrest/ResourceMatchersTest.java b/src/test/java/org/apache/sling/hamcrest/ResourceMatchersTest.java index f65ccfe..c84bc5f 100644 --- a/src/test/java/org/apache/sling/hamcrest/ResourceMatchersTest.java +++ b/src/test/java/org/apache/sling/hamcrest/ResourceMatchersTest.java @@ -1,25 +1,26 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.apache.sling.hamcrest; -import static org.hamcrest.MatcherAssert.assertThat; - import java.util.Map; +import com.google.common.collect.ImmutableMap; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.SyntheticResource; @@ -28,7 +29,7 @@ import org.hamcrest.Matchers; import org.junit.Rule; import org.junit.Test; -import com.google.common.collect.ImmutableMap; +import static org.hamcrest.MatcherAssert.assertThat; public class ResourceMatchersTest { @@ -40,34 +41,43 @@ public class ResourceMatchersTest { @Test public void testResourceType() { - context.build().resource("/resource", - ResourceResolver.PROPERTY_RESOURCE_TYPE, "some/type", - "some other key", "some other value"); - + context.build() + .resource( + "/resource", + ResourceResolver.PROPERTY_RESOURCE_TYPE, + "some/type", + "some other key", + "some other value"); + Resource resource = context.resourceResolver().getResource("/resource"); assertThat(resource, ResourceMatchers.resourceType("some/type")); assertThat(resource, Matchers.not(ResourceMatchers.resourceType("some/other/type"))); - SyntheticResource syntheticResource = new SyntheticResource( - context.resourceResolver(), "/synthetic", "some/type"); + SyntheticResource syntheticResource = + new SyntheticResource(context.resourceResolver(), "/synthetic", "some/type"); assertThat(syntheticResource, ResourceMatchers.resourceType("some/type")); assertThat(syntheticResource, Matchers.not(ResourceMatchers.resourceType("some/other/type"))); } @Test public void testResourceTypeOrDerived() { - context.build().resource("/resource", - ResourceResolver.PROPERTY_RESOURCE_TYPE, "some/type", - PROPERTY_RESOURCE_SUPER_TYPE, "some/base/type", - "some other key", "some other value"); - + context.build() + .resource( + "/resource", + ResourceResolver.PROPERTY_RESOURCE_TYPE, + "some/type", + PROPERTY_RESOURCE_SUPER_TYPE, + "some/base/type", + "some other key", + "some other value"); + Resource resource = context.resourceResolver().getResource("/resource"); assertThat(resource, ResourceMatchers.resourceTypeOrDerived("some/type")); assertThat(resource, ResourceMatchers.resourceTypeOrDerived("some/base/type")); assertThat(resource, Matchers.not(ResourceMatchers.resourceTypeOrDerived("some/other/type"))); - SyntheticResource syntheticResource = new SyntheticResource( - context.resourceResolver(), "/synthetic", "some/type"); + SyntheticResource syntheticResource = + new SyntheticResource(context.resourceResolver(), "/synthetic", "some/type"); assertThat(syntheticResource, ResourceMatchers.resourceType("some/type")); assertThat(syntheticResource, Matchers.not(ResourceMatchers.resourceType("some/other/type"))); } @@ -75,7 +85,7 @@ public class ResourceMatchersTest { @Test public void testPath() { context.build().resource("/resource"); - + Resource resource = context.resourceResolver().getResource("/resource"); assertThat(resource, ResourceMatchers.path("/resource")); assertThat(resource, Matchers.not(ResourceMatchers.path("some/other/name"))); @@ -84,7 +94,7 @@ public class ResourceMatchersTest { @Test public void testName() { context.build().resource("/resource"); - + Resource resource = context.resourceResolver().getResource("/resource"); assertThat(resource, ResourceMatchers.name("resource")); assertThat(resource, Matchers.not(ResourceMatchers.name("some/other/name"))); @@ -92,112 +102,92 @@ public class ResourceMatchersTest { @Test public void testProps() { - context.build().resource("/resource", - "key1", "value1", - "key2", 123, - "key3", new String[] { "item1", "item2" }, - "key4", "otherValue"); - + context.build() + .resource( + "/resource", + "key1", + "value1", + "key2", + 123, + "key3", + new String[] {"item1", "item2"}, + "key4", + "otherValue"); + Map<String, Object> expectedProperties = ImmutableMap.<String, Object>builder() .put("key1", "value1") .put("key2", 123) - .put("key3", new String[] { "item1", "item2" }) + .put("key3", new String[] {"item1", "item2"}) .build(); - + Resource resource = context.resourceResolver().getResource("/resource"); assertThat(resource, ResourceMatchers.props(expectedProperties)); - + // test existing key with not matching value expectedProperties = ImmutableMap.<String, Object>builder() .put("key1", "value1") .put("key3", "value3") .build(); assertThat(resource, Matchers.not(ResourceMatchers.props(expectedProperties))); - + // test non-existing key - expectedProperties = ImmutableMap.<String, Object>builder() - .put("key5", "value5") - .build(); + expectedProperties = + ImmutableMap.<String, Object>builder().put("key5", "value5").build(); assertThat(resource, Matchers.not(ResourceMatchers.props(expectedProperties))); } @Test public void testPropsVarargs() { - context.build().resource("/resource", - "key1", "value1", - "key2", true, - "key3", new int[] { 1, 2, 3 }, - "key4", "otherValue"); - - Object[] expectedProperties = new Object[] { - "key1", "value1", - "key2", true, - "key3", new int[] { 1, 2, 3 } - }; - + context.build() + .resource( + "/resource", "key1", "value1", "key2", true, "key3", new int[] {1, 2, 3}, "key4", "otherValue"); + + Object[] expectedProperties = new Object[] {"key1", "value1", "key2", true, "key3", new int[] {1, 2, 3}}; + Resource resource = context.resourceResolver().getResource("/resource"); assertThat(resource, ResourceMatchers.props(expectedProperties)); // test existing key with not matching value - expectedProperties = new Object[] { - "key1", "value1", - "key3", new int[] { 1, 2, 5 } - }; + expectedProperties = new Object[] {"key1", "value1", "key3", new int[] {1, 2, 5}}; assertThat(resource, Matchers.not(ResourceMatchers.props(expectedProperties))); - expectedProperties = new Object[] { - "key1", "value1", - "key3", new int[] { 1, 2 } - }; + expectedProperties = new Object[] {"key1", "value1", "key3", new int[] {1, 2}}; assertThat(resource, Matchers.not(ResourceMatchers.props(expectedProperties))); - - expectedProperties = new Object[] { - "key1", "value1", - "key3", 1 - }; + + expectedProperties = new Object[] {"key1", "value1", "key3", 1}; assertThat(resource, Matchers.not(ResourceMatchers.props(expectedProperties))); - - expectedProperties = new Object[] { - "key1", "value1", - "key3", null - }; + + expectedProperties = new Object[] {"key1", "value1", "key3", null}; assertThat(resource, Matchers.not(ResourceMatchers.props(expectedProperties))); - + // test non-existing key - expectedProperties = new Object[] { - "key5", "value5" - }; + expectedProperties = new Object[] {"key5", "value5"}; assertThat(resource, Matchers.not(ResourceMatchers.props(expectedProperties))); } @Test public void testHasChildren() { - context.build() - .resource("/parent").resource("child1") - .resource("/parent/child2"); - + context.build().resource("/parent").resource("child1").resource("/parent/child2"); + Resource resource = context.resourceResolver().getResource("/parent"); assertThat(resource, ResourceMatchers.hasChildren("child1")); } - + @Test public void testNameAndProps() { - context.build().resource("/resource", - "key1", "value1", - "key2", new String[] { "item1" }, - "key3", "value3"); - + context.build().resource("/resource", "key1", "value1", "key2", new String[] {"item1"}, "key3", "value3"); + Map<String, Object> expectedProperties = ImmutableMap.<String, Object>builder() .put("key1", "value1") - .put("key2", new String[] { "item1" }) + .put("key2", new String[] {"item1"}) .build(); - + Resource resource = context.resourceResolver().getResource("/resource"); assertThat(resource, ResourceMatchers.nameAndProps("resource", expectedProperties)); - + // test not matching name assertThat(resource, Matchers.not(ResourceMatchers.nameAndProps("resource1", expectedProperties))); - + // test existing key with not matching value expectedProperties = ImmutableMap.<String, Object>builder() .put("key1", "value1") @@ -208,36 +198,31 @@ public class ResourceMatchersTest { @Test public void testNameAndPropsVarargs() { - context.build().resource("/resource", - "key1", "value1", - "key2", "value2", - "key3", "value3"); - + context.build().resource("/resource", "key1", "value1", "key2", "value2", "key3", "value3"); + Object[] expectedProperties = new Object[] { - "key1", "value1", - "key2", "value2" + "key1", "value1", + "key2", "value2" }; - + Resource resource = context.resourceResolver().getResource("/resource"); assertThat(resource, ResourceMatchers.nameAndProps("resource", expectedProperties)); - + // test not matching name assertThat(resource, Matchers.not(ResourceMatchers.nameAndProps("resource1", expectedProperties))); - + // test existing key with not matching value expectedProperties = new Object[] { - "key1", "value1", - "key2", "value3" + "key1", "value1", + "key2", "value3" }; assertThat(resource, Matchers.not(ResourceMatchers.nameAndProps("resource", expectedProperties))); } @Test public void testContainsChildrenInAnyOrder() { - context.build() - .resource("/parent").resource("child1") - .resource("/parent/child2"); - + context.build().resource("/parent").resource("child1").resource("/parent/child2"); + Resource resource = context.resourceResolver().getResource("/parent"); assertThat(resource, ResourceMatchers.containsChildrenInAnyOrder("child2", "child1")); assertThat(resource, ResourceMatchers.containsChildrenInAnyOrder("child1", "child2")); @@ -246,14 +231,11 @@ public class ResourceMatchersTest { @Test public void testContainsChildren() { - context.build() - .resource("/parent").resource("child1") - .resource("/parent/child2"); - + context.build().resource("/parent").resource("child1").resource("/parent/child2"); + Resource resource = context.resourceResolver().getResource("/parent"); assertThat(resource, ResourceMatchers.containsChildren("child1", "child2")); assertThat(resource, Matchers.not(ResourceMatchers.containsChildren("child2", "child1"))); assertThat(resource, Matchers.not(ResourceMatchers.containsChildren("child1", "child2", "child3"))); } - }
