QueryStringParser { public static Map<String, List<String>> parseMap(String s) { if(null == s || s.length() == 0) { return Collections.emptyMap(); } Map<String, List<String>> params = new LinkedHashMap<>(); parse(s, params); return params; } protected  QueryStringParser(); static QueryString parse(String s); static Map<String, List<String>> parseMap(String s);  }
@Test public void testEmpty() { Map<String, List<String>> params = QueryStringParser.parseMap(null); assertTrue(params.isEmpty()); params = QueryStringParser.parseMap(""); assertTrue(params.isEmpty()); }
@Test public void testSingle() { Map<String, List<String>> params = QueryStringParser.parseMap("a=b&c=d%20e"); assertEquals(2, params.size()); assertEquals("b", params.get("a").get(0)); assertEquals("d e",params.get("c").get(0)); }
@Test public void testMulti() { Map<String, List<String>> params = QueryStringParser.parseMap("a=b&c=d&a=e"); assertEquals(2, params.size()); assertEquals("b", params.get("a").get(0)); assertEquals("e", params.get("a").get(1)); assertEquals("d",params.get("c").get(0)); }
@Test public void testEmptyValue() { Map<String, List<String>> params = QueryStringParser.parseMap("a=&b=&c&d"); assertEquals(4, params.size()); assertEquals("", params.get("a").get(0)); assertEquals("", params.get("b").get(0)); assertEquals("", params.get("c").get(0)); assertEquals("", params.get("d").get(0)); }