### Question:
FlotChartService { public AnalysisResult generateCharts(AnalysisForm analysisForm) { Preconditions.checkNotNull(analysisForm); Map<ChartCode, FlotChart> charts = Maps.newHashMap(); generateAllPossibleCharts(analysisForm, charts); generateAggregatedMainChart(analysisForm, charts); return new AnalysisResult(analysisForm, charts); }  AnalysisResult generateCharts(AnalysisForm analysisForm); @Autowired void setFlotChartAggregator(FlotChartAggregator flotChartAggregator); @Autowired void setFlotChartGenerator(FlotChartGenerator flotChartGenerator);  }### Answer:
@Test(expected = NullPointerException.class) public void generateCharts_NULL() { flotChartService.generateCharts(null); }
@Test public void generateCharts() { AnalysisForm analysisForm = mock(AnalysisForm.class); UiySettings uiySettings = new UiySettings(); UiyValueType valueType = UiyValueType.NUMBER; uiySettings.setValueType(valueType); when(analysisForm.getYsettings()).thenReturn(uiySettings); FlotChart mainChart = mock(FlotChart.class); when(flotChartGenerator.canGenerateChart(ChartCode.MAIN_CHART, analysisForm)).thenReturn(true); when(flotChartGenerator.generateFlotChart(ChartCode.MAIN_CHART, analysisForm)).thenReturn(mainChart); when(flotChartGenerator.canGenerateChart(ChartCode.AGGREGATED_MAIN_CHART, analysisForm)).thenReturn(false); FlotChart aggregatedMainChart = mock(FlotChart.class); when(chartAggregator.aggregateChart(mainChart, valueType)).thenReturn(aggregatedMainChart); AnalysisResult analysisResult = flotChartService.generateCharts(analysisForm); assertNotNull(analysisResult); Map<ChartCode, FlotChart> flotCharts = analysisResult.getCharts(); assertNotNull(flotCharts); assertEquals(2, flotCharts.size()); assertTrue(mainChart == flotCharts.get(ChartCode.MAIN_CHART)); assertTrue(aggregatedMainChart == flotCharts.get(ChartCode.AGGREGATED_MAIN_CHART)); for (ChartCode chartCode : ChartCode.values()) { verify(flotChartGenerator).canGenerateChart(chartCode, analysisForm); } AnalysisForm generatedChartAnalysisForm = analysisResult.getAnalysisForm(); assertTrue(analysisForm == generatedChartAnalysisForm); }