LatenessDormancyController { @RequestMapping(method = RequestMethod.POST) public String processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel, @Valid @ModelAttribute("formBean") LatenessDormancyFormBean formBean, BindingResult result, SessionStatus status) { String viewName = REDIRECT_TO_ADMIN_SCREEN; if (StringUtils.isNotBlank(cancel)) { viewName = REDIRECT_TO_ADMIN_SCREEN; status.setComplete(); } else if (result.hasErrors()) { viewName = "editLatenessDormancy"; } else { ProductConfigurationDto productConfigurationDto = new ProductConfigurationDto(formBean.getLatenessDays(), formBean.getDormancyDays()); this.adminServiceFacade.updateProductConfiguration(productConfigurationDto); status.setComplete(); } return viewName; } protected  LatenessDormancyController();  LatenessDormancyController(final AdminServiceFacade adminServiceFacade); @ModelAttribute("breadcrumbs") List<BreadCrumbsLinks> showBreadCrumbs(); @RequestMapping(method = RequestMethod.GET) @ModelAttribute("formBean") LatenessDormancyFormBean showPopulatedForm(); @RequestMapping(method = RequestMethod.POST) String processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel,
                                    @Valid @ModelAttribute("formBean") LatenessDormancyFormBean formBean,
                                    BindingResult result,
                                    SessionStatus status);  }
@Test public void cancelShouldRedirectToAdminView() throws Exception { LatenessDormancyFormBean expectedFormBean = new LatenessDormancyFormBean(); expectedFormBean.setLatenessDays(1); expectedFormBean.setDormancyDays(1); String returnedView = latenessDormancyController.processFormSubmit("Cancel", expectedFormBean, bindingResult, sessionStatus); Assert.assertThat(returnedView, is(ADMIN_VIEW)); Mockito.verify(sessionStatus).setComplete(); }
@Test public void bindingErrorsShouldCauseReturnToFormView() throws Exception { LatenessDormancyFormBean expectedFormBean = new LatenessDormancyFormBean(); expectedFormBean.setLatenessDays(1); expectedFormBean.setDormancyDays(1); when(bindingResult.hasErrors()).thenReturn(true); String returnedView = latenessDormancyController.processFormSubmit("", expectedFormBean, bindingResult, sessionStatus); Assert.assertThat(returnedView, is(FORM_VIEW)); Mockito.verify(sessionStatus, times(0)).setComplete(); }
@Test public void productConfigurationIsUpdatedOnFormSubmission() throws Exception { LatenessDormancyFormBean expectedFormBean = new LatenessDormancyFormBean(); expectedFormBean.setLatenessDays(1); expectedFormBean.setDormancyDays(1); String returnedView = latenessDormancyController.processFormSubmit("", expectedFormBean, bindingResult, sessionStatus); Assert.assertThat(returnedView, is(ADMIN_VIEW)); Mockito.verify(adminServiceFacade).updateProductConfiguration((ProductConfigurationDto)anyObject()); Mockito.verify(sessionStatus).setComplete(); }