| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.tools;
|
|---|
| 3 |
|
|---|
| 4 | import static org.junit.Assert.assertEquals;
|
|---|
| 5 | import static org.junit.Assert.assertTrue;
|
|---|
| 6 |
|
|---|
| 7 | import java.util.Arrays;
|
|---|
| 8 | import java.util.HashSet;
|
|---|
| 9 |
|
|---|
| 10 | import nl.jqno.equalsverifier.EqualsVerifier;
|
|---|
| 11 | import org.junit.Test;
|
|---|
| 12 |
|
|---|
| 13 | /**
|
|---|
| 14 | * Unit tests of {@link MultiMap} class.
|
|---|
| 15 | */
|
|---|
| 16 | public class MultiMapTest {
|
|---|
| 17 |
|
|---|
| 18 | /**
|
|---|
| 19 | * Unit test of methods {@link MultiMap#equals} and {@link MultiMap#hashCode}.
|
|---|
| 20 | */
|
|---|
| 21 | @Test
|
|---|
| 22 | public void testEqualsContract() {
|
|---|
| 23 | EqualsVerifier.forClass(MultiMap.class).usingGetClass().verify();
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | /**
|
|---|
| 27 | * Various test of {@link MultiMap}.
|
|---|
| 28 | */
|
|---|
| 29 | @Test
|
|---|
| 30 | public void testMultiMap() {
|
|---|
| 31 | final MultiMap<String, String> map = new MultiMap<>();
|
|---|
| 32 | assertTrue(map.isEmpty());
|
|---|
| 33 | map.put("foo", "bar");
|
|---|
| 34 | map.put("foo", "baz");
|
|---|
| 35 | map.putVoid("alpha");
|
|---|
| 36 | assertEquals(2, map.size());
|
|---|
| 37 | assertEquals(new HashSet<>(Arrays.asList("foo", "alpha")), map.keySet());
|
|---|
| 38 | assertEquals(new HashSet<>(Arrays.asList("bar", "baz")), map.get("foo"));
|
|---|
| 39 | assertEquals(new HashSet<>(), map.get("alpha"));
|
|---|
| 40 | assertEquals(null, map.get("beta"));
|
|---|
| 41 | assertEquals(new HashSet<>(), map.getValues("alpha"));
|
|---|
| 42 | assertEquals(new HashSet<>(), map.getValues("beta"));
|
|---|
| 43 | map.put("foo", "baz2");
|
|---|
| 44 | map.put("foo", "baz");
|
|---|
| 45 | assertEquals(new HashSet<>(Arrays.asList("bar", "baz", "baz2")), map.get("foo"));
|
|---|
| 46 | map.remove("foo", "baz");
|
|---|
| 47 | assertEquals(new HashSet<>(Arrays.asList("bar", "baz2")), map.get("foo"));
|
|---|
| 48 | map.remove("foo");
|
|---|
| 49 | assertEquals(null, map.get("foo"));
|
|---|
| 50 | assertEquals("(alpha->{})", map.toString());
|
|---|
| 51 | map.remove("alpha");
|
|---|
| 52 | assertTrue(map.isEmpty());
|
|---|
| 53 | map.remove("omega", null);
|
|---|
| 54 | assertTrue(map.isEmpty());
|
|---|
| 55 | map.clear();
|
|---|
| 56 | assertTrue(map.isEmpty());
|
|---|
| 57 | map.putAll("foo", Arrays.asList("bar", "baz"));
|
|---|
| 58 | assertEquals(new HashSet<>(Arrays.asList("bar", "baz")), map.get("foo"));
|
|---|
| 59 | }
|
|---|
| 60 | }
|
|---|