MapUtils { public static Map<String, String> mapOf(final String... keyOrValues) { if (keyOrValues.length % 2 != 0) { throw new IllegalArgumentException("Must provide an even number of arguments"); } final Map<String, String> map = _Maps.newLinkedHashMap(); String key = null; for (final String keyOrValue : keyOrValues) { if (key != null) { map.put(key, keyOrValue); key = null; } else { key = keyOrValue; } } return Collections.unmodifiableMap(map); }  static Map<String, String> mapOf(final String... keyOrValues);  }
@Test public void happyCase() throws Exception { final Map<String, String> map = MapUtils.mapOf("foo", "bar", "foz", "boz"); assertThat(map.get("foo"), is("bar")); assertThat(map.get("foz"), is("boz")); assertThat(map.size(), is(2)); }
@Test public void emptyList() throws Exception { final Map<String, String> map = MapUtils.mapOf(); assertThat(map.size(), is(0)); }
@Test(expected = IllegalArgumentException.class) public void uneven() throws Exception { MapUtils.mapOf("foo"); }