@Test public void testSmileReadException() throws IOException { InputStream inputStream = mock(InputStream.class); IOException expectedException = new IOException("test exception"); when(inputStream.read()).thenThrow(expectedException); when(inputStream.read(any(byte[].class))).thenThrow(expectedException); when(inputStream.read(any(byte[].class), anyInt(), anyInt())).thenThrow(expectedException); try { handler.handle(null, mockResponse() .contentType(MEDIA_TYPE_SMILE) .body(inputStream) .build()); fail("expected exception"); } catch (RuntimeException e) { assertEquals(e.getMessage(), "Error reading SMILE response from server"); assertSame(e.getCause(), expectedException); } }
@Override public SmileResponse<T> handle(Request request, Response response) { String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_SMILE)) { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders()); } try { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, response.getInputStream()); } catch (IOException e) { throw new RuntimeException("Error reading SMILE response from server", e); } }
FullSmileResponseHandler implements ResponseHandler<SmileResponse<T>, RuntimeException> { @Override public SmileResponse<T> handle(Request request, Response response) { String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_SMILE)) { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders()); } try { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, response.getInputStream()); } catch (IOException e) { throw new RuntimeException("Error reading SMILE response from server", e); } } }
FullSmileResponseHandler implements ResponseHandler<SmileResponse<T>, RuntimeException> { @Override public SmileResponse<T> handle(Request request, Response response) { String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_SMILE)) { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders()); } try { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, response.getInputStream()); } catch (IOException e) { throw new RuntimeException("Error reading SMILE response from server", e); } } private  FullSmileResponseHandler(JsonCodec<T> jsonCodec); }
FullSmileResponseHandler implements ResponseHandler<SmileResponse<T>, RuntimeException> { @Override public SmileResponse<T> handle(Request request, Response response) { String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_SMILE)) { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders()); } try { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, response.getInputStream()); } catch (IOException e) { throw new RuntimeException("Error reading SMILE response from server", e); } } private  FullSmileResponseHandler(JsonCodec<T> jsonCodec); static FullSmileResponseHandler<T> createFullSmileResponseHandler(JsonCodec<T> jsonCodec); @Override SmileResponse<T> handleException(Request request, Exception exception); @Override SmileResponse<T> handle(Request request, Response response); }
FullSmileResponseHandler implements ResponseHandler<SmileResponse<T>, RuntimeException> { @Override public SmileResponse<T> handle(Request request, Response response) { String contentType = response.getHeader(CONTENT_TYPE); if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_SMILE)) { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders()); } try { return new SmileResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, response.getInputStream()); } catch (IOException e) { throw new RuntimeException("Error reading SMILE response from server", e); } } private  FullSmileResponseHandler(JsonCodec<T> jsonCodec); static FullSmileResponseHandler<T> createFullSmileResponseHandler(JsonCodec<T> jsonCodec); @Override SmileResponse<T> handleException(Request request, Exception exception); @Override SmileResponse<T> handle(Request request, Response response);  }