### Question:
CredentialValidator { public ValidationResult validateAwsCredentialRequest(CredentialRequest credentialRequest) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); resultBuilder.ifError(() -> !CloudPlatform.AWS.name().equalsIgnoreCase(credentialRequest.getCloudPlatform()), "Credential request is not for AWS."); resultBuilder.ifError(() -> StringUtils.isBlank(Optional.ofNullable(credentialRequest.getAws()) .map(AwsCredentialParameters::getRoleBased) .map(RoleBasedParameters::getRoleArn) .orElse(null)), "Role ARN is not found in credential request."); return resultBuilder.build(); } CredentialValidator(@Value("${environment.enabledplatforms}") Set<String> enabledPlatforms,
            CredentialDefinitionService credentialDefinitionService,
            List<ProviderCredentialValidator> providerCredentialValidators,
            EntitlementService entitlementService); void validateParameters(Platform platform, Json json); void validateCredentialCloudPlatform(String cloudPlatform, String userCrn); boolean isCredentialCloudPlatformValid(String cloudPlatform, String accountId); ValidationResult validateCredentialUpdate(Credential original, Credential newCred, CredentialType type); ValidationResult validateAwsCredentialRequest(CredentialRequest credentialRequest);  }### Answer:
@Test void testValidateAwsCredentialRequestNotAWS() { CredentialRequest request = new CredentialRequest(); request.setCloudPlatform("AZURE"); ValidationResult result = underTest.validateAwsCredentialRequest(request); assertTrue(result.hasError()); assertEquals("Credential request is not for AWS.", result.getErrors().get(0)); }
@Test void testValidateAwsCredentialRequestNoAwsParams() { CredentialRequest request = new CredentialRequest(); request.setCloudPlatform("AWS"); ValidationResult result = underTest.validateAwsCredentialRequest(request); assertTrue(result.hasError()); assertEquals("Role ARN is not found in credential request.", result.getErrors().get(0)); }
@Test void testValidateAwsCredentialRequestKeyBased() { CredentialRequest request = new CredentialRequest(); request.setCloudPlatform("AWS"); request.setAws(new AwsCredentialParameters()); ValidationResult result = underTest.validateAwsCredentialRequest(request); assertTrue(result.hasError()); assertEquals("Role ARN is not found in credential request.", result.getErrors().get(0)); }
@Test void testValidateAwsCredentialRequestNoArn() { CredentialRequest request = new CredentialRequest(); request.setCloudPlatform("AWS"); AwsCredentialParameters aws = new AwsCredentialParameters(); aws.setRoleBased(new RoleBasedParameters()); request.setAws(aws); ValidationResult result = underTest.validateAwsCredentialRequest(request); assertTrue(result.hasError()); assertEquals("Role ARN is not found in credential request.", result.getErrors().get(0)); }
@Test void testValidateAwsCredentialRequestValid() { CredentialRequest request = new CredentialRequest(); request.setCloudPlatform("AWS"); AwsCredentialParameters aws = new AwsCredentialParameters(); RoleBasedParameters roleBased = new RoleBasedParameters(); roleBased.setRoleArn("arn"); aws.setRoleBased(roleBased); request.setAws(aws); ValidationResult result = underTest.validateAwsCredentialRequest(request); assertFalse(result.hasError()); }