@Test public void shouldLoadFilledModel() throws Exception { // GIVEN a filled data model final Map<String, Object> modelData = createFilledModel(); // Some static data is changed at this moment, so need to reset the extractors list ReportColumnsExtractorHelper.reset(); // WHEN asking the view to render the model contents underTest.renderMergedOutputModel(modelData, mock(HttpServletRequest.class), response); // THEN the resulting CSV contains the expected data verify(writer).write("\"Header\",\"Header NG\",\"H\",\"Header\"\n"); verify(writer).write("\"str\",\"\",\"2\",\"\"\n"); verify(writer).flush(); }
@Test public void shouldLoadEmptyModel() throws Exception { // GIVEN a data model (empty in our case) final Map<String, Object> modelData = createEmptyModel(); // WHEN asking the view to render the model contents underTest.renderMergedOutputModel(modelData, mock(HttpServletRequest.class), response); // THEN the response sets the correct MIME type verify(response).setContentType("text/csv"); verify(response).setHeader("Content-Disposition", "attachment; filename=activityReport.csv"); // AND returns an empty closed stream verify(sourceWriter).close(); }