### Question:
PsuDataInInitialRequestValidator implements BusinessValidator<PsuIdData> { @Override public @NotNull ValidationResult validate(@NotNull PsuIdData psuIdData) { String psuId = psuIdData.getPsuId(); if (aspspProfileService.isPsuInInitialRequestMandated() && StringUtils.isBlank(psuId)) { ErrorType errorType = errorTypeMapper.mapToErrorType(serviceTypeDiscoveryService.getServiceType(), FORMAT_ERROR.getCode()); if (psuId == null) { log.info("PSU Data validation has failed: mandated PSU ID is null"); return ValidationResult.invalid(errorType, FORMAT_ERROR_NO_PSU_ID); } log.info("PSU Data validation has failed: mandated PSU ID is blank"); return ValidationResult.invalid(errorType, FORMAT_ERROR_PSU_ID_BLANK); } return ValidationResult.valid(); }  @Override @NotNull ValidationResult validate(@NotNull PsuIdData psuIdData);  }### Answer:
@Test void validate_withPsuDataNotMandated_shouldReturnValid() { ValidationResult validationResult = psuDataInInitialRequestValidator.validate(EMPTY_PSU_DATA); assertTrue(validationResult.isValid()); }
@Test void validate_withPsuDataMandatedAndValidPsuData_shouldReturnValid() { when(aspspProfileService.isPsuInInitialRequestMandated()).thenReturn(true); ValidationResult validationResult = psuDataInInitialRequestValidator.validate(PSU_DATA); assertTrue(validationResult.isValid()); }
@Test void validate_withPsuDataMandatedAndBlankPsuId_shouldReturnFormatError() { when(aspspProfileService.isPsuInInitialRequestMandated()).thenReturn(true); PsuIdData psuIdData = new PsuIdData(" ", null, null, null, null); when(serviceTypeDiscoveryService.getServiceType()).thenReturn(SERVICE_TYPE); when(errorTypeMapper.mapToErrorType(SERVICE_TYPE, FORMAT_ERROR.getCode())).thenReturn(ErrorType.AIS_400); ValidationResult validationResult = psuDataInInitialRequestValidator.validate(psuIdData); verify(serviceTypeDiscoveryService).getServiceType(); verify(errorTypeMapper).mapToErrorType(SERVICE_TYPE, FORMAT_ERROR.getCode()); assertTrue(validationResult.isNotValid()); assertEquals(BLANK_PSU_ID_ERROR, validationResult.getMessageError()); }
@Test void validate_withPsuDataMandatedAndNullPsuId_shouldReturnFormatError() { when(aspspProfileService.isPsuInInitialRequestMandated()).thenReturn(true); PsuIdData psuIdData = new PsuIdData(null, null, null, null, null); when(serviceTypeDiscoveryService.getServiceType()).thenReturn(SERVICE_TYPE); when(errorTypeMapper.mapToErrorType(SERVICE_TYPE, FORMAT_ERROR.getCode())).thenReturn(ErrorType.AIS_400); ValidationResult validationResult = psuDataInInitialRequestValidator.validate(psuIdData); verify(serviceTypeDiscoveryService).getServiceType(); verify(errorTypeMapper).mapToErrorType(SERVICE_TYPE, FORMAT_ERROR.getCode()); assertTrue(validationResult.isNotValid()); assertEquals(NULL_PSU_ID_ERROR, validationResult.getMessageError()); }