CompiledResourceCreatorConfiguration { public boolean matches(TerraformResource resource) { return typePattern.matcher(resource.getType()).matches() && providerPattern.matcher(resource.getProviderName()).matches(); } CompiledResourceCreatorConfiguration(ResourceCreatorConfiguration resourceCreatorConfiguration); boolean matches(TerraformResource resource); Collection<VirtualTerraformResource> apply(TerraformResource resource);  }
@Test void matchesShouldReturnTrueIfTypeAndProviderPatternsAreMatching() { ResourceCreatorConfiguration resourceCreatorConfiguration = createMatcherTestConfiguration("provider_.*", "type_.*"); CompiledResourceCreatorConfiguration compiledResourceCreatorConfiguration = new CompiledResourceCreatorConfiguration(resourceCreatorConfiguration); TerraformResource resource = mock(TerraformResource.class); when(resource.getProviderName()).thenReturn("provider_matching"); when(resource.getType()).thenReturn("type_matching"); boolean matches = compiledResourceCreatorConfiguration.matches(resource); assertThat(matches).isTrue(); verify(resource, times(1)).getType(); verify(resource, times(1)).getProviderName(); }
@Test void matchesShouldReturnFalseIfTypePatternDoesNotMatch() { ResourceCreatorConfiguration configuration = createMatcherTestConfiguration("provider_.*", "type_.*"); CompiledResourceCreatorConfiguration compiledResourceCreatorConfiguration = new CompiledResourceCreatorConfiguration(configuration); TerraformResource resource = mock(TerraformResource.class); when(resource.getProviderName()).thenReturn("provider_matching"); when(resource.getType()).thenReturn("type1_not_matching"); boolean matches = compiledResourceCreatorConfiguration.matches(resource); assertThat(matches).isFalse(); verify(resource, times(1)).getType(); }
@Test void matchesShouldReturnFalseIfProviderDoesNotMatch() { ResourceCreatorConfiguration configuration = createMatcherTestConfiguration("provider_.*", "type_.*"); CompiledResourceCreatorConfiguration compiledResourceCreatorConfiguration = new CompiledResourceCreatorConfiguration(configuration); TerraformResource resource = mock(TerraformResource.class); when(resource.getProviderName()).thenReturn("provider1_not_matching"); when(resource.getType()).thenReturn("type_matching"); boolean matches = compiledResourceCreatorConfiguration.matches(resource); assertThat(matches).isFalse(); verify(resource, times(1)).getProviderName(); }