### Question:
ConstraintValidatorImpl implements ConstraintValidator { @Override public ResourceMatchUsing verifyResources(final Set<String> resources) { return new ResourceMatchUsing() { @Override public AgainstResourceType using(final ResourceName resourceHandler) { return new AgainstResourceType() { @Override public ConstraintResult against(ResourceType resourceType) { return verifyResources(resources, resourceHandler, resourceType); } }; } }; }  @Override ResourceMatchUsing verifyResources(final Set<String> resources); @Override AgainstResourceType verifyActions(final Set<String> actions);  }### Answer:
@Test public void validResourceWithoutPortNumberPass() { ResourceType resourceType = ResourceType .builder() .setName("test") .setUUID("abc") .addPattern("http: .build(); Set<String> resources = CollectionUtils .asSet("http: boolean successful = validator .verifyResources(resources) .using(new URLResourceName()) .against(resourceType) .isSuccessful(); assertThat(successful).isTrue(); }
@Test public void validResourceWithPortNumberPass() { ResourceType resourceType = ResourceType .builder() .setName("test") .setUUID("abc") .addPattern("http: .build(); Set<String> resources = CollectionUtils .asSet("http: boolean successful = validator .verifyResources(resources) .using(new URLResourceName()) .against(resourceType) .isSuccessful(); assertThat(successful).isTrue(); }
@Test public void validResourceWithPortNumberAndURLWithoutPortNumberPass() { ResourceType resourceType = ResourceType .builder() .setName("test") .setUUID("abc") .addPattern("http: .build(); Set<String> resources = CollectionUtils .asSet("http: boolean successful = validator .verifyResources(resources) .using(new URLResourceName()) .against(resourceType) .isSuccessful(); assertThat(successful).isTrue(); }
@Test public void validResourcesPass() { ResourceType resourceType = ResourceType .builder() .setName("test") .setUUID("abc") .addPattern("a: .build(); Set<String> resources = CollectionUtils .asSet("a: boolean successful = validator .verifyResources(resources) .using(new URLResourceName()) .against(resourceType) .isSuccessful(); assertThat(successful).isTrue(); }
@Test public void invalidResourcesFail() { ResourceType resourceType = ResourceType .builder() .setName("test") .setUUID("abc") .addPattern("a: .build(); Set<String> resources = CollectionUtils .asSet("a: boolean successful = validator .verifyResources(resources) .using(new URLResourceName()) .against(resourceType) .isSuccessful(); assertThat(successful).isFalse(); }
@Test(expectedExceptions = ConstraintFailureException.class, expectedExceptionsMessageRegExp = "Invalid value fail: public void throwsExceptionWhenResourcesFail() throws ConstraintFailureException { ResourceType resourceType = ResourceType .builder() .setName("test") .setUUID("abc") .addPattern("a: .build(); Set<String> resources = CollectionUtils .asSet("a: validator .verifyResources(resources) .using(new URLResourceName()) .against(resourceType) .throwExceptionIfFailure(); }