### Question:
LoggingCallAdapterFactory extends CallAdapter.Factory { public static String errorMessage(ResponseBody errorBody) throws IOException { if (errorBody.contentLength() == 0) { return ""; } Buffer buffer = new Buffer(); buffer.writeAll(errorBody.source().peek()); if (!isPlaintext(buffer)) { return "Error body is not plain text."; } return ResponseBody.create(errorBody.contentType(), buffer.size(), buffer).string(); } LoggingCallAdapterFactory(Logger logger); static String errorMessage(ResponseBody errorBody); @Override CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit);  }### Answer:
@Test public void errorMessageHelperDoesNotConsumeErrorBody() throws IOException { ResponseBody errorBody = ResponseBody.create(null, "This request failed."); BufferedSource source = errorBody.source(); assertThat(LoggingCallAdapterFactory.errorMessage(errorBody)).isEqualTo("This request failed."); assertThat(source.getBuffer().size()).isEqualTo(20); assertThat(source.exhausted()).isFalse(); String errorBodyUtf8 = source.readUtf8(); assertThat(errorBodyUtf8).isEqualTo("This request failed."); assertThat(source.exhausted()).isTrue(); }
@Test public void errorMessageHelperReturnsEmptyStringForEmptyBody() throws IOException { ResponseBody errorBody = ResponseBody.create(null, new byte[0]); assertThat(LoggingCallAdapterFactory.errorMessage(errorBody)).isEmpty(); }
@Test public void errorMessageHelperChecksForPlainText() throws IOException { ResponseBody errorBody = ResponseBody.create(null, String.valueOf((char) 0x9F)); assertThat(LoggingCallAdapterFactory.errorMessage(errorBody)) .isEqualTo("Error body is not plain text."); }