### Question:
Tags { public static void parse(final HashMap<String, String> tags, final String tag) { final String[] kv = splitString(tag, '='); if (kv.length != 2 || kv[0].length() <= 0 || kv[1].length() <= 0) { throw new IllegalArgumentException("invalid tag: " + tag); } if (kv[1].equals(tags.get(kv[0]))) { return; } if (tags.get(kv[0]) != null) { throw new IllegalArgumentException("duplicate tag: " + tag + ", tags=" + tags); } tags.put(kv[0], kv[1]); } private  Tags(); static String[] splitString(final String s, final char c); static void parse(final HashMap<String, String> tags,
                             final String tag); static String parseWithMetric(final String metric,
                                         final HashMap<String, String> tags); static long parseLong(final CharSequence s); static boolean looksLikeInteger(final String value);  }### Answer:
@Test public void parseSuccessful() { final HashMap<String, String> tags = new HashMap<String, String>(2); Tags.parse(tags, "foo=bar"); assertEquals(1, tags.size()); assertEquals("bar", tags.get("foo")); Tags.parse(tags, "qux=baz"); assertEquals(2, tags.size()); assertEquals("bar", tags.get("foo")); assertEquals("baz", tags.get("qux")); }
@Test(expected=IllegalArgumentException.class) public void parseNoEqualSign() { Tags.parse(new HashMap<String, String>(1), "foo"); }
@Test(expected=IllegalArgumentException.class) public void parseTooManyEqualSigns() { Tags.parse(new HashMap<String, String>(1), "foo=bar=qux"); }
@Test(expected=IllegalArgumentException.class) public void parseEmptyTagName() { Tags.parse(new HashMap<String, String>(1), "=bar"); }
@Test(expected=IllegalArgumentException.class) public void parseEmptyTagValue() { Tags.parse(new HashMap<String, String>(1), "foo="); }
@Test(expected=IllegalArgumentException.class) public void parseDifferentValues() { final HashMap<String, String> tags = new HashMap<String, String>(1); Tags.parse(tags, "foo=bar"); assertEquals(1, tags.size()); assertEquals("bar", tags.get("foo")); Tags.parse(tags, "foo=qux"); }
@Test public void parseSameValues() { final HashMap<String, String> tags = new HashMap<String, String>(1); Tags.parse(tags, "foo=bar"); assertEquals(1, tags.size()); assertEquals("bar", tags.get("foo")); Tags.parse(tags, "foo=bar"); assertEquals(1, tags.size()); assertEquals("bar", tags.get("foo")); }