HttpRequestLineUtils { public static Map<String, String> transformRaw(String queryStr) { HashMap<String, String> result = new HashMap<>(); if (queryStr != null) { String[] queries = queryStr.split("&"); for (String query : queries) { int first = query.indexOf('='); if (first == -1) { result.put(query, ""); } else { String key = query.substring(0, first); String value = query.substring(first + 1, query.length()); result.put(key, value); } } } return result; }  static Map<String, String> transformRaw(String queryStr); static Map<String, String> transform(String queryStr); static Map<String, String> transform(String queryStr, String encoding);  }
@Test public void transformRawTestKeyNoValue() { String query = "testkey"; Map<String, String> map = HttpRequestLineUtils.transformRaw(query); Assert.assertEquals(map.size(), 1); for (String key : map.keySet()) { Assert.assertEquals(key, "testkey"); Assert.assertEquals(map.get(key), ""); } }
@Test public void transformRawTestKeyEmptyValue() { String query = "testkey="; Map<String, String> map = HttpRequestLineUtils.transformRaw(query); Assert.assertEquals(map.size(), 1); for (String key : map.keySet()) { Assert.assertEquals(key, "testkey"); Assert.assertEquals(map.get(key), ""); } }
@Test public void transformRawTestKeyWithValue() { String query = "testkey=blablub"; Map<String, String> map = HttpRequestLineUtils.transformRaw(query); Assert.assertEquals(map.size(), 1); for (String key : map.keySet()) { Assert.assertEquals(key, "testkey"); Assert.assertEquals(map.get(key), "blablub"); } }
@Test public void transformRawTestKeyWithValueContainingEqualsSign() { String query = "testkey=blablub=test"; Map<String, String> map = HttpRequestLineUtils.transformRaw(query); Assert.assertEquals(map.size(), 1); for (String key : map.keySet()) { Assert.assertEquals(key, "testkey"); Assert.assertEquals(map.get(key), "blablub=test"); } }