### Question:
ChartCsvService { public void generateChartCsv(ChartCode chartCode, AnalysisForm analysisForm, Locale locale, HttpServletResponse response) throws IOException { createHttpHeaders(chartCode, response); Chart<Object, Number> chart = chartGenerator.generateChart(chartCode, analysisForm); chartCsvExporter.exportChartToCsv(chart, chartCode, analysisForm, locale, response.getWriter()); response.flushBuffer(); }  void generateChartCsv(ChartCode chartCode, AnalysisForm analysisForm, Locale locale, HttpServletResponse response); @Autowired void setChartGenerator(ChartGenerator chartGenerator); @Autowired void setChartCsvExporter(ChartCsvExporter chartCsvExporter);  }### Answer:
@SuppressWarnings("unchecked") @Test public void generateChartCsv() throws IOException { ChartCode chartCode = ChartCode.MAIN_CHART; AnalysisForm analysisForm = mock(AnalysisForm.class); HttpServletResponse response = mock(HttpServletResponse.class); Locale locale = Locale.CANADA_FRENCH; PrintWriter writer = mock(PrintWriter.class); when(response.getWriter()).thenReturn(writer); Chart<Object, Number> chart = mock(Chart.class); when(chartGenerator.generateChart(chartCode, analysisForm)).thenReturn(chart); chartCsvService.generateChartCsv(chartCode, analysisForm, locale, response); verify(chartCsvExporter).exportChartToCsv(same(chart), eq(chartCode), same(analysisForm), eq(locale), same(writer)); verify(response).flushBuffer(); }