source: josm/trunk/test/unit/org/openstreetmap/josm/tools/MultiMapTest.java@ 10758

Last change on this file since 10758 was 10758, checked in by Don-vip, 8 years ago

sonar - squid:S3578 - Test methods should comply with a naming convention

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertTrue;
6
7import java.util.Arrays;
8import java.util.HashSet;
9
10import nl.jqno.equalsverifier.EqualsVerifier;
11import org.junit.Test;
12
13/**
14 * Unit tests of {@link MultiMap} class.
15 */
16public 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}
Note: See TracBrowser for help on using the repository browser.