kwin commented on a change in pull request #2:
URL: 
https://github.com/apache/sling-org-apache-sling-testing-resourceresolver-mock/pull/2#discussion_r555373728



##########
File path: 
src/main/java/org/apache/sling/testing/resourceresolver/MockResourceResolver.java
##########
@@ -447,22 +451,46 @@ public Resource getParent(@NotNull Resource child) {
         return this.getResource(parentPath);
     }
 
+    @Override
+    @SuppressWarnings("null")
+    public @NotNull Iterator<Resource> findResources(final @NotNull String 
query, final String language) {
+        return findResourcesHandlers.stream()
+            .map(handler -> handler.findResources(query, language))
+            .filter(Objects::nonNull)
+            .findFirst()
+            .orElse(Collections.emptyIterator());
+    }
 
-    // --- unsupported operations ---
+    /**
+     * @param handler Handler that can provide a mocked find resources result.
+     */
+    public void addFindResourceHandler(@NotNull MockFindResourcesHandler 
handler) {
+        findResourcesHandlers.add(handler);
+    }
 
     @Override
-    @Deprecated
-    public @NotNull Resource resolve(final @NotNull HttpServletRequest 
request) {
-        throw new UnsupportedOperationException();
+    @SuppressWarnings("null")
+    public @NotNull Iterator<Map<String, Object>> queryResources(@NotNull 
String query, String language) {
+        return queryResourcesHandlers.stream()
+                .map(handler -> handler.queryResources(query, language))
+                .filter(Objects::nonNull)
+                .findFirst()
+                .orElse(Collections.emptyIterator());
     }
 
-    @Override
-    public @NotNull Iterator<Resource> findResources(final @NotNull String 
query, final String language) {
-        throw new UnsupportedOperationException();
+    /**
+     * @param handler Handler that can provide a mocked query resources result.
+     */
+    public void addQueryResourceHandler(@NotNull MockQueryResourceHandler 
handler) {

Review comment:
       It would be useful to add to javadoc that all handlers are queried until 
the first one returns a non-null value. And also that all registered handlers 
form a FIFO queue.

##########
File path: 
src/main/java/org/apache/sling/testing/resourceresolver/MockResourceResolver.java
##########
@@ -447,22 +451,46 @@ public Resource getParent(@NotNull Resource child) {
         return this.getResource(parentPath);
     }
 
+    @Override
+    @SuppressWarnings("null")
+    public @NotNull Iterator<Resource> findResources(final @NotNull String 
query, final String language) {
+        return findResourcesHandlers.stream()
+            .map(handler -> handler.findResources(query, language))
+            .filter(Objects::nonNull)
+            .findFirst()
+            .orElse(Collections.emptyIterator());
+    }
 
-    // --- unsupported operations ---
+    /**
+     * @param handler Handler that can provide a mocked find resources result.
+     */

Review comment:
       It would be useful to add to javadoc that all handlers are queried until 
the first one returns a non-null value. And also that all registered handlers 
form a FIFO queue. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to