### Question:
IndexTemplate { public String getSource() { return this.source; } protected  IndexTemplate(String name, String source); String getName(); String getSource(); @PluginBuilderFactory static IndexTemplate.Builder newBuilder(); static final String PLUGIN_NAME; static final String ELEMENT_TYPE; }### Answer:
@Test public void builderResolvesSourceWithValueResolverIfProvided() { String var1Name = UUID.randomUUID().toString(); String var1Value = UUID.randomUUID().toString(); String var2Name = UUID.randomUUID().toString(); String var2Value = UUID.randomUUID().toString(); System.setProperty(var1Name, var1Value); System.setProperty(var2Name, var2Value); String expected = String.format("{\n\t\"%s: \"%s\",\n\t\"%s: \"%s\"}", var1Name, var1Value, var2Name, var2Value); String source = String.format("{\n\t\"%s: \"%s\",\n\t\"%s: \"%s\"}", var1Name, String.format("${sys:%s}", var1Name), var2Name, String.format("${sys:%s}", var2Name)); IndexTemplate.Builder builder = createTestIndexTemplateBuilder() .withPath(null) .withSource(source) .withValueResolver(defaultTestValueResolver()); IndexTemplate template = builder.build(); assertEquals(expected, template.getSource()); }
@Test public void builderResolvesSourceIfValueResolverNotProvidedAndConfigurationProvided() { String var1Name = UUID.randomUUID().toString(); String var1Value = UUID.randomUUID().toString(); String var2Name = UUID.randomUUID().toString(); String var2Value = UUID.randomUUID().toString(); System.setProperty(var1Name, var1Value); System.setProperty(var2Name, var2Value); String expected = String.format("{\n\t\"%s: \"%s\",\n\t\"%s: \"%s\"}", var1Name, var1Value, var2Name, var2Value); String source = String.format("{\n\t\"%s: \"%s\",\n\t\"%s: \"%s\"}", var1Name, String.format("${sys:%s}", var1Name), var2Name, String.format("${sys:%s}", var2Name)); IndexTemplate.Builder builder = createTestIndexTemplateBuilder() .withPath(null) .withSource(source) .withConfiguration(LoggerContext.getContext(false).getConfiguration()); IndexTemplate template = builder.build(); assertEquals(expected, template.getSource()); }
@Test public void builderResolvesSourceWithNoopResolverIfValueResolverNotProvidedAndConfigurationNotProvided() { String var1Name = UUID.randomUUID().toString(); String var1Value = UUID.randomUUID().toString(); String var2Name = UUID.randomUUID().toString(); String var2Value = UUID.randomUUID().toString(); System.setProperty(var1Name, var1Value); System.setProperty(var2Name, var2Value); String source = String.format("{\n\t\"%s: \"%s\",\n\t\"%s: \"%s\"}", var1Name, String.format("${sys:%s}", var1Name), var2Name, String.format("${sys:%s}", var2Name)); IndexTemplate.Builder builder = createTestIndexTemplateBuilder() .withPath(null) .withSource(source) .withConfiguration(null) .withValueResolver(null); IndexTemplate template = builder.build(); assertEquals(source, template.getSource()); }