You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/02/23 08:46:12 UTC

[isis] branch master updated: ISIS-2297: covers _Sets

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

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new c24682b  ISIS-2297: covers _Sets
c24682b is described below

commit c24682b9b58c3663637707dd95596da8e8332cc1
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sun Feb 23 09:45:58 2020 +0100

    ISIS-2297: covers _Sets
---
 .../core/commons/internal/collections/_Sets.java   |   6 +-
 .../core/commons/internal/collections/Samples.java |  86 +++++
 .../commons/internal/collections/_ArraysTest.java  |  33 +-
 .../commons/internal/collections/_SetsTest.java    | 390 +++++++++++++++++++++
 4 files changed, 481 insertions(+), 34 deletions(-)

diff --git a/core/commons/src/main/java/org/apache/isis/core/commons/internal/collections/_Sets.java b/core/commons/src/main/java/org/apache/isis/core/commons/internal/collections/_Sets.java
index 4662062..24d120a 100644
--- a/core/commons/src/main/java/org/apache/isis/core/commons/internal/collections/_Sets.java
+++ b/core/commons/src/main/java/org/apache/isis/core/commons/internal/collections/_Sets.java
@@ -45,6 +45,7 @@ import static org.apache.isis.core.commons.internal.functions._Predicates.not;
 
 import lombok.NonNull;
 import lombok.val;
+import lombok.experimental.UtilityClass;
 
 /**
  * <h1>- internal use only -</h1>
@@ -58,10 +59,9 @@ import lombok.val;
  *
  * @since 2.0
  */
+@UtilityClass
 public final class _Sets {
 
-    private _Sets(){}
-
     // -- UNMODIFIABLE SET
 
     /**
@@ -109,7 +109,7 @@ public final class _Sets {
             return Collections.emptySet();
         }
         return _NullSafe.stream(iterable)
-                .collect(toUnmodifiable());
+                .collect(toUnmodifiable(LinkedHashSet::new)); // preserve order
     }
 
     // -- TREE SET
diff --git a/core/commons/src/test/java/org/apache/isis/core/commons/internal/collections/Samples.java b/core/commons/src/test/java/org/apache/isis/core/commons/internal/collections/Samples.java
new file mode 100644
index 0000000..bf7bf94
--- /dev/null
+++ b/core/commons/src/test/java/org/apache/isis/core/commons/internal/collections/Samples.java
@@ -0,0 +1,86 @@
+/*
+ *  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.isis.core.commons.internal.collections;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import lombok.val;
+import lombok.experimental.UtilityClass;
+
+@UtilityClass
+class Samples {
+
+    static Iterable<Integer> iterable(final Integer ... elements) {
+        return new Iterable<Integer>() {
+        
+            @Override
+            public Iterator<Integer> iterator() {
+                return Arrays.asList(elements).iterator();
+            }
+        };
+    }
+
+    /**
+     * order matters
+     */
+    void assertListEquals(List<Integer> expected, Collection<Integer> actual) {
+        assertEquals(expected, new ArrayList<>(actual));
+    }
+
+    /**
+     * order is ignored
+     */
+    void assertSetEquals(Set<Integer> expected, Collection<Integer> actual) {
+        assertEquals(
+                new HashSet<Integer>(expected).removeAll(actual),
+                new HashSet<Integer>(actual).removeAll(expected));
+    }
+    
+    
+    @FunctionalInterface
+    interface IndexedBiConsumer<T, U> {
+        void accept(int i, int j, T t, U u);
+    }
+    
+    static class FiniteSpace2 {
+        
+        static void visit(
+                List<Integer[]> as, 
+                List<Integer[]> bs, 
+                IndexedBiConsumer<Integer[], Integer[]> probe) {
+            int i=0;
+            for(val a : as) {
+                int j=0;
+                for(val b : bs) {
+                    probe.accept(i, j++, a, b);
+                }
+                i++;
+            }
+        }
+    }
+    
+}
diff --git a/core/commons/src/test/java/org/apache/isis/core/commons/internal/collections/_ArraysTest.java b/core/commons/src/test/java/org/apache/isis/core/commons/internal/collections/_ArraysTest.java
index 780f5e2..c8d8010 100644
--- a/core/commons/src/test/java/org/apache/isis/core/commons/internal/collections/_ArraysTest.java
+++ b/core/commons/src/test/java/org/apache/isis/core/commons/internal/collections/_ArraysTest.java
@@ -20,7 +20,6 @@ package org.apache.isis.core.commons.internal.collections;
 
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
@@ -39,6 +38,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import org.apache.isis.core.commons.internal.base._NullSafe;
+import org.apache.isis.core.commons.internal.collections.Samples.FiniteSpace2;
 
 import lombok.val;
 
@@ -72,28 +72,6 @@ class _ArraysTest {
     void tearDown() throws Exception {
     }
 
-    @FunctionalInterface
-    public interface IndexedBiConsumer<T, U> {
-        void accept(int i, int j, T t, U u);
-    }
-    
-    static class FiniteSpace2 {
-        
-        static void visit(
-                List<Integer[]> as, 
-                List<Integer[]> bs, 
-                IndexedBiConsumer<Integer[], Integer[]> probe) {
-            int i=0;
-            for(val a : as) {
-                int j=0;
-                for(val b : bs) {
-                    probe.accept(i, j++, a, b);
-                }
-                i++;
-            }
-        }
-    }
-    
     
     /**
      * Test method for {@link org.apache.isis.core.commons.internal.collections._Arrays#testAnyMatch(T[], T[], java.util.function.BiPredicate)}.
@@ -291,15 +269,8 @@ class _ArraysTest {
     @Test
     void testToArrayIterableOfQextendsTClassOfT() {
         
-        val iterable = new Iterable<Integer>() {
-            @Override
-            public Iterator<Integer> iterator() {
-                return Arrays.asList(1,2,3).iterator();
-            }
-        };
-        
         assertArrayEquals( new Integer[] {1, 2, 3},
-                _Arrays.toArray(iterable, Integer.class) );
+                _Arrays.toArray(Samples.iterable(1, 2, 3), Integer.class) );
     }
 
     /**
diff --git a/core/commons/src/test/java/org/apache/isis/core/commons/internal/collections/_SetsTest.java b/core/commons/src/test/java/org/apache/isis/core/commons/internal/collections/_SetsTest.java
new file mode 100644
index 0000000..e49617d
--- /dev/null
+++ b/core/commons/src/test/java/org/apache/isis/core/commons/internal/collections/_SetsTest.java
@@ -0,0 +1,390 @@
+/**
+ * 
+ */
+package org.apache.isis.core.commons.internal.collections;
+
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.stream.Stream;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import lombok.val;
+
+/**
+ * @since Feb 23, 2020
+ *
+ */
+class _SetsTest {
+
+    /**
+     * @throws java.lang.Exception
+     */
+    @BeforeEach
+    void setUp() throws Exception {
+    }
+
+    /**
+     * @throws java.lang.Exception
+     */
+    @AfterEach
+    void tearDown() throws Exception {
+    }
+    
+    void assertUnmodifiable(Set<Integer> set) {
+        if(set.size()>0) {
+            assertThrows(Exception.class, ()->set.clear());
+            val iterator = set.iterator();
+            assertThrows(Exception.class, ()->{
+                iterator.next();
+                iterator.remove();
+            });
+            assertThrows(Exception.class, ()->set.remove(1));
+        }
+        assertThrows(Exception.class, ()->set.add(2));
+    }
+    
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#singleton(java.lang.Object)}.
+     */
+    @Test
+    void testSingleton() {
+        val set = _Sets.<Integer>singleton(1);
+        assertUnmodifiable(set);
+        assertEquals(1, set.size());
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#singletonOrElseEmpty(java.lang.Object)}.
+     */
+    @Test
+    void testSingletonOrElseEmpty() {
+        val set = _Sets.<Integer>singletonOrElseEmpty(1);
+        assertUnmodifiable(set);
+        assertEquals(1, set.size());
+        val emptySet = _Sets.<Integer>singletonOrElseEmpty(null);
+        assertUnmodifiable(emptySet);
+        assertEquals(0, emptySet.size());
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#of(T[])}.
+     */
+    @Test
+    void testOf() {
+        assertArrayEquals(new Integer[] {}, _Arrays.toArray(_Sets.of(), Integer.class)); 
+        assertArrayEquals(new Integer[] {0, 1, -1, 3}, _Arrays.toArray(_Sets.of(0, 1, -1, 3), Integer.class));
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#unmodifiable(java.lang.Iterable)}.
+     */
+    @Test
+    void testUnmodifiable() {
+        val set = _Sets.unmodifiable(Samples.iterable(3, 1, 2));
+        assertUnmodifiable(set);
+        Samples.assertListEquals(_Lists.of(3, 1, 2), set);
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#newTreeSet()}.
+     */
+    @Test
+    void testNewTreeSet() {
+        val set = _Sets.newTreeSet();
+        assertEquals(TreeSet.class, set.getClass());
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#newTreeSet(java.util.Comparator)}.
+     */
+    @Test
+    void testNewTreeSetComparatorOfT() {
+        val set = _Sets.newTreeSet(Integer::compare);
+        assertEquals(TreeSet.class, set.getClass());
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#newTreeSet(java.lang.Iterable)}.
+     */
+    @Test
+    void testNewTreeSetIterableOfT() {
+        val set = _Sets.newTreeSet(Samples.iterable(3, 1, 2));
+        assertEquals(TreeSet.class, set.getClass());
+        Samples.assertListEquals(_Lists.of(1, 2, 3), set);
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#newTreeSet(java.lang.Iterable, java.util.Comparator)}.
+     */
+    @Test
+    void testNewTreeSetIterableOfTComparatorOfT() {
+        val set = _Sets.newTreeSet(Samples.iterable(3, 1, 2), (a, b)->Integer.compare(b, a));
+        assertEquals(TreeSet.class, set.getClass());
+        Samples.assertListEquals(_Lists.of(3, 2, 1), set);
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#newHashSet()}.
+     */
+    @Test
+    void testNewHashSet() {
+        val set = _Sets.newHashSet();
+        assertEquals(HashSet.class, set.getClass());
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#newHashSet(java.util.Collection)}.
+     */
+    @Test
+    void testNewHashSetCollectionOfT() {
+        val set = _Sets.newHashSet(_Lists.of(3, 1, 2, 3, 3));
+        assertEquals(HashSet.class, set.getClass());
+        Samples.assertSetEquals(_Sets.of(1, 2, 3), set);
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#newHashSet(java.lang.Iterable)}.
+     */
+    @Test
+    void testNewHashSetIterableOfT() {
+        val set = _Sets.newHashSet(Samples.iterable(3, 1, 2, 3, 3));
+        assertEquals(HashSet.class, set.getClass());
+        Samples.assertSetEquals(_Sets.of(1, 2, 3), set);
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#newLinkedHashSet()}.
+     */
+    @Test
+    void testNewLinkedHashSet() {
+        val set = _Sets.newLinkedHashSet();
+        assertEquals(LinkedHashSet.class, set.getClass());
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#newLinkedHashSet(java.util.Collection)}.
+     */
+    @Test
+    void testNewLinkedHashSetCollectionOfT() {
+        val set = _Sets.newLinkedHashSet(_Lists.of(3, 1, 2, 3, 3));
+        assertEquals(LinkedHashSet.class, set.getClass());
+        Samples.assertListEquals(_Lists.of(3, 1, 2), set);
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#newLinkedHashSet(java.lang.Iterable)}.
+     */
+    @Test
+    void testNewLinkedHashSetIterableOfT() {
+        val set = _Sets.newLinkedHashSet(Samples.iterable(3, 1, 2, 3, 3));
+        assertEquals(LinkedHashSet.class, set.getClass());
+        Samples.assertListEquals(_Lists.of(3, 1, 2), set);
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#newConcurrentHashSet()}.
+     */
+    @Test
+    void testNewConcurrentHashSet() {
+        val set = _Sets.newConcurrentHashSet();
+        assertEquals(ConcurrentHashMap.KeySetView.class, set.getClass());
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#newConcurrentHashSet(java.util.Collection)}.
+     */
+    @Test
+    void testNewConcurrentHashSetCollectionOfT() {
+        val set = _Sets.newConcurrentHashSet(Samples.iterable(3, 1, 2, 3, 3));
+        assertEquals(ConcurrentHashMap.KeySetView.class, set.getClass());
+        Samples.assertSetEquals(_Sets.of(1, 2, 3), set);
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#newConcurrentHashSet(java.lang.Iterable)}.
+     */
+    @Test
+    void testNewConcurrentHashSetIterableOfT() {
+        val set = _Sets.newConcurrentHashSet(_Lists.of(3, 1, 2, 3, 3));
+        assertEquals(ConcurrentHashMap.KeySetView.class, set.getClass());
+        Samples.assertSetEquals(_Sets.of(1, 2, 3), set);
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#newCopyOnWriteArraySet()}.
+     */
+    @Test
+    void testNewCopyOnWriteArraySet() {
+        val set = _Sets.newCopyOnWriteArraySet();
+        assertEquals(CopyOnWriteArraySet.class, set.getClass());
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#newCopyOnWriteArraySet(java.util.Collection)}.
+     */
+    @Test
+    void testNewCopyOnWriteArraySetCollectionOfT() {
+        val set = _Sets.newCopyOnWriteArraySet(_Lists.of(3, 1, 2, 3, 3));
+        assertEquals(CopyOnWriteArraySet.class, set.getClass());
+        Samples.assertListEquals(_Lists.of(3, 1, 2), set);
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#newCopyOnWriteArraySet(java.lang.Iterable)}.
+     */
+    @Test
+    void testNewCopyOnWriteArraySetIterableOfT() {
+        val set = _Sets.newCopyOnWriteArraySet(Samples.iterable(3, 1, 2, 3, 3));
+        assertEquals(CopyOnWriteArraySet.class, set.getClass());
+        Samples.assertListEquals(_Lists.of(3, 1, 2), set);
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#intersect(java.util.Set, java.util.Set)}.
+     */
+    @Test
+    void testIntersect() {
+        Samples.assertSetEquals(_Sets.of(), _Sets.intersect(null, null));
+        Samples.assertSetEquals(_Sets.of(), _Sets.intersect(null, _Sets.of()));
+        Samples.assertSetEquals(_Sets.of(), _Sets.intersect(_Sets.of(), null));
+        Samples.assertSetEquals(_Sets.of(), _Sets.intersect(_Sets.of(), _Sets.of()));
+        Samples.assertSetEquals(_Sets.of(), _Sets.intersect(_Sets.of(0, 1), _Sets.of(2, 3)));
+        Samples.assertSetEquals(_Sets.of(1, 2), _Sets.intersect(_Sets.of(0, 1, 2), _Sets.of(1, 2, 3)));
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#intersectSorted(java.util.SortedSet, java.util.SortedSet)}.
+     */
+    @Test
+    void testIntersectSorted() {
+        Samples.assertListEquals(_Lists.of(), _Sets.intersectSorted(null, null));
+        Samples.assertListEquals(_Lists.of(), _Sets.intersectSorted(null, _Sets.newTreeSet(_Sets.of())));
+        Samples.assertListEquals(_Lists.of(), _Sets.intersectSorted(_Sets.newTreeSet(), null));
+        Samples.assertListEquals(_Lists.of(), _Sets.intersectSorted(_Sets.newTreeSet(), _Sets.newTreeSet()));
+        Samples.assertListEquals(_Lists.of(), _Sets.intersectSorted(_Sets.newTreeSet(_Sets.of(1, 0)), _Sets.newTreeSet(_Sets.of(3, 2))));
+        Samples.assertListEquals(_Lists.of(1, 2), _Sets.intersectSorted(_Sets.newTreeSet(_Sets.of(2, 0, 1)), _Sets.newTreeSet((_Sets.of(3, 1, 2)))));
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#minus(java.util.Set, java.util.Set)}.
+     */
+    @Test
+    void testMinusSetOfTSetOfT() {
+        Samples.assertSetEquals(_Sets.of(), _Sets.minus(null, null));
+        Samples.assertSetEquals(_Sets.of(), _Sets.minus(null, _Sets.of()));
+        Samples.assertSetEquals(_Sets.of(), _Sets.minus(_Sets.of(), null));
+        Samples.assertSetEquals(_Sets.of(), _Sets.minus(_Sets.of(), _Sets.of()));
+        Samples.assertSetEquals(_Sets.of(0, 1), _Sets.minus(_Sets.of(0, 1), _Sets.of(2, 3)));
+        Samples.assertSetEquals(_Sets.of(0), _Sets.minus(_Sets.of(0, 1, 2), _Sets.of(1, 2, 3)));
+
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#minusSorted(java.util.SortedSet, java.util.SortedSet)}.
+     */
+    @Test
+    void testMinusSortedSortedSetOfTSortedSetOfT() {
+        Samples.assertListEquals(_Lists.of(), _Sets.minusSorted(null, null));
+        Samples.assertListEquals(_Lists.of(), _Sets.minusSorted(null, _Sets.newTreeSet(_Sets.of())));
+        Samples.assertListEquals(_Lists.of(), _Sets.minusSorted(_Sets.newTreeSet(), null));
+        Samples.assertListEquals(_Lists.of(), _Sets.minusSorted(_Sets.newTreeSet(), _Sets.newTreeSet()));
+        Samples.assertListEquals(_Lists.of(0, 1), _Sets.minusSorted(_Sets.newTreeSet(_Sets.of(1, 0)), _Sets.newTreeSet(_Sets.of(3, 2))));
+        Samples.assertListEquals(_Lists.of(0), _Sets.minusSorted(_Sets.newTreeSet(_Sets.of(2, 0, 1)), _Sets.newTreeSet((_Sets.of(3, 1, 2)))));
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#minus(java.util.Set, java.util.Set, java.util.function.Supplier)}.
+     */
+    @Test
+    void testMinusSetOfTSetOfTSupplierOfSetOfT() {
+        val set = _Sets.<Integer>minus(null, null, TreeSet::new);
+        assertUnmodifiable(set);
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#minusSorted(java.util.SortedSet, java.util.SortedSet, java.util.function.Supplier)}.
+     */
+    @Test
+    void testMinusSortedSortedSetOfTSortedSetOfTSupplierOfSortedSetOfT() {
+        val set = _Sets.<Integer>minusSorted(null, null, TreeSet::new);
+        assertUnmodifiable(set);
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#toUnmodifiable(java.util.function.Supplier)}.
+     */
+    @Test
+    void testToUnmodifiableSupplierOfSetOfT() {
+        val set = Stream.of(3,1,2)
+        .collect(_Sets.toUnmodifiable(HashSet::new));
+        assertUnmodifiable(set);
+        Samples.assertSetEquals(_Sets.of(1, 2, 3), set);
+        
+        val sortedSet = Stream.of(3,1,2)
+        .collect(_Sets.toUnmodifiable(TreeSet::new));
+        assertUnmodifiable(sortedSet);
+        Samples.assertListEquals(_Lists.of(1, 2, 3), sortedSet);
+        
+        val orderedSet = Stream.of(3,1,2)
+        .collect(_Sets.toUnmodifiable(LinkedHashSet::new));
+        assertUnmodifiable(orderedSet);
+        Samples.assertListEquals(_Lists.of(3, 1, 2), orderedSet);
+        
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#toUnmodifiable()}.
+     */
+    @Test
+    void testToUnmodifiable() {
+        val set = Stream.of(3,1,2)
+        .collect(_Sets.toUnmodifiable(HashSet::new));
+        assertUnmodifiable(set);
+        Samples.assertSetEquals(_Sets.of(1, 2, 3), set);
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#toUnmodifiablePreservingOrder()}.
+     */
+    @Test
+    void testToUnmodifiablePreservingOrder() {
+        val orderedSet = Stream.of(3,1,2)
+        .collect(_Sets.toUnmodifiablePreservingOrder());
+        assertUnmodifiable(orderedSet);
+        Samples.assertListEquals(_Lists.of(3, 1, 2), orderedSet);
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#toUnmodifiableSorted(java.util.function.Supplier)}.
+     */
+    @Test
+    void testToUnmodifiableSortedSupplierOfSortedSetOfT() {
+        val sortedSet = Stream.of(3,1,2)
+        .collect(_Sets.toUnmodifiableSorted(TreeSet::new));
+        assertUnmodifiable(sortedSet);
+        Samples.assertListEquals(_Lists.of(1, 2, 3), sortedSet);
+    }
+
+    /**
+     * Test method for {@link org.apache.isis.core.commons.internal.collections._Sets#toUnmodifiableSorted()}.
+     */
+    @Test
+    void testToUnmodifiableSorted() {
+        val sortedSet = Stream.of(3,1,2)
+        .collect(_Sets.toUnmodifiableSorted());
+        assertUnmodifiable(sortedSet);
+        Samples.assertListEquals(_Lists.of(1, 2, 3), sortedSet);
+    }
+
+}