DefineProductCategoryPreviewController { @RequestMapping(method = RequestMethod.POST) public ModelAndView processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel, @RequestParam(value = EDIT_PARAM, required = false) String edit, @ModelAttribute("formBean") ProductCategoryFormBean bean, BindingResult result) { ModelAndView modelAndView = new ModelAndView("defineNewCategory"); if (StringUtils.isNotBlank(cancel)) { modelAndView.setViewName(REDIRECT_TO_ADMIN); } else if (StringUtils.isNotBlank(edit)) { modelAndView.setViewName("defineNewCategory"); modelAndView.addObject("formBean", bean); modelAndView.addObject("typeList", this.getProductCategoryTypes()); } else if (result.hasErrors()) { modelAndView.setViewName("newProductCategoryPreview"); modelAndView.addObject("formBean", bean); } else { CreateOrUpdateProductCategory productCategory = new CreateOrUpdateProductCategory(Short.parseShort(bean.getProductTypeId()), bean.getProductCategoryName(), bean.getProductCategoryDesc(), Short.parseShort(bean.getProductCategoryStatusId()), bean.getGlobalPrdCategoryNum()); try { this.adminServiceFacade.createProductCategory(productCategory); modelAndView.setViewName(REDIRECT_TO_ADMIN); } catch (BusinessRuleException e) { ObjectError error = new ObjectError("formBean", new String[] { e.getMessageKey() }, new Object[] {}, "default: "); result.addError(error); modelAndView.setViewName("newProductCategoryPreview"); modelAndView.addObject("formBean", bean); } } return modelAndView; } DefineProductCategoryPreviewController(final AdminServiceFacade adminServiceFacade); protected  DefineProductCategoryPreviewController(); @RequestMapping(method = RequestMethod.GET) ModelAndView showPopulatedForm(ProductCategoryFormBean formBean); @RequestMapping(method = RequestMethod.POST) ModelAndView processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel,
            @RequestParam(value = EDIT_PARAM, required = false) String edit,
            @ModelAttribute("formBean") ProductCategoryFormBean bean,
            BindingResult result);  }
@Test public void cancelShouldRedirectToAdminView() throws Exception { ProductCategoryFormBean expectedFormBean = new ProductCategoryFormBean(); ModelAndView returnedView = productCategoryPreviewController.processFormSubmit("Cancel", "", expectedFormBean, bindingResult); Assert.assertThat(returnedView.getViewName(), is(ADMIN_VIEW)); }