HeadersSerializer implements Serializer<Headers> { @Override public String serialize(final Headers headers) { Set<String> names = headers.keySet(); StringBuilder sb = new StringBuilder(); for (String name : names) { sb.append(name) .append(KEY_VALUE_SEPARATOR) .append(headers.getHeader(name)) .append(NEW_LINE); } sb.append(NEW_LINE); return sb.toString(); }  @Override String serialize(final Headers headers);  }
@Test public void shouldSerializeResponse() { Headers headers = new Headers(); headers.setHeader("Header", "Value"); headers.setHeader("SomeOtherHeader", "123"); assertThat(headersSerializer.serialize(headers), anyOf( is("SomeOtherHeader: 123\r\nHeader: Value\r\n\r\n"), is("Header: Value\r\nSomeOtherHeader: 123\r\n\r\n") )); }
@Test public void shouldPreserveOriginalCase() { Headers headers = new Headers(); headers.setHeader("header", "Value"); headers.setHeader("someOtherHeader", "123"); assertThat(headersSerializer.serialize(headers), anyOf( is("someOtherHeader: 123\r\nheader: Value\r\n\r\n"), is("header: Value\r\nsomeOtherHeader: 123\r\n\r\n") )); }