CustomerController { @RequestMapping(value = "/customers/createCustomer", method = RequestMethod.POST) public ModelAndView createCustomer( @Valid @ModelAttribute("createCustomerForm") Customer customer, BindingResult result) { ModelAndView modelAndView = new ModelAndView(); if(result.hasErrors()) { modelAndView.setViewName("customers/customers-createCustomer"); return modelAndView; } logger.debug(customer.toString()); customer.getCustomerPaymentDetail().setCustomer(customer); Customer customerAdded = customerService.addCustomer(customer); if(customerAdded != null) { logger.info("Successfully added customer"); modelAndView.addObject("submittedCustomerForm", customer); modelAndView.setViewName("redirect:/customers/" + customer.getCustomerId()); } else { logger.warn("Unable to add customer"); } return modelAndView; }  @RequestMapping(value = "/customers/create", method = RequestMethod.GET) String showCreateCustomerFormPage(ModelMap modelMap); @RequestMapping(value = "/customers/createCustomer", method = RequestMethod.POST) ModelAndView createCustomer(
			@Valid @ModelAttribute("createCustomerForm") Customer customer,
			BindingResult result); @RequestMapping(value = "/customers", method = RequestMethod.GET) String listCustomers(ModelMap modelMap);  }
@Test public void testCreateCustomer() { Customer customer = new Customer(); customer.setCustomerId(1); customer.setCustomerPaymentDetail(new CustomerPaymentDetail()); Mockito.when(customerService.addCustomer(Matchers.any(Customer.class))) .thenReturn(customer); ModelAndView modelAndView = customerController.createCustomer(customer, new DirectFieldBindingResult(null, "")); assertEquals("redirect:/customers/1", modelAndView.getViewName()); }