@Test public void testCreateOrder_Succss() { Order order = new Order(); Mockito.doNothing().when(orderFormValidator) .validate(Matchers.anyObject(), Matchers.any(Errors.class)); Mockito.when(orderService.addOrder(order)).thenReturn(true); ModelAndView modelAndView = orderController.createOrder(order, new DirectFieldBindingResult(null, "")); assertNotNull(modelAndView); assertEquals("orders-createOrderSuccess", modelAndView.getViewName()); }
@RequestMapping(value = "orders/createOrder", method = RequestMethod.POST) public ModelAndView createOrder(@ModelAttribute("createOrderForm") Order order, BindingResult result) { ModelAndView modelAndView = new ModelAndView(); orderFormValidator.validate(order, result); if(result.hasErrors()) { modelAndView.setViewName("orders/orders-createOrder"); } else { if(orderService.addOrder(order)) { modelAndView.setViewName("orders-createOrderSuccess"); } } return modelAndView; }
OrderController { @RequestMapping(value = "orders/createOrder", method = RequestMethod.POST) public ModelAndView createOrder(@ModelAttribute("createOrderForm") Order order, BindingResult result) { ModelAndView modelAndView = new ModelAndView(); orderFormValidator.validate(order, result); if(result.hasErrors()) { modelAndView.setViewName("orders/orders-createOrder"); } else { if(orderService.addOrder(order)) { modelAndView.setViewName("orders-createOrderSuccess"); } } return modelAndView; } }
OrderController { @RequestMapping(value = "orders/createOrder", method = RequestMethod.POST) public ModelAndView createOrder(@ModelAttribute("createOrderForm") Order order, BindingResult result) { ModelAndView modelAndView = new ModelAndView(); orderFormValidator.validate(order, result); if(result.hasErrors()) { modelAndView.setViewName("orders/orders-createOrder"); } else { if(orderService.addOrder(order)) { modelAndView.setViewName("orders-createOrderSuccess"); } } return modelAndView; }  }
OrderController { @RequestMapping(value = "orders/createOrder", method = RequestMethod.POST) public ModelAndView createOrder(@ModelAttribute("createOrderForm") Order order, BindingResult result) { ModelAndView modelAndView = new ModelAndView(); orderFormValidator.validate(order, result); if(result.hasErrors()) { modelAndView.setViewName("orders/orders-createOrder"); } else { if(orderService.addOrder(order)) { modelAndView.setViewName("orders-createOrderSuccess"); } } return modelAndView; }  @RequestMapping(value = "/orders/create", method=RequestMethod.GET) String showCreateOrdersForm(ModelMap modelMap, @RequestParam("customerId") int customerId); @RequestMapping(value = "orders/createOrder", method = RequestMethod.POST) ModelAndView createOrder(@ModelAttribute("createOrderForm") Order order, BindingResult result); @RequestMapping(value="/orders", method=RequestMethod.GET) String listOrders(ModelMap modelMap); }
OrderController { @RequestMapping(value = "orders/createOrder", method = RequestMethod.POST) public ModelAndView createOrder(@ModelAttribute("createOrderForm") Order order, BindingResult result) { ModelAndView modelAndView = new ModelAndView(); orderFormValidator.validate(order, result); if(result.hasErrors()) { modelAndView.setViewName("orders/orders-createOrder"); } else { if(orderService.addOrder(order)) { modelAndView.setViewName("orders-createOrderSuccess"); } } return modelAndView; }  @RequestMapping(value = "/orders/create", method=RequestMethod.GET) String showCreateOrdersForm(ModelMap modelMap, @RequestParam("customerId") int customerId); @RequestMapping(value = "orders/createOrder", method = RequestMethod.POST) ModelAndView createOrder(@ModelAttribute("createOrderForm") Order order, BindingResult result); @RequestMapping(value="/orders", method=RequestMethod.GET) String listOrders(ModelMap modelMap);  }