### Question:
CredentialValidator { public ValidationResult validateCredentialUpdate(Credential original, Credential newCred, CredentialType type) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); if (!original.getCloudPlatform().equals(newCred.getCloudPlatform())) { resultBuilder.error(String.format("CloudPlatform of the credential cannot be changed! Original: '%s' New: '%s'.", original.getCloudPlatform(), newCred.getCloudPlatform())); return resultBuilder.build(); } if (original.getType() != null && !type.equals(original.getType())) { resultBuilder.error(String.format("Credential type must be %s type and the current is %s.", type, original.getType())); return resultBuilder.build(); } return Optional.ofNullable(providerValidators.get(newCred.getCloudPlatform())) .map(validator -> validator.validateUpdate(original, newCred, resultBuilder)) .orElse(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 testValidateCredentialUpdate() { Credential original = new Credential(); original.setCloudPlatform(CloudPlatform.AWS.name()); Credential newCred = new Credential(); newCred.setCloudPlatform(CloudPlatform.AWS.name()); ValidationResult result = underTest.validateCredentialUpdate(original, newCred, CredentialType.ENVIRONMENT); assertFalse(result.hasError()); }
@Test void testValidateCredentialUpdateWhenInvalidPlatformChange() { Credential original = new Credential(); original.setCloudPlatform(CloudPlatform.AWS.name()); Credential newCred = new Credential(); newCred.setCloudPlatform(CloudPlatform.AZURE.name()); ValidationResult result = underTest.validateCredentialUpdate(original, newCred, CredentialType.ENVIRONMENT); assertEquals(1, result.getErrors().size()); assertThat(result.getErrors().get(0)).contains("CloudPlatform of the credential cannot be changed! Original: 'AWS' New: 'AZURE'."); }