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