@Test void testWriteInternal() throws IOException { List<String> attrName = asList("attr0", "attr1"); Entity entity0 = mock(Entity.class); Entity entity1 = mock(Entity.class); EntityCollection entityCollection = mock(EntityCollection.class); when(entityCollection.getAttributeNames()).thenReturn(attrName); when(entityCollection.stream()).thenReturn(Stream.of(entity0, entity1)); HttpHeaders httpHeaders = mock(HttpHeaders.class); when(httpHeaders.getContentType()).thenReturn(APPLICATION_JSON_UTF8); OutputStream outputStream = mock(OutputStream.class); HttpOutputMessage outputMessage = mock(HttpOutputMessage.class); when(outputMessage.getHeaders()).thenReturn(httpHeaders); when(outputMessage.getBody()).thenReturn(outputStream); csvHttpMessageConverter.writeInternal(entityCollection, outputMessage); verify(outputStream).close(); }
@Override protected void writeInternal(EntityCollection entities, HttpOutputMessage outputMessage) throws IOException { Charset charset = getCharset(outputMessage.getHeaders()); try (CsvWriter csvWriter = new CsvWriter(new OutputStreamWriter(outputMessage.getBody(), charset))) { csvWriter.writeAttributeNames(entities.getAttributeNames()); csvWriter.add(entities.stream()); } }
CsvHttpMessageConverter extends BaseHttpMessageConverter<EntityCollection> { @Override protected void writeInternal(EntityCollection entities, HttpOutputMessage outputMessage) throws IOException { Charset charset = getCharset(outputMessage.getHeaders()); try (CsvWriter csvWriter = new CsvWriter(new OutputStreamWriter(outputMessage.getBody(), charset))) { csvWriter.writeAttributeNames(entities.getAttributeNames()); csvWriter.add(entities.stream()); } } }
CsvHttpMessageConverter extends BaseHttpMessageConverter<EntityCollection> { @Override protected void writeInternal(EntityCollection entities, HttpOutputMessage outputMessage) throws IOException { Charset charset = getCharset(outputMessage.getHeaders()); try (CsvWriter csvWriter = new CsvWriter(new OutputStreamWriter(outputMessage.getBody(), charset))) { csvWriter.writeAttributeNames(entities.getAttributeNames()); csvWriter.add(entities.stream()); } } CsvHttpMessageConverter(); }
CsvHttpMessageConverter extends BaseHttpMessageConverter<EntityCollection> { @Override protected void writeInternal(EntityCollection entities, HttpOutputMessage outputMessage) throws IOException { Charset charset = getCharset(outputMessage.getHeaders()); try (CsvWriter csvWriter = new CsvWriter(new OutputStreamWriter(outputMessage.getBody(), charset))) { csvWriter.writeAttributeNames(entities.getAttributeNames()); csvWriter.add(entities.stream()); } } CsvHttpMessageConverter();  }
CsvHttpMessageConverter extends BaseHttpMessageConverter<EntityCollection> { @Override protected void writeInternal(EntityCollection entities, HttpOutputMessage outputMessage) throws IOException { Charset charset = getCharset(outputMessage.getHeaders()); try (CsvWriter csvWriter = new CsvWriter(new OutputStreamWriter(outputMessage.getBody(), charset))) { csvWriter.writeAttributeNames(entities.getAttributeNames()); csvWriter.add(entities.stream()); } } CsvHttpMessageConverter();   }