### Question:
AwsInstanceProfileEC2TrustValidator { boolean checkEC2InPrincipals(List<Principal> principals) { return principals .stream() .anyMatch(principal -> "Service".equals(principal.getProvider()) && Services.AmazonEC2.getServiceId().equals(principal.getId())); }  boolean isTrusted(InstanceProfile instanceProfile, ValidationResultBuilder resultBuilder);  }### Answer:
@Test public void ec2NotInPrincipals() { assertThat(awsInstanceProfileEC2TrustValidator.checkEC2InPrincipals( Collections.singletonList(Principal.All))).isFalse(); assertThat(awsInstanceProfileEC2TrustValidator.checkEC2InPrincipals( Collections.singletonList(Principal.AllServices))).isFalse(); assertThat(awsInstanceProfileEC2TrustValidator.checkEC2InPrincipals( Collections.singletonList(new Principal("Service", "invalid")))).isFalse(); assertThat(awsInstanceProfileEC2TrustValidator.checkEC2InPrincipals( Arrays.asList( Principal.All, Principal.AllServices, new Principal("Service", "invalid") ))).isFalse(); }
@Test public void ec2InPrincipals() { assertThat(awsInstanceProfileEC2TrustValidator.checkEC2InPrincipals(Collections.singletonList( new Principal("Service", Services.AmazonEC2.getServiceId())))).isTrue(); assertThat(awsInstanceProfileEC2TrustValidator.checkEC2InPrincipals( Arrays.asList( Principal.AllServices, new Principal("Service", Services.AmazonEC2.getServiceId()) ))).isTrue(); }