### Question:
ConfigurationController { @RequestMapping(value="/configuration/sape", method=RequestMethod.POST) public ModelAndView saveSapeConfiguration(@ModelAttribute SapeConfiguration configuration, BindingResult result) { if (!result.hasErrors()) { Component forumComponent = componentService.getComponentOfForum(); configurationService.updateSapeConfiguration(configuration, forumComponent.getId()); } return new ModelAndView(VIEW_SAPE_CONFIGURATION) .addObject(PARAM_SAPE_CONFIGURATION, configuration); } @Autowired  ConfigurationController(ConfigurationService configurationService, ComponentService componentService); @InitBinder void initBinder(WebDataBinder binder); @RequestMapping(value="/configuration/sape", method=RequestMethod.GET) ModelAndView showSapeConfigurationPage(); @RequestMapping(value="/configuration/sape", method=RequestMethod.POST) ModelAndView saveSapeConfiguration(@ModelAttribute SapeConfiguration configuration, BindingResult result);  }### Answer:
@Test public void testSaveSapeConfigurationValidationSuccess() { SapeConfiguration newConfiguration = new SapeConfiguration(); BindingResult bindingResult = mock(BindingResult.class); when(bindingResult.hasErrors()).thenReturn(false); ModelAndView mav = controller.saveSapeConfiguration(newConfiguration, bindingResult); verify(configurationService).updateSapeConfiguration(eq(newConfiguration), anyLong()); assertViewName(mav, VIEW_SAPE_CONFIGURATION); assertModelAttributeAvailable(mav, PARAM_SAPE_CONFIGURATION); SapeConfiguration configuration = assertAndReturnModelAttributeOfType( mav, PARAM_SAPE_CONFIGURATION, SapeConfiguration.class); assertEquals(configuration, newConfiguration); }
@Test public void testSaveSapeConfigurationValidationFail() { SapeConfiguration newConfiguration = new SapeConfiguration(); BindingResult bindingResult = mock(BindingResult.class); when(bindingResult.hasErrors()).thenReturn(true); ModelAndView mav = controller.saveSapeConfiguration(newConfiguration, bindingResult); verify(configurationService, never()).updateSapeConfiguration(eq(newConfiguration), anyLong()); assertViewName(mav, VIEW_SAPE_CONFIGURATION); assertModelAttributeAvailable(mav, PARAM_SAPE_CONFIGURATION); SapeConfiguration configuration = assertAndReturnModelAttributeOfType( mav, PARAM_SAPE_CONFIGURATION, SapeConfiguration.class); assertEquals(configuration, newConfiguration); }