StringReaderWriter extends AbstractReaderWriter { @SuppressWarnings("unchecked") @Override public <T> T readFrom(InternalRequest<Object> request, Type<T> clazz) { Charset charset = Optional.of(request.getContentType()) .flatMap(mediaType -> mediaType.getParam("charset")) .map(Charset::forName) .orElse(DEFAULT_CHARSET); StringBuilder builder = new BufferedReader( new InputStreamReader(request.getInputStream(), charset)).lines() .collect(StringBuilder::new, StringBuilder::append, StringBuilder::append); return (T) builder.toString(); }  @SuppressWarnings("unchecked") @Override T readFrom(InternalRequest<Object> request, Type<T> clazz); @Override void writeTo(InternalResponse<?> response, InternalRequest<?> request); @Override boolean isClassCompatible(Class<?> clazz); @Override MediaType getMediaType();  }
@Test public void read_from_success() { String entity = "Well Done!"; RequestStub request = new RequestStub(); request.setInputStream(new ByteArrayInputStream(entity.getBytes(StandardCharsets.UTF_8))); String result = testedClass.readFrom(request, Req(String.class)); Assert.assertEquals(entity, result); }