BUG-4803: introduce unordered offset maps
[yangtools.git] / common / util / src / test / java / org / opendaylight / yangtools / util / SharedSingletonMapTest.java
index 3e0bb753dfbead2d027e3808f964faa0695d1628..58064e87bc9369a2997040aa8a3f306ff194d4e1 100644 (file)
@@ -11,6 +11,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import com.google.common.collect.ImmutableMap;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
@@ -18,7 +19,7 @@ import org.junit.Test;
 
 public class SharedSingletonMapTest {
     private static UnmodifiableMapPhase<String, String> create() {
-        return SharedSingletonMap.of("k1", "v1");
+        return SharedSingletonMap.orderedOf("k1", "v1");
     }
 
     @Test
@@ -59,12 +60,39 @@ public class SharedSingletonMapTest {
         assertFalse(m.equals(Collections.singletonMap("k1", null)));
         assertFalse(m.equals(Collections.singletonMap(null, "v1")));
         assertFalse(m.equals(Collections.singletonMap("k1", "v2")));
+        assertFalse(m.equals(ImmutableMap.of("k1", "v1", "k2", "v2")));
 
         final Set<String> set = m.keySet();
         assertTrue(set instanceof SingletonSet);
         assertTrue(set.contains("k1"));
     }
 
+    @Test
+    public void testOrderedCopyOf() {
+        final Map<String, String> t = Collections.singletonMap("k1", "v1");
+        final Map<String, String> m = SharedSingletonMap.orderedCopyOf(t);
+        assertTrue(t.equals(m));
+        assertTrue(m.equals(t));
+    }
+
+    @Test
+    public void testUnorderedCopyOf() {
+        final Map<String, String> t = Collections.singletonMap("k1", "v1");
+        final Map<String, String> m = SharedSingletonMap.unorderedCopyOf(t);
+        assertTrue(t.equals(m));
+        assertTrue(m.equals(t));
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testEmptyOrderedCopyOf() {
+        SharedSingletonMap.orderedCopyOf(ImmutableMap.of());
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testEmptyUnorderedCopyOf() {
+        SharedSingletonMap.unorderedCopyOf(ImmutableMap.of());
+    }
+
     @Test(expected=UnsupportedOperationException.class)
     public void testClear() {
         create().clear();