### Question:
TppRedirectUriBodyValidatorImpl implements BodyValidator { @Override public MessageError validate(HttpServletRequest request, MessageError messageError) { if (isRedirectScaApproach()) { String tppRedirectUriHeader = request.getHeader(TPP_REDIRECT_URI); Map<String, String> headers = Collections.list(request.getHeaderNames()) .stream() .collect(Collectors.toMap(String::toLowerCase, request::getHeader)); if (!headers.containsKey(TPP_REDIRECT_URI)) { errorBuildingService.enrichMessageError(messageError, TppMessageInformation.of(FORMAT_ERROR_ABSENT_HEADER, TPP_REDIRECT_URI)); } else if (tppRedirectUriHeader == null) { errorBuildingService.enrichMessageError(messageError, TppMessageInformation.of(FORMAT_ERROR_NULL_HEADER, TPP_REDIRECT_URI)); } else if (StringUtils.isBlank(tppRedirectUriHeader)) { errorBuildingService.enrichMessageError(messageError, TppMessageInformation.of(FORMAT_ERROR_BLANK_HEADER, TPP_REDIRECT_URI)); } } return messageError; }  @Override MessageError validate(HttpServletRequest request, MessageError messageError);  }### Answer:
@Test void validate_NotRedirect_success() { when(scaApproachResolver.resolveScaApproach()).thenReturn(ScaApproach.EMBEDDED); tppRedirectUriBodyValidator.validate(request, messageError); verify(scaApproachResolver, times(1)).resolveScaApproach(); assertTrue(messageError.getTppMessages().isEmpty()); }
@Test void validate_RedirectApproach_success() { when(aspspProfileServiceWrapper.getScaRedirectFlow()).thenReturn(ScaRedirectFlow.REDIRECT); when(scaApproachResolver.resolveScaApproach()).thenReturn(ScaApproach.REDIRECT); request.addHeader(TPP_REDIRECT_URI, "some.url"); tppRedirectUriBodyValidator.validate(request, messageError); verify(scaApproachResolver, times(1)).resolveScaApproach(); assertTrue(messageError.getTppMessages().isEmpty()); }
@Test void validate_oAuthApproach_success() { when(aspspProfileServiceWrapper.getScaRedirectFlow()).thenReturn(ScaRedirectFlow.OAUTH); when(scaApproachResolver.resolveScaApproach()).thenReturn(ScaApproach.REDIRECT); tppRedirectUriBodyValidator.validate(request, messageError); verify(scaApproachResolver).resolveScaApproach(); assertTrue(messageError.getTppMessages().isEmpty()); }
@Test void validate_RedirectApproachAndRedirectPreferredHeaderTrue_TppRedirectUriIsBotContain_error() { when(aspspProfileServiceWrapper.getScaRedirectFlow()).thenReturn(ScaRedirectFlow.REDIRECT); when(scaApproachResolver.resolveScaApproach()).thenReturn(ScaApproach.REDIRECT); tppRedirectUriBodyValidator.validate(request, messageError); verify(scaApproachResolver, times(1)).resolveScaApproach(); assertFalse(messageError.getTppMessages().isEmpty()); assertEquals(MessageCategory.ERROR, messageError.getTppMessage().getCategory()); assertEquals(MessageErrorCode.FORMAT_ERROR_ABSENT_HEADER, messageError.getTppMessage().getMessageErrorCode()); }
@Test void validate_RedirectApproachAndRedirectPreferredHeaderTrue_TppRedirectUriIsBlank_error() { when(aspspProfileServiceWrapper.getScaRedirectFlow()).thenReturn(ScaRedirectFlow.REDIRECT); when(scaApproachResolver.resolveScaApproach()).thenReturn(ScaApproach.REDIRECT); request.addHeader(TPP_REDIRECT_URI, ""); tppRedirectUriBodyValidator.validate(request, messageError); verify(scaApproachResolver, times(1)).resolveScaApproach(); assertFalse(messageError.getTppMessages().isEmpty()); assertEquals(MessageCategory.ERROR, messageError.getTppMessage().getCategory()); assertEquals(MessageErrorCode.FORMAT_ERROR_BLANK_HEADER, messageError.getTppMessage().getMessageErrorCode()); }