WorldpayChoosePaymentMethodCheckoutStepController extends AbstractWorldpayPaymentMethodCheckoutStepController { protected boolean addGlobalErrors(final Model model, final BindingResult bindingResult) { if (bindingResult.hasGlobalErrors()) { GlobalMessages.addErrorMessage(model, bindingResult.getGlobalErrors().get(0).getCode()); return true; } if (bindingResult.hasErrors()) { GlobalMessages.addErrorMessage(model, CHECKOUT_BILLING_ADDRESS_PAGE_GLOBAL_FIELD_ERROR); return true; } return false; }  @Override @RequestMapping(method = GET, value = {"", "/", "/add-cse-payment-details", "/add-payment-details"}) @RequireHardLogIn @PreValidateCheckoutStep(checkoutStep = CHOOSE_PAYMENT_METHOD) String enterStep(final Model model, final RedirectAttributes redirectAttributes); @RequestMapping(value = "/getDeclineMessage", method = GET) @ResponseBody String getDeclineMessage(); @RequestMapping(value = "/choose", method = GET) @RequireHardLogIn String doSelectPaymentMethod(@RequestParam("selectedPaymentMethodId") final String selectedPaymentMethodId); @ModelAttribute(value = "getTermsAndConditionsUrl") String getTermsAndConditionsUrl(final HttpServletRequest request); @RequestMapping(value = "/remove", method = POST) @RequireHardLogIn String remove(@RequestParam(value = "paymentInfoId") final String paymentMethodId,
                         final RedirectAttributes redirectAttributes); @RequestMapping(value = "/back", method = GET) @RequireHardLogIn @Override String back(final RedirectAttributes redirectAttributes); @RequestMapping(value = "/next", method = GET) @RequireHardLogIn @Override String next(final RedirectAttributes redirectAttributes); String getRedirectToPaymentMethod(); PaymentDetailsFormValidator getPaymentDetailsFormValidator(); MessageSource getThemeSource();  }
@Test public void shouldAddGlobalError() { when(bindingResultMock.hasGlobalErrors()).thenReturn(true); when(bindingResultMock.getGlobalErrors()).thenReturn(singletonList(objectErrorMock)); final boolean result = testObj.addGlobalErrors(modelMock, bindingResultMock); verify(modelMock).addAttribute(eq(ERROR_MESSAGES_HOLDER), any(GlobalMessage.class)); assertTrue(result); }
@Test public void shouldAddError() { when(bindingResultMock.hasErrors()).thenReturn(true); final boolean result = testObj.addGlobalErrors(modelMock, bindingResultMock); verify(modelMock).addAttribute(eq(ERROR_MESSAGES_HOLDER), any(GlobalMessage.class)); assertTrue(result); }