### Question:
TransactionStatusAcceptHeaderValidator { public ValidationResult validate(@NotNull String acceptHeader) { if (acceptHeader.equalsIgnoreCase(MediaType.ALL_VALUE)) { return ValidationResult.valid(); } List<String> supportedTransactionStatusFormats = aspspProfileServiceWrapper.getSupportedTransactionStatusFormats(); if (!isMediaTypeSupported(acceptHeader, supportedTransactionStatusFormats)) { return ValidationResult.invalid(ErrorType.PIS_406, REQUESTED_FORMATS_INVALID); } return ValidationResult.valid(); }  ValidationResult validate(@NotNull String acceptHeader);  }### Answer:
@Test void validate_withSupportedHeader_shouldReturnValid() { when(aspspProfileServiceWrapper.getSupportedTransactionStatusFormats()) .thenReturn(Collections.singletonList(JSON_MEDIA_TYPE)); ValidationResult validationResult = transactionStatusAcceptHeaderValidator.validate(ACCEPT_HEADER_JSON); verify(aspspProfileServiceWrapper).getSupportedTransactionStatusFormats(); assertTrue(validationResult.isValid()); assertNull(validationResult.getMessageError()); }
@Test void validate_withMixedSupportedHeader_shouldReturnValid() { when(aspspProfileServiceWrapper.getSupportedTransactionStatusFormats()) .thenReturn(Collections.singletonList(JSON_MEDIA_TYPE)); ValidationResult validationResult = transactionStatusAcceptHeaderValidator.validate(ACCEPT_HEADER_JSON_XML); verify(aspspProfileServiceWrapper).getSupportedTransactionStatusFormats(); assertTrue(validationResult.isValid()); assertNull(validationResult.getMessageError()); }
@Test void validate_withWildcardHeader_shouldReturnValid() { ValidationResult validationResult = transactionStatusAcceptHeaderValidator.validate(ACCEPT_HEADER_WILDCARD); assertTrue(validationResult.isValid()); assertNull(validationResult.getMessageError()); }
@Test void validate_withEmptyListInProfile_shouldReturnValid() { when(aspspProfileServiceWrapper.getSupportedTransactionStatusFormats()) .thenReturn(Collections.emptyList()); ValidationResult validationResult = transactionStatusAcceptHeaderValidator.validate(ACCEPT_HEADER_JSON_XML); verify(aspspProfileServiceWrapper).getSupportedTransactionStatusFormats(); assertTrue(validationResult.isValid()); assertNull(validationResult.getMessageError()); }
@Test void validate_withNotSupportedHeader_shouldReturnValidationError() { when(aspspProfileServiceWrapper.getSupportedTransactionStatusFormats()) .thenReturn(Collections.singletonList(JSON_MEDIA_TYPE)); ValidationResult validationResult = transactionStatusAcceptHeaderValidator.validate(ACCEPT_HEADER_XML); verify(aspspProfileServiceWrapper).getSupportedTransactionStatusFormats(); assertTrue(validationResult.isNotValid()); assertEquals(VALIDATION_ERROR, validationResult.getMessageError()); }
@Test void validate_multipleAcceptHeaders() { when(aspspProfileServiceWrapper.getSupportedTransactionStatusFormats()) .thenReturn(Collections.singletonList(JSON_MEDIA_TYPE)); ValidationResult validationResult = transactionStatusAcceptHeaderValidator.validate("application/xml, application/json"); verify(aspspProfileServiceWrapper).getSupportedTransactionStatusFormats(); assertTrue(validationResult.isValid()); }
@Test void validate_multipleAcceptHeaders_caseSensitive() { when(aspspProfileServiceWrapper.getSupportedTransactionStatusFormats()) .thenReturn(Collections.singletonList(JSON_MEDIA_TYPE)); ValidationResult validationResult = transactionStatusAcceptHeaderValidator.validate(" application/xml, application/JSON"); verify(aspspProfileServiceWrapper).getSupportedTransactionStatusFormats(); assertTrue(validationResult.isValid()); }