MessageController { @PostMapping("/sendMsg") public String handleMessage(@ModelAttribute Order order, RedirectAttributes redirectAttributes) { try { this.orderMessageSender.sendOrder(order); redirectAttributes.addFlashAttribute("message", "Order message sent successfully"); return "redirect:/"; } catch (JsonProcessingException exc) { throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Unable To Parse " + order.toString(), exc); } }  @PostMapping("/sendMsg") String handleMessage(@ModelAttribute Order order, RedirectAttributes redirectAttributes);  }
@Test void testHandleMessage() throws Exception { willDoNothing().given(this.orderMessageSender).sendOrder(MockObjectCreator.getOrder()); this.mockMvc .perform(post("/sendMsg").content(this.objectMapper.writeValueAsString(MockObjectCreator.getOrder())) .contentType(MediaType.APPLICATION_JSON).with(csrf())) .andExpect(status().isFound()) .andExpect(flash().attribute("message", "Order message sent successfully")) .andExpect(redirectedUrl("/")); }