class CompiledResourceCreatorConfiguration {

    public Collection<VirtualTerraformResource> apply(TerraformResource resource) {
        Object values;
        try {
            values = valuesPath.read(resource.getValues());
        } catch (PathNotFoundException e) {
            return Collections.emptyList();
        }

        if (values instanceof List) {
            return createResource(resource, (List<?>)values);
        }
        List<Object> valueList = new ArrayList<>();
        valueList.add(values);
        return createResource(resource, valueList);
    }

}

class CompiledResourceCreatorConfigurationTest {

    private static final Gson GSON;

    @Test
    void applyShouldReturnOneResourceIfValueSelectorMatchesOneElmentThatContainsThePropertySelectedByTheNameSelector() {

        // Arrange
        ResourceCreatorConfiguration configuration = createSelectorTestConfiguration("$.name", "$.tmp");
        CompiledResourceCreatorConfiguration compiledResourceCreatorConfiguration = new CompiledResourceCreatorConfiguration(configuration);
        TerraformResource terraformResource = mockSelectorTestResource("{ \"foo\": \"bar\", \"tmp\": { \"a\": 1, \"b\": 2, \"name\": \"i am a name\" } }");

        // Act
        Collection<VirtualTerraformResource> results = compiledResourceCreatorConfiguration.apply(terraformResource);

        // Verrify
        assertThat(results).hasSize(1);
        Optional<VirtualTerraformResource> resourceOptional = results.stream().findFirst();
        assertThat(resourceOptional).isPresent();
        VirtualTerraformResource resource = resourceOptional.get();
        assertThat(resource.getOriginalResource()).isSameAs(terraformResource);
        assertThat(resource.getName()).isEqualTo("i am a name");
        Map<String, Object> values = resource.getValues();
        assertThat(values.get("a")).isEqualTo(1d);
        assertThat(values.get("b")).isEqualTo(2d);
        assertThat(values.get("name")).isEqualTo(resource.getName());
    }

}