StreamConverter implements GenericHttpMessageConverter<Stream<T>> { @Override public boolean canRead(final Class<?> clazz, final MediaType mediaType) { return false; }  @Override boolean canRead(final Class<?> clazz, final MediaType mediaType); @Override boolean canRead(final Type type, @Nullable final Class<?> contextClass, final MediaType mediaType); @Override List<MediaType> getSupportedMediaTypes(); @Override Stream<T> read(final Class<? extends Stream<T>> clazz, final HttpInputMessage inputMessage); @Override Stream<T> read(final Type type, final Class<?> contextClass, final HttpInputMessage inputMessage); @Override boolean canWrite(final Class<?> clazz, final MediaType mediaType); boolean canWrite(final Type type, final Class<?> clazz, final MediaType mediaType); @Override void write(final Stream<T> t, final MediaType mediaType, final HttpOutputMessage message); void write(final Stream<T> t, final Type type, final MediaType mediaType, final HttpOutputMessage message);  }
@Test void shouldSupportRead() { final HttpMessageConverter<Stream<Object>> unit = streamConverter(new ObjectMapper(), singletonList(APPLICATION_JSON)); assertFalse(unit.canRead(Object.class, APPLICATION_XML)); assertFalse(unit.canRead(Stream.class, APPLICATION_JSON)); assertFalse(unit.canRead(Object.class, APPLICATION_JSON)); assertFalse(unit.canRead(List.class, APPLICATION_JSON)); assertFalse(unit.canRead(List[].class, APPLICATION_JSON)); assertFalse(unit.canRead(AccountBody.class, null)); assertFalse(unit.canRead(AccountBody[].class, null)); }
@Test void shouldSupportReadGeneric() { final ObjectMapper mapper = mock(ObjectMapper.class); final TypeFactory factory = new ObjectMapper().getTypeFactory(); when(mapper.getTypeFactory()).thenReturn(factory); when(mapper.canDeserialize(any())).thenReturn(true); final StreamConverter<Object> unit = streamConverter(mapper, singletonList(APPLICATION_X_JSON_STREAM)); assertFalse(unit.canRead(Object.class, getClass(), APPLICATION_X_JSON_STREAM)); assertFalse(unit.canRead(Streams.streamOf(Object.class).getType(), getClass(), APPLICATION_XML)); assertTrue(unit.canRead(Streams.streamOf(List.class).getType(), getClass(), APPLICATION_X_JSON_STREAM)); assertTrue(unit.canRead(Streams.streamOf(List[].class).getType(), getClass(), APPLICATION_X_JSON_STREAM)); assertTrue(unit.canRead(Streams.streamOf(AccountBody.class).getType(), getClass(), null)); assertTrue(unit.canRead(Streams.streamOf(AccountBody[].class).getType(), getClass(), null)); when(mapper.canDeserialize(factory.constructType(AccountBody.class))).thenReturn(false); assertFalse(unit.canRead(Streams.streamOf(AccountBody.class).getType(), getClass(), APPLICATION_X_JSON_STREAM)); }