Maps { public static Map<String, String> of(String k1, String v1) { Map<String, String> map = new LinkedHashMap<>(2); map.put(k1, v1); return map; }  static Map<String, String> of(String k1, String v1); static Map<String, String> of(String k1, String v1, String k2, String v2); static Map<String, String> of(String... kvp);  }
@Test public void testTwoKeyValues() { map = Maps.of("foo", "bar", "baz", "qux"); assertEquals(2, map.size()); keys = map.keySet().iterator(); assertEquals("foo", keys.next()); assertEquals("baz", keys.next()); values = map.values().iterator(); assertEquals("bar", values.next()); assertEquals("qux", values.next()); }
@Test(expected = IllegalArgumentException.class) public void oddNumberOfParamsThrowsException() { map = Maps.of("foo", "bar", "baz"); }
@Test public void evenNumberOfParamsWorks() { map = Maps.of("a", "b", "c", "d", "e", "f"); assertEquals(3, map.size()); keys = map.keySet().iterator(); assertEquals("a", keys.next()); assertEquals("c", keys.next()); assertEquals("e", keys.next()); values = map.values().iterator(); assertEquals("b", values.next()); assertEquals("d", values.next()); assertEquals("f", values.next()); }
@Test public void testOneKeyValue() { map = Maps.of("foo", "bar"); assertEquals(1, map.size()); assertEquals("foo", map.keySet().iterator().next()); assertEquals("bar", map.values().iterator().next()); }