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 2017/11/07 09:39:07 UTC

[sling-org-apache-sling-fsresource] 04/07: SLING-6829 make unit tests independent of resource child order

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.fsresource-2.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git

commit 682d27e69b1ef8d5b5d965cb18a1c6f884b8d5bb
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Thu May 4 16:27:29 2017 +0000

    SLING-6829 make unit tests independent of resource child order
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/fsresource@1793831 13f79535-47bb-0310-9956-ffa450edef68
---
 .../fsprovider/internal/JcrXmlContentTest.java     |  6 ++--
 .../sling/fsprovider/internal/JsonContentTest.java |  6 ++--
 .../internal/ResourcePathComparator.java           | 32 ++++++++++++++++++++++
 3 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java b/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
index 5306566..cece206 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThat;
 
+import java.util.Collections;
 import java.util.List;
 
 import javax.jcr.Node;
@@ -43,7 +44,7 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
 
 /**
  * Test access to files and folders from file system.
@@ -152,7 +153,8 @@ public class JcrXmlContentTest {
     @Test
     public void testFolder3ChildNodes() throws RepositoryException {
         Resource folder3 = fsroot.getChild("folder3");
-        List<Resource> children = ImmutableList.copyOf(folder3.listChildren());
+        List<Resource> children = Lists.newArrayList(folder3.listChildren());
+        Collections.sort(children, new ResourcePathComparator());
         
         assertEquals(2, children.size());
         Resource child1 = children.get(0);
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java b/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
index b792f97..1046350 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
@@ -29,6 +29,7 @@ import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 import java.math.BigDecimal;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -53,8 +54,8 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
-import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
 
 /**
  * Test access to files and folders and JSON content from file system.
@@ -247,7 +248,8 @@ public class JsonContentTest {
     @Test
     public void testFolder2ChildNodes() throws RepositoryException {
         Resource folder2 = fsroot.getChild("folder2");
-        List<Resource> children = ImmutableList.copyOf(folder2.listChildren());
+        List<Resource> children = Lists.newArrayList(folder2.listChildren());
+        Collections.sort(children, new ResourcePathComparator());
         
         assertEquals(2, children.size());
         Resource child1 = children.get(0);
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/ResourcePathComparator.java b/src/test/java/org/apache/sling/fsprovider/internal/ResourcePathComparator.java
new file mode 100644
index 0000000..f1c6272
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/ResourcePathComparator.java
@@ -0,0 +1,32 @@
+/*
+ * 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.fsprovider.internal;
+
+import java.util.Comparator;
+
+import org.apache.sling.api.resource.Resource;
+
+class ResourcePathComparator implements Comparator<Resource> {
+
+    @Override
+    public int compare(Resource o1, Resource o2) {
+        return o1.getPath().compareTo(o2.getPath());
+    }
+
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.