SLING-5881 jcr-mock: Dummy implementations for unsupported operations of MockObservationManager

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1753652 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/testing/mock/jcr/MockEventListenerIterator.java b/src/main/java/org/apache/sling/testing/mock/jcr/MockEventListenerIterator.java
new file mode 100644
index 0000000..a051643
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/mock/jcr/MockEventListenerIterator.java
@@ -0,0 +1,39 @@
+/*
+ * 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
+ *
+ * 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.testing.mock.jcr;
+
+import java.util.Collection;
+
+import javax.jcr.observation.EventListener;
+import javax.jcr.observation.EventListenerIterator;
+
+import org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter;
+
+class MockEventListenerIterator extends RangeIteratorAdapter implements EventListenerIterator {
+    
+    public MockEventListenerIterator(Collection collection) {
+        super(collection);
+    }
+
+    @Override
+    public EventListener nextEventListener() {
+        return (EventListener)this.next();
+    }
+
+}
diff --git a/src/main/java/org/apache/sling/testing/mock/jcr/MockObservationManager.java b/src/main/java/org/apache/sling/testing/mock/jcr/MockObservationManager.java
index b1ea937..f2cbe5f 100644
--- a/src/main/java/org/apache/sling/testing/mock/jcr/MockObservationManager.java
+++ b/src/main/java/org/apache/sling/testing/mock/jcr/MockObservationManager.java
@@ -18,6 +18,8 @@
  */
 package org.apache.sling.testing.mock.jcr;
 
+import java.util.Collections;
+
 import javax.jcr.RepositoryException;
 import javax.jcr.observation.EventJournal;
 import javax.jcr.observation.EventListener;
@@ -41,26 +43,27 @@
         // do nothing
     }
 
-    // --- unsupported operations ---
     @Override
     public EventListenerIterator getRegisteredEventListeners() throws RepositoryException {
-        throw new UnsupportedOperationException();
+        return new MockEventListenerIterator(Collections.emptyList());
     }
 
     @Override
     public void setUserData(final String userData) throws RepositoryException {
-        throw new UnsupportedOperationException();
+        // accept call but ignore it
     }
 
     @Override
     public EventJournal getEventJournal() throws RepositoryException {
-        throw new UnsupportedOperationException();
+        // always return null
+        return null;
     }
 
     @Override
     public EventJournal getEventJournal(final int eventTypes, final String absPath, final boolean isDeep,
             final String[] uuid, final String[] nodeTypeName) throws RepositoryException {
-        throw new UnsupportedOperationException();
+        // always return null
+        return null;
     }
 
 }
diff --git a/src/test/java/org/apache/sling/testing/mock/jcr/MockWorkspaceTest.java b/src/test/java/org/apache/sling/testing/mock/jcr/MockWorkspaceTest.java
index 662a623..cd4830e 100644
--- a/src/test/java/org/apache/sling/testing/mock/jcr/MockWorkspaceTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/jcr/MockWorkspaceTest.java
@@ -19,7 +19,9 @@
 package org.apache.sling.testing.mock.jcr;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Workspace;
@@ -49,11 +51,14 @@
 
     @Test
     public void testObservationManager() throws RepositoryException {
-        // just mage sure listener methods can be called, although they do
-        // nothing
-        ObservationManager observationManager = underTest.getObservationManager();
-        observationManager.addEventListener(null, 0, null, false, null, null, false);
-        observationManager.removeEventListener(null);
+        // just make sure observation manager methods can be called, although they do nothing
+        ObservationManager mgr = underTest.getObservationManager();
+        mgr.addEventListener(null, 0, null, false, null, null, false);
+        mgr.removeEventListener(null);
+        assertFalse(mgr.getRegisteredEventListeners().hasNext());
+        mgr.setUserData("abc");
+        assertNull(mgr.getEventJournal());
+        assertNull(mgr.getEventJournal(0, "/any", true, null, null));
     }
 
     @Test