*/
package org.opendaylight.yangtools.util;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.common.collect.ImmutableMap;
import java.util.Collections;
import java.util.Map;
-import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class SharedSingletonMapTest {
+class SharedSingletonMapTest {
private static UnmodifiableMapPhase<String, String> create() {
return SharedSingletonMap.orderedOf("k1", "v1");
}
@Test
- public void testSimpleOperations() {
- final Map<String, String> m = create();
+ void testSimpleOperations() {
+ final var m = create();
assertFalse(m.isEmpty());
assertEquals(1, m.size());
assertNull(m.get(null));
assertNull(m.get("v1"));
- assertFalse(m.equals(null));
- assertTrue(m.equals(m));
- assertFalse(m.equals(""));
+ assertNotEquals(null, m);
+ assertEquals(m, m);
+ assertNotEquals("", m);
- final Map<String, String> same = Collections.singletonMap("k1", "v1");
+ final var same = Collections.singletonMap("k1", "v1");
assertEquals(same.toString(), m.toString());
- assertTrue(same.equals(m));
- assertTrue(m.equals(same));
+ assertEquals(same, m);
+ assertEquals(m, same);
assertEquals(same.entrySet(), m.entrySet());
assertEquals(same.values(), m.values());
assertEquals(same.hashCode(), m.hashCode());
assertEquals(same.hashCode(), m.hashCode());
- assertFalse(m.equals(Collections.singletonMap(null, null)));
- 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")));
+ assertNotEquals(m, Collections.singletonMap(null, null));
+ assertNotEquals(m, Collections.singletonMap("k1", null));
+ assertNotEquals(m, Collections.singletonMap(null, "v1"));
+ assertNotEquals(m, Map.of("k1", "v2"));
+ assertNotEquals(m, ImmutableMap.of("k1", "v1", "k2", "v2"));
- final Set<String> set = m.keySet();
- assertThat(set, instanceOf(SingletonSet.class));
+ final var set = m.keySet();
+ assertInstanceOf(SingletonSet.class, set);
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));
+ void testOrderedCopyOf() {
+ final var t = Map.of("k1", "v1");
+ final var m = SharedSingletonMap.orderedCopyOf(t);
+ assertEquals(t, m);
+ assertEquals(m, 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));
+ void testUnorderedCopyOf() {
+ final var t = Map.of("k1", "v1");
+ final var m = SharedSingletonMap.unorderedCopyOf(t);
+ assertEquals(t, m);
+ assertEquals(m, t);
}
@Test
- public void testEmptyOrderedCopyOf() {
+ void testEmptyOrderedCopyOf() {
assertThrows(IllegalArgumentException.class, () -> SharedSingletonMap.orderedCopyOf(ImmutableMap.of()));
}
@Test
- public void testEmptyUnorderedCopyOf() {
+ void testEmptyUnorderedCopyOf() {
assertThrows(IllegalArgumentException.class, () -> SharedSingletonMap.unorderedCopyOf(ImmutableMap.of()));
}
@Test
- public void testClear() {
+ void testClear() {
assertThrows(UnsupportedOperationException.class, () -> create().clear());
}
@Test
- public void testPut() {
+ void testPut() {
assertThrows(UnsupportedOperationException.class, () -> create().put(null, null));
}
@Test
- public void testPutAll() {
+ void testPutAll() {
assertThrows(UnsupportedOperationException.class, () -> create().putAll(Collections.singletonMap("", "")));
}
@Test
- public void testRemove() {
+ void testRemove() {
assertThrows(UnsupportedOperationException.class, () -> create().remove(null));
}
}