@Test public void testUsesDelegateWhenReturnTypeNotInputStream() throws Exception { String returned = "string"; when(delegate.decode(any(), any())).thenReturn(returned); Response response = Response.create(200, "OK", ImmutableMap.of(), returned, StandardCharsets.UTF_8); String decodedObject = (String) inputStreamDelegateDecoder.decode(response, String.class); assertThat(decodedObject).isEqualTo(returned); }
@Override public Object decode(Response response, Type type) throws IOException, FeignException { if (type.equals(InputStream.class)) { byte[] body = response.body() != null ? Util.toByteArray(response.body().asInputStream()) : new byte[0]; return new ByteArrayInputStream(body); } else { return delegate.decode(response, type); } }
InputStreamDelegateDecoder implements Decoder { @Override public Object decode(Response response, Type type) throws IOException, FeignException { if (type.equals(InputStream.class)) { byte[] body = response.body() != null ? Util.toByteArray(response.body().asInputStream()) : new byte[0]; return new ByteArrayInputStream(body); } else { return delegate.decode(response, type); } } }
InputStreamDelegateDecoder implements Decoder { @Override public Object decode(Response response, Type type) throws IOException, FeignException { if (type.equals(InputStream.class)) { byte[] body = response.body() != null ? Util.toByteArray(response.body().asInputStream()) : new byte[0]; return new ByteArrayInputStream(body); } else { return delegate.decode(response, type); } } InputStreamDelegateDecoder(Decoder delegate); }
InputStreamDelegateDecoder implements Decoder { @Override public Object decode(Response response, Type type) throws IOException, FeignException { if (type.equals(InputStream.class)) { byte[] body = response.body() != null ? Util.toByteArray(response.body().asInputStream()) : new byte[0]; return new ByteArrayInputStream(body); } else { return delegate.decode(response, type); } } InputStreamDelegateDecoder(Decoder delegate); @Override Object decode(Response response, Type type); }
InputStreamDelegateDecoder implements Decoder { @Override public Object decode(Response response, Type type) throws IOException, FeignException { if (type.equals(InputStream.class)) { byte[] body = response.body() != null ? Util.toByteArray(response.body().asInputStream()) : new byte[0]; return new ByteArrayInputStream(body); } else { return delegate.decode(response, type); } } InputStreamDelegateDecoder(Decoder delegate); @Override Object decode(Response response, Type type);  }