Changeset 15870 in josm for trunk/test/unit


Ignore:
Timestamp:
2020-02-16T23:43:01+01:00 (5 years ago)
Author:
simon04
Message:

MultiMapTest: extend

Based on test coverage and mutation testing using Pitest.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/tools/MultiMapTest.java

    r15723 r15870  
    33
    44import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertFalse;
     6import static org.junit.Assert.assertNull;
    57import static org.junit.Assert.assertTrue;
    68
    79import java.util.Arrays;
     10import java.util.Collections;
    811import java.util.HashSet;
     12import java.util.Map;
     13import java.util.Set;
    914
    1015import org.junit.Test;
     
    4045        assertEquals(new HashSet<>(Arrays.asList("foo", "alpha")), map.keySet());
    4146        assertEquals(new HashSet<>(Arrays.asList("bar", "baz")), map.get("foo"));
     47        assertEquals(new HashSet<>(Arrays.asList("bar", "baz")), map.getValues("foo"));
    4248        assertEquals(new HashSet<>(), map.get("alpha"));
    43         assertEquals(null, map.get("beta"));
     49        assertEquals(Collections.emptySet(), map.getValues("alpha"));
     50        assertNull(map.get("beta"));
     51        assertEquals(Collections.emptySet(), map.getValues("beta"));
    4452        assertEquals(new HashSet<>(), map.getValues("alpha"));
    4553        assertEquals(new HashSet<>(), map.getValues("beta"));
    4654        map.put("foo", "baz2");
    4755        map.put("foo", "baz");
     56        assertTrue(map.containsKey("foo"));
     57        assertTrue(map.contains("foo", "bar"));
    4858        assertEquals(new HashSet<>(Arrays.asList("bar", "baz", "baz2")), map.get("foo"));
    49         map.remove("foo", "baz");
     59        assertFalse(map.contains("foo", "xxx"));
     60        assertFalse(map.remove("foo", "xxx"));
     61        assertTrue(map.remove("foo", "baz"));
    5062        assertEquals(new HashSet<>(Arrays.asList("bar", "baz2")), map.get("foo"));
    51         map.remove("foo");
    52         assertEquals(null, map.get("foo"));
     63        assertEquals(new HashSet<>(Arrays.asList("bar", "baz2")), map.remove("foo"));
     64        assertFalse(map.containsKey("foo"));
     65        assertNull(map.get("foo"));
    5366        assertEquals("(alpha->[])", map.toString());
    54         map.remove("alpha");
     67        assertEquals(Collections.emptySet(), map.remove("alpha"));
    5568        assertTrue(map.isEmpty());
    56         map.remove("omega", null);
     69        assertFalse(map.remove("omega", null));
    5770        assertTrue(map.isEmpty());
    5871        map.clear();
     
    6073        map.putAll("foo", Arrays.asList("bar", "baz"));
    6174        assertEquals(new HashSet<>(Arrays.asList("bar", "baz")), map.get("foo"));
     75        assertFalse(map.isEmpty());
     76        map.clear();
     77        assertTrue(map.isEmpty());
     78        assertEquals(0, new MultiMap<String, String>(null).size());
     79        final Map<String, Set<String>> asMap = Collections.singletonMap("foo", Collections.singleton("bar"));
     80        assertEquals(asMap, new MultiMap<>(asMap).toMap());
     81        assertEquals("[foo=[bar]]", new MultiMap<>(asMap).entrySet().toString());
     82        assertEquals("[foo]", new MultiMap<>(asMap).keySet().toString());
     83        assertEquals("[[bar]]", new MultiMap<>(asMap).values().toString());
    6284    }
    6385}
Note: See TracChangeset for help on using the changeset viewer.