### Question:
HttpHeaderTransport { Map<String, String> parse(String serialized) { final StringTokenizer pairTokenizer = new StringTokenizer(serialized.trim(), ","); final Map<String, String> context = new HashMap<>(); while (pairTokenizer.hasMoreTokens()) { final String pairStr = pairTokenizer.nextToken(); final String[] keyValuePair = pairStr.split("="); if (keyValuePair.length != 2) { continue; } try { final String key = URLDecoder.decode(keyValuePair[0], ENCODING_CHARSET); final String value = URLDecoder.decode(keyValuePair[1], ENCODING_CHARSET); context.put(key, value); } catch (UnsupportedEncodingException e) { LOGGER.error("Charset not found", e); } } return context; }  Map<String, String> parse(List<String> serializedElements); String render(Map<String, String> context); static final String ENCODING_CHARSET; }### Answer:
@Test public void emptyHeaderShouldReturnEmptyMap() { final Map<String, String> contextMap = UNIT.parse(""); assertThat(contextMap, is(notNullValue())); assertThat(contextMap.isEmpty(), is(true)); }
@Test public void parseHeaderWithoutAnySpecialChars() { final String header = "key1=value1,key2=value2"; final Map<String, String> context = UNIT.parse(header); assertThat(context, hasEntry("key1", "value1")); assertThat(context, hasEntry("key2", "value2")); }
@Test public void specialCharactersShouldBeParsedBackIntoContextMap() { final String header = "%C3%B6+%C3%BC%C3%A4%C3%9F=%C3%96+%C3%9C%C3%84%C3%9F%E2%82%AC,%21%22%C2%A7%24%25%26%40%2F%28+%29%3D%3F=%5E%C2%B0%2B*%27%23-.%2C%3B%3A_%3C%3E+%C2%B4%C2%B4%60%60"; final Map<String, String> context = UNIT.parse(header); assertThat(context, hasEntry("!\"§$%&@/( )=?", "^°+*'#-.,;:_<> ´´``")); assertThat(context, hasEntry("ö üäß", "Ö ÜÄß€")); }
@Test public void trimHeaderBeforeParsing() { final String header = " key1=value1,key2=value2 "; final Map<String, String> context = UNIT.parse(header); assertThat(context, hasEntry("key1", "value1")); assertThat(context, hasEntry("key2", "value2")); }
@Test public void skipPairWithoutValuePart() { final String header = "key1=value1,key2"; final Map<String, String> context = UNIT.parse(header); assertThat(context, hasEntry("key1", "value1")); assertThat(context.size(), is(1)); }
@Test public void skipPairWithTwoEqualSign() { final String header = "key1=value1=subvalue1,key2=value2"; final Map<String, String> context = UNIT.parse(header); assertThat(context, hasEntry("key2", "value2")); assertThat(context.size(), is(1)); }
@Test public void headerWithCommaShouldReturnInEmptyMap() { final Map<String, String> contextMap = UNIT.parse(","); assertThat(contextMap, is(notNullValue())); assertThat(contextMap.isEmpty(), is(true)); }
@Test public void shouldParseTwoHeadersAndMergeThem() { final List<String> headers = Arrays.asList("key1=value1,key2=value2", "key3=value3"); final Map<String, String> context = UNIT.parse(headers); assertThat(context, hasEntry("key1", "value1")); assertThat(context, hasEntry("key2", "value2")); assertThat(context, hasEntry("key3", "value3")); assertThat(context.size(), is(3)); }