freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [2/4] incubator-freemarker git commit: Made TemplateConfiguration immutable, added a TemplateConfiguration.Builder. (This is not the final version of TemplateConfiguration; it will be become cleaner as Template also becomes immutable.)
Date Wed, 05 Apr 2017 19:55:48 GMT
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/88baea20/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/OutputFormatTest.java b/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
index 04816f2..224e953 100644
--- a/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
+++ b/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
@@ -115,15 +115,15 @@ public class OutputFormatTest extends TemplateTest {
             case 3:
                 cfgOutputFormat = UndefinedOutputFormat.INSTANCE;
                 cfg.unsetOutputFormat();
-                TemplateConfiguration tcXml = new TemplateConfiguration();
-                tcXml.setOutputFormat(XMLOutputFormat.INSTANCE);
+                TemplateConfiguration.Builder tcbXML = new TemplateConfiguration.Builder();
+                tcbXML.setOutputFormat(XMLOutputFormat.INSTANCE);
                 cfg.setTemplateConfigurations(
                         new ConditionalTemplateConfigurationFactory(
                                 new OrMatcher(
                                         new FileNameGlobMatcher("*.ftlh"),
                                         new FileNameGlobMatcher("*.FTLH"),
                                         new FileNameGlobMatcher("*.fTlH")),
-                                tcXml));
+                                tcbXML.build()));
                 ftlhOutputFormat = HTMLOutputFormat.INSTANCE; // can't be overidden
                 ftlxOutputFormat = XMLOutputFormat.INSTANCE;
                 break;
@@ -174,15 +174,15 @@ public class OutputFormatTest extends TemplateTest {
         addTemplate("t.ftl",
                 "${'{}'} ${'{}'?esc} ${'{}'?noEsc}");
         
-        TemplateConfiguration tcHTML = new TemplateConfiguration();
-        tcHTML.setOutputFormat(HTMLOutputFormat.INSTANCE);
+        TemplateConfiguration.Builder tcbHTML = new TemplateConfiguration.Builder();
+        tcbHTML.setOutputFormat(HTMLOutputFormat.INSTANCE);
         ConditionalTemplateConfigurationFactory tcfHTML = new ConditionalTemplateConfigurationFactory(
-                new FileNameGlobMatcher("t.*"), tcHTML);
+                new FileNameGlobMatcher("t.*"), tcbHTML.build());
 
-        TemplateConfiguration tcNoAutoEsc = new TemplateConfiguration();
-        tcNoAutoEsc.setAutoEscapingPolicy(Configuration.DISABLE_AUTO_ESCAPING_POLICY);
+        TemplateConfiguration.Builder tcbNoAutoEsc = new TemplateConfiguration.Builder();
+        tcbNoAutoEsc.setAutoEscapingPolicy(Configuration.DISABLE_AUTO_ESCAPING_POLICY);
         ConditionalTemplateConfigurationFactory tcfNoAutoEsc = new ConditionalTemplateConfigurationFactory(
-                new FileNameGlobMatcher("t.*"), tcNoAutoEsc);
+                new FileNameGlobMatcher("t.*"), tcbNoAutoEsc.build());
 
         Configuration cfg = getConfiguration();
         cfg.setOutputFormat(HTMLOutputFormat.INSTANCE);
@@ -1007,10 +1007,10 @@ public class OutputFormatTest extends TemplateTest {
     protected Configuration createConfiguration() throws TemplateModelException {
         Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
         
-        TemplateConfiguration xmlTC = new TemplateConfiguration();
-        xmlTC.setOutputFormat(XMLOutputFormat.INSTANCE);
+        TemplateConfiguration.Builder tcbXML = new TemplateConfiguration.Builder();
+        tcbXML.setOutputFormat(XMLOutputFormat.INSTANCE);
         cfg.setTemplateConfigurations(
-                new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*.xml"), xmlTC));
+                new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*.xml"), tcbXML.build()));
 
         cfg.setSharedVariable("rtfPlain", RTFOutputFormat.INSTANCE.fromPlainTextByEscaping("\\par a & b"));
         cfg.setSharedVariable("rtfMarkup", RTFOutputFormat.INSTANCE.fromMarkup("\\par c"));

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/88baea20/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java b/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java
index 7cbb0f6..6f6b7f3 100644
--- a/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java
+++ b/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java
@@ -198,11 +198,12 @@ public class TemplateConfigurationTest {
                 + "Set";
     }
 
-    public static List<PropertyDescriptor> getTemplateConfigurationSettingPropDescs(boolean includeCompilerSettings)
+    public static List<PropertyDescriptor> getTemplateConfigurationSettingPropDescs(
+            Class<? extends ProcessingConfiguration> confClass, boolean includeCompilerSettings)
             throws IntrospectionException {
         List<PropertyDescriptor> settingPropDescs = new ArrayList<>();
 
-        BeanInfo beanInfo = Introspector.getBeanInfo(TemplateConfiguration.class);
+        BeanInfo beanInfo = Introspector.getBeanInfo(confClass);
         for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
             String name = pd.getName();
             if (pd.getWriteMethod() != null && !IGNORED_PROP_NAMES.contains(name)
@@ -281,24 +282,26 @@ public class TemplateConfigurationTest {
 
     @Test
     public void testMergeBasicFunctionality() throws Exception {
-        for (PropertyDescriptor propDesc1 : getTemplateConfigurationSettingPropDescs(true)) {
-            for (PropertyDescriptor propDesc2 : getTemplateConfigurationSettingPropDescs(true)) {
-                TemplateConfiguration tc1 = new TemplateConfiguration();
-                TemplateConfiguration tc2 = new TemplateConfiguration();
+        for (PropertyDescriptor propDesc1 : getTemplateConfigurationSettingPropDescs(
+                TemplateConfiguration.Builder.class, true)) {
+            for (PropertyDescriptor propDesc2 : getTemplateConfigurationSettingPropDescs(
+                    TemplateConfiguration.Builder.class, true)) {
+                TemplateConfiguration.Builder tcb1 = new TemplateConfiguration.Builder();
+                TemplateConfiguration.Builder tcb2 = new TemplateConfiguration.Builder();
 
                 Object value1 = SETTING_ASSIGNMENTS.get(propDesc1.getName());
-                propDesc1.getWriteMethod().invoke(tc1, value1);
+                propDesc1.getWriteMethod().invoke(tcb1, value1);
                 Object value2 = SETTING_ASSIGNMENTS.get(propDesc2.getName());
-                propDesc2.getWriteMethod().invoke(tc2, value2);
+                propDesc2.getWriteMethod().invoke(tcb2, value2);
 
-                tc1.merge(tc2);
+                tcb1.merge(tcb2);
                 if (propDesc1.getName().equals(propDesc2.getName()) && value1 instanceof List
                         && !propDesc1.getName().equals("autoIncludes")) {
                     assertEquals("For " + propDesc1.getName(),
-                            ListUtils.union((List) value1, (List) value1), propDesc1.getReadMethod().invoke(tc1));
+                            ListUtils.union((List) value1, (List) value1), propDesc1.getReadMethod().invoke(tcb1));
                 } else { // Values of the same setting merged
-                    assertEquals("For " + propDesc1.getName(), value1, propDesc1.getReadMethod().invoke(tc1));
-                    assertEquals("For " + propDesc2.getName(), value2, propDesc2.getReadMethod().invoke(tc1));
+                    assertEquals("For " + propDesc1.getName(), value1, propDesc1.getReadMethod().invoke(tcb1));
+                    assertEquals("For " + propDesc2.getName(), value2, propDesc2.getReadMethod().invoke(tcb1));
                 }
             }
         }
@@ -306,7 +309,7 @@ public class TemplateConfigurationTest {
     
     @Test
     public void testMergeMapSettings() throws Exception {
-        TemplateConfiguration tc1 = new TemplateConfiguration();
+        TemplateConfiguration.Builder tc1 = new TemplateConfiguration.Builder();
         tc1.setCustomDateFormats(ImmutableMap.of(
                 "epoch", EpochMillisTemplateDateFormatFactory.INSTANCE,
                 "x", LocAndTZSensitiveTemplateDateFormatFactory.INSTANCE));
@@ -315,7 +318,7 @@ public class TemplateConfigurationTest {
                 "x", LocaleSensitiveTemplateNumberFormatFactory.INSTANCE));
         tc1.setAutoImports(ImmutableMap.of("a", "a1.ftl", "b", "b1.ftl"));
         
-        TemplateConfiguration tc2 = new TemplateConfiguration();
+        TemplateConfiguration.Builder tc2 = new TemplateConfiguration.Builder();
         tc2.setCustomDateFormats(ImmutableMap.of(
                 "loc", LocAndTZSensitiveTemplateDateFormatFactory.INSTANCE,
                 "x", EpochMillisDivTemplateDateFormatFactory.INSTANCE));
@@ -342,12 +345,12 @@ public class TemplateConfigurationTest {
         assertEquals("c2.ftl", mergedAutoImports.get("c"));
         
         // Empty map merging optimization:
-        tc1.merge(new TemplateConfiguration());
+        tc1.merge(new TemplateConfiguration.Builder());
         assertSame(mergedCustomDateFormats, tc1.getCustomDateFormats());
         assertSame(mergedCustomNumberFormats, tc1.getCustomNumberFormats());
         
         // Empty map merging optimization:
-        TemplateConfiguration tc3 = new TemplateConfiguration();
+        TemplateConfiguration.Builder tc3 = new TemplateConfiguration.Builder();
         tc3.merge(tc1);
         assertSame(mergedCustomDateFormats, tc3.getCustomDateFormats());
         assertSame(mergedCustomNumberFormats, tc3.getCustomNumberFormats());
@@ -355,10 +358,10 @@ public class TemplateConfigurationTest {
     
     @Test
     public void testMergeListSettings() throws Exception {
-        TemplateConfiguration tc1 = new TemplateConfiguration();
+        TemplateConfiguration.Builder tc1 = new TemplateConfiguration.Builder();
         tc1.setAutoIncludes(ImmutableList.of("a.ftl", "x.ftl", "b.ftl"));
         
-        TemplateConfiguration tc2 = new TemplateConfiguration();
+        TemplateConfiguration.Builder tc2 = new TemplateConfiguration.Builder();
         tc2.setAutoIncludes(ImmutableList.of("c.ftl", "x.ftl", "d.ftl"));
         
         tc1.merge(tc2);
@@ -368,16 +371,16 @@ public class TemplateConfigurationTest {
     
     @Test
     public void testMergePriority() throws Exception {
-        TemplateConfiguration tc1 = new TemplateConfiguration();
+        TemplateConfiguration.Builder tc1 = new TemplateConfiguration.Builder();
         tc1.setDateFormat("1");
         tc1.setTimeFormat("1");
         tc1.setDateTimeFormat("1");
 
-        TemplateConfiguration tc2 = new TemplateConfiguration();
+        TemplateConfiguration.Builder tc2 = new TemplateConfiguration.Builder();
         tc2.setDateFormat("2");
         tc2.setTimeFormat("2");
 
-        TemplateConfiguration tc3 = new TemplateConfiguration();
+        TemplateConfiguration.Builder tc3 = new TemplateConfiguration.Builder();
         tc3.setDateFormat("3");
 
         tc1.merge(tc2);
@@ -390,7 +393,7 @@ public class TemplateConfigurationTest {
     
     @Test
     public void testMergeCustomAttributes() throws Exception {
-        TemplateConfiguration tc1 = new TemplateConfiguration();
+        TemplateConfiguration.Builder tc1 = new TemplateConfiguration.Builder();
         tc1.setCustomAttribute("k1", "v1");
         tc1.setCustomAttribute("k2", "v1");
         tc1.setCustomAttribute("k3", "v1");
@@ -398,13 +401,13 @@ public class TemplateConfigurationTest {
         tc1.setCustomAttribute(CA2, "V1");
         tc1.setCustomAttribute(CA3, "V1");
 
-        TemplateConfiguration tc2 = new TemplateConfiguration();
+        TemplateConfiguration.Builder tc2 = new TemplateConfiguration.Builder();
         tc2.setCustomAttribute("k1", "v2");
         tc2.setCustomAttribute("k2", "v2");
         tc2.setCustomAttribute(CA1, "V2");
         tc2.setCustomAttribute(CA2, "V2");
 
-        TemplateConfiguration tc3 = new TemplateConfiguration();
+        TemplateConfiguration.Builder tc3 = new TemplateConfiguration.Builder();
         tc3.setCustomAttribute("k1", "v3");
         tc3.setCustomAttribute(CA1, "V3");
 
@@ -421,7 +424,7 @@ public class TemplateConfigurationTest {
 
     @Test
     public void testMergeNullCustomAttributes() throws Exception {
-        TemplateConfiguration tc1 = new TemplateConfiguration();
+        TemplateConfiguration.Builder tc1 = new TemplateConfiguration.Builder();
         tc1.setCustomAttribute("k1", "v1");
         tc1.setCustomAttribute("k2", "v1");
         tc1.setCustomAttribute(CA1, "V1");
@@ -434,13 +437,13 @@ public class TemplateConfigurationTest {
         assertEquals("V1", tc1.getCustomAttribute(CA2));
         assertNull(tc1.getCustomAttribute(CA3));
 
-        TemplateConfiguration tc2 = new TemplateConfiguration();
+        TemplateConfiguration.Builder tc2 = new TemplateConfiguration.Builder();
         tc2.setCustomAttribute("k1", "v2");
         tc2.setCustomAttribute("k2", null);
         tc2.setCustomAttribute(CA1, "V2");
         tc2.setCustomAttribute(CA2, null);
 
-        TemplateConfiguration tc3 = new TemplateConfiguration();
+        TemplateConfiguration.Builder tc3 = new TemplateConfiguration.Builder();
         tc3.setCustomAttribute("k1", null);
         tc2.setCustomAttribute(CA1, null);
 
@@ -454,7 +457,7 @@ public class TemplateConfigurationTest {
         assertNull(tc1.getCustomAttribute(CA2));
         assertNull(tc1.getCustomAttribute(CA3));
 
-        TemplateConfiguration tc4 = new TemplateConfiguration();
+        TemplateConfiguration.Builder tc4 = new TemplateConfiguration.Builder();
         tc4.setCustomAttribute("k1", "v4");
         tc4.setCustomAttribute(CA1, "V4");
 
@@ -474,15 +477,16 @@ public class TemplateConfigurationTest {
         Template t = new Template(null, "", cfg);
         
         {
-            TemplateConfiguration  tc = new TemplateConfiguration();
-            tc.setParentConfiguration(cfg);
-            tc.setBooleanFormat("Y,N");
-            tc.setAutoImports(ImmutableMap.of("a", "a.ftl", "b", "b.ftl", "c", "c.ftl"));
-            tc.setAutoIncludes(ImmutableList.of("i1.ftl", "i2.ftl", "i3.ftl"));
-            tc.setCustomNumberFormats(ImmutableMap.of(
+            TemplateConfiguration.Builder  tcb = new TemplateConfiguration.Builder();
+            tcb.setBooleanFormat("Y,N");
+            tcb.setAutoImports(ImmutableMap.of("a", "a.ftl", "b", "b.ftl", "c", "c.ftl"));
+            tcb.setAutoIncludes(ImmutableList.of("i1.ftl", "i2.ftl", "i3.ftl"));
+            tcb.setCustomNumberFormats(ImmutableMap.of(
                     "a", HexTemplateNumberFormatFactory.INSTANCE,
                     "b", LocaleSensitiveTemplateNumberFormatFactory.INSTANCE));
-            
+
+            TemplateConfiguration tc = tcb.build();
+            tc.setParentConfiguration(cfg);
             tc.apply(t);
         }
         assertEquals("Y,N", t.getBooleanFormat());
@@ -491,15 +495,15 @@ public class TemplateConfigurationTest {
         assertEquals(ImmutableList.of("i1.ftl", "i2.ftl", "i3.ftl"), t.getAutoIncludes());
         
         {
-            TemplateConfiguration  tc = new TemplateConfiguration();
-            tc.setParentConfiguration(cfg);
-            tc.setBooleanFormat("J,N");
-            tc.setAutoImports(ImmutableMap.of("b", "b2.ftl", "d", "d.ftl"));
-            tc.setAutoIncludes(ImmutableList.of("i2.ftl", "i4.ftl"));
-            tc.setCustomNumberFormats(ImmutableMap.of(
+            TemplateConfiguration.Builder  tcb = new TemplateConfiguration.Builder();
+            tcb.setBooleanFormat("J,N");
+            tcb.setAutoImports(ImmutableMap.of("b", "b2.ftl", "d", "d.ftl"));
+            tcb.setAutoIncludes(ImmutableList.of("i2.ftl", "i4.ftl"));
+            tcb.setCustomNumberFormats(ImmutableMap.of(
                     "b", BaseNTemplateNumberFormatFactory.INSTANCE,
                     "c", BaseNTemplateNumberFormatFactory.INSTANCE));
-            
+            TemplateConfiguration tc = tcb.build();
+            tc.setParentConfiguration(cfg);
             tc.apply(t);
         }
         assertEquals("Y,N", t.getBooleanFormat());
@@ -515,17 +519,19 @@ public class TemplateConfigurationTest {
 
     @Test
     public void testConfigureNonParserConfig() throws Exception {
-        for (PropertyDescriptor pd : getTemplateConfigurationSettingPropDescs(false)) {
-            TemplateConfiguration tc = new TemplateConfiguration();
-            tc.setParentConfiguration(DEFAULT_CFG);
-    
+        for (PropertyDescriptor pd : getTemplateConfigurationSettingPropDescs(
+                TemplateConfiguration.Builder.class, false)) {
+            TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+
             Object newValue = SETTING_ASSIGNMENTS.get(pd.getName());
-            pd.getWriteMethod().invoke(tc, newValue);
+            pd.getWriteMethod().invoke(tcb, newValue);
             
             Template t = new Template(null, "", DEFAULT_CFG);
             Method tReaderMethod = t.getClass().getMethod(pd.getReadMethod().getName());
             
             assertNotEquals("For \"" + pd.getName() + "\"", newValue, tReaderMethod.invoke(t));
+            TemplateConfiguration tc = tcb.build();
+            tc.setParentConfiguration(DEFAULT_CFG);
             tc.apply(t);
             assertEquals("For \"" + pd.getName() + "\"", newValue, tReaderMethod.invoke(t));
         }
@@ -538,15 +544,15 @@ public class TemplateConfigurationTest {
         cfg.setCustomAttribute("k2", "c");
         cfg.setCustomAttribute("k3", "c");
 
-        TemplateConfiguration tc = new TemplateConfiguration();
-        tc.setCustomAttribute("k2", "tc");
-        tc.setCustomAttribute("k3", null);
-        tc.setCustomAttribute("k4", "tc");
-        tc.setCustomAttribute("k5", "tc");
-        tc.setCustomAttribute("k6", "tc");
-        tc.setCustomAttribute(CA1, "tc");
-        tc.setCustomAttribute(CA2,"tc");
-        tc.setCustomAttribute(CA3,"tc");
+        TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+        tcb.setCustomAttribute("k2", "tc");
+        tcb.setCustomAttribute("k3", null);
+        tcb.setCustomAttribute("k4", "tc");
+        tcb.setCustomAttribute("k5", "tc");
+        tcb.setCustomAttribute("k6", "tc");
+        tcb.setCustomAttribute(CA1, "tc");
+        tcb.setCustomAttribute(CA2,"tc");
+        tcb.setCustomAttribute(CA3,"tc");
 
         Template t = new Template(null, "", cfg);
         t.setCustomAttribute("k5", "t");
@@ -555,7 +561,8 @@ public class TemplateConfigurationTest {
         t.setCustomAttribute(CA2, "t");
         t.setCustomAttribute(CA3, null);
         t.setCustomAttribute(CA4, "t");
-        
+
+        TemplateConfiguration tc = tcb.build();
         tc.setParentConfiguration(cfg);
         tc.apply(t);
         
@@ -577,41 +584,46 @@ public class TemplateConfigurationTest {
         Set<String> testedProps = new HashSet<>();
         
         {
-            TemplateConfiguration tc = new TemplateConfiguration();
+            TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+            tcb.setTagSyntax(Configuration.SQUARE_BRACKET_TAG_SYNTAX);
+            TemplateConfiguration tc = tcb.build();
             tc.setParentConfiguration(DEFAULT_CFG);
-            tc.setTagSyntax(Configuration.SQUARE_BRACKET_TAG_SYNTAX);
             assertOutputWithoutAndWithTC(tc, "[#if true]y[/#if]", "[#if true]y[/#if]", "y");
             testedProps.add(Configuration.TAG_SYNTAX_KEY_CAMEL_CASE);
         }
         
         {
-            TemplateConfiguration tc = new TemplateConfiguration();
+            TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+            tcb.setNamingConvention(Configuration.CAMEL_CASE_NAMING_CONVENTION);
+            TemplateConfiguration tc = tcb.build();
             tc.setParentConfiguration(DEFAULT_CFG);
-            tc.setNamingConvention(Configuration.CAMEL_CASE_NAMING_CONVENTION);
             assertOutputWithoutAndWithTC(tc, "<#if true>y<#elseif false>n</#if>", "y", null);
             testedProps.add(Configuration.NAMING_CONVENTION_KEY_CAMEL_CASE);
         }
         
         {
-            TemplateConfiguration tc = new TemplateConfiguration();
+            TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+            tcb.setWhitespaceStripping(false);
+            TemplateConfiguration tc = tcb.build();
             tc.setParentConfiguration(DEFAULT_CFG);
-            tc.setWhitespaceStripping(false);
             assertOutputWithoutAndWithTC(tc, "<#if true>\nx\n</#if>\n", "x\n", "\nx\n\n");
             testedProps.add(Configuration.WHITESPACE_STRIPPING_KEY_CAMEL_CASE);
         }
 
         {
-            TemplateConfiguration tc = new TemplateConfiguration();
+            TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+            tcb.setArithmeticEngine(new DummyArithmeticEngine());
+            TemplateConfiguration tc = tcb.build();
             tc.setParentConfiguration(DEFAULT_CFG);
-            tc.setArithmeticEngine(new DummyArithmeticEngine());
             assertOutputWithoutAndWithTC(tc, "${1} ${1+1}", "1 2", "11 22");
             testedProps.add(Configuration.ARITHMETIC_ENGINE_KEY_CAMEL_CASE);
         }
 
         {
-            TemplateConfiguration tc = new TemplateConfiguration();
+            TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+            tcb.setOutputFormat(XMLOutputFormat.INSTANCE);
+            TemplateConfiguration tc = tcb.build();
             tc.setParentConfiguration(DEFAULT_CFG);
-            tc.setOutputFormat(XMLOutputFormat.INSTANCE);
             assertOutputWithoutAndWithTC(tc, "${.outputFormat} ${\"a'b\"}",
                     UndefinedOutputFormat.INSTANCE.getName() + " a'b",
                     XMLOutputFormat.INSTANCE.getName() + " a&apos;b");
@@ -619,17 +631,19 @@ public class TemplateConfigurationTest {
         }
 
         {
-            TemplateConfiguration tc = new TemplateConfiguration();
+            TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+            tcb.setOutputFormat(XMLOutputFormat.INSTANCE);
+            tcb.setAutoEscapingPolicy(Configuration.DISABLE_AUTO_ESCAPING_POLICY);
+            TemplateConfiguration tc = tcb.build();
             tc.setParentConfiguration(DEFAULT_CFG);
-            tc.setOutputFormat(XMLOutputFormat.INSTANCE);
-            tc.setAutoEscapingPolicy(Configuration.DISABLE_AUTO_ESCAPING_POLICY);
             assertOutputWithoutAndWithTC(tc, "${'a&b'}", "a&b", "a&b");
             testedProps.add(Configuration.AUTO_ESCAPING_POLICY_KEY_CAMEL_CASE);
         }
         
         {
-            TemplateConfiguration tc = new TemplateConfiguration();
+            TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
             /* Can't test this now, as the only valid value is 3.0.0. [FM3.0.1]
+            TemplateConfiguration tc = tcb.build();
             tc.setParentConfiguration(new Configuration(new Version(2, 3, 0)));
             assertOutputWithoutAndWithTC(tc, "<#foo>", null, "<#foo>");
             */
@@ -637,19 +651,21 @@ public class TemplateConfigurationTest {
         }
 
         {
-            TemplateConfiguration tc = new TemplateConfiguration();
+            TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+            tcb.setRecognizeStandardFileExtensions(false);
+            TemplateConfiguration tc = tcb.build();
             tc.setParentConfiguration(DEFAULT_CFG);
-            tc.setRecognizeStandardFileExtensions(false);
             assertOutputWithoutAndWithTC(tc, "adhoc.ftlh", "${.outputFormat}",
                     HTMLOutputFormat.INSTANCE.getName(), UndefinedOutputFormat.INSTANCE.getName());
             testedProps.add(Configuration.RECOGNIZE_STANDARD_FILE_EXTENSIONS_KEY_CAMEL_CASE);
         }
 
         {
-            TemplateConfiguration tc = new TemplateConfiguration();
-            tc.setLogTemplateExceptions(false);
+            TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+            tcb.setLogTemplateExceptions(false);
+            tcb.setTabSize(3);
+            TemplateConfiguration tc = tcb.build();
             tc.setParentConfiguration(DEFAULT_CFG);
-            tc.setTabSize(3);
             assertOutputWithoutAndWithTC(tc,
                     "<#attempt><@'\\t$\\{1+}'?interpret/><#recover>"
                     + "${.error?replace('(?s).*?column ([0-9]+).*', '$1', 'r')}"
@@ -662,12 +678,12 @@ public class TemplateConfigurationTest {
             // As the TemplateLanguage-based parser selection happens in the TemplateResolver, we can't use
             // assertOutput here, as that hard-coded to create an FTL Template.
 
-            TemplateConfiguration tc = new TemplateConfiguration();
-            tc.setTemplateLanguage(TemplateLanguage.STATIC_TEXT);
+            TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+            tcb.setTemplateLanguage(TemplateLanguage.STATIC_TEXT);
 
             Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
             cfg.setTemplateConfigurations(new ConditionalTemplateConfigurationFactory(new FileExtensionMatcher
-                    ("txt"), tc));
+                    ("txt"), tcb.build()));
 
             StringTemplateLoader templateLoader = new StringTemplateLoader();
             templateLoader.putTemplate("adhoc.ftl", "${1+1}");
@@ -692,13 +708,13 @@ public class TemplateConfigurationTest {
             // As the TemplateLanguage-based parser selection happens in the TemplateResolver, we can't use
             // assertOutput here, as that hard-coded to create an FTL Template.
 
-            TemplateConfiguration tc = new TemplateConfiguration();
-            tc.setSourceEncoding(StandardCharsets.ISO_8859_1);
+            TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+            tcb.setSourceEncoding(StandardCharsets.ISO_8859_1);
 
             Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
             cfg.setSourceEncoding(StandardCharsets.UTF_8);
             cfg.setTemplateConfigurations(new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher
-                    ("latin1.ftl"), tc));
+                    ("latin1.ftl"), tcb.build()));
 
             MonitoredTemplateLoader templateLoader = new MonitoredTemplateLoader();
             templateLoader.putBinaryTemplate("utf8.ftl", "prĂ³ba", StandardCharsets.UTF_8, 1);
@@ -728,9 +744,10 @@ public class TemplateConfigurationTest {
     
     @Test
     public void testArithmeticEngine() throws TemplateException, IOException {
-        TemplateConfiguration tc = new TemplateConfiguration();
+        TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+        tcb.setArithmeticEngine(new DummyArithmeticEngine());
+        TemplateConfiguration tc = tcb.build();
         tc.setParentConfiguration(DEFAULT_CFG);
-        tc.setArithmeticEngine(new DummyArithmeticEngine());
         assertOutputWithoutAndWithTC(tc,
                 "<#setting locale='en_US'>${1} ${1+1} ${1*3} <#assign x = 1>${x + x} ${x * 3}",
                 "1 2 3 2 3", "11 22 33 22 33");
@@ -742,25 +759,28 @@ public class TemplateConfigurationTest {
 
     @Test
     public void testAutoImport() throws TemplateException, IOException {
-        TemplateConfiguration tc = new TemplateConfiguration();
-        tc.setAutoImports(ImmutableMap.of("t1", "t1.ftl", "t2", "t2.ftl"));
-        tc.setParent(DEFAULT_CFG);
+        TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+        tcb.setAutoImports(ImmutableMap.of("t1", "t1.ftl", "t2", "t2.ftl"));
+        TemplateConfiguration tc = tcb.build();
+        tc.setParentConfiguration(DEFAULT_CFG);
         assertOutputWithoutAndWithTC(tc, "<#import 't3.ftl' as t3>${loaded}", "t3;", "t1;t2;t3;");
     }
 
     @Test
     public void testAutoIncludes() throws TemplateException, IOException {
-        TemplateConfiguration tc = new TemplateConfiguration();
-        tc.setAutoIncludes(ImmutableList.of("t1.ftl", "t2.ftl"));
-        tc.setParent(DEFAULT_CFG);
+        TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+        tcb.setAutoIncludes(ImmutableList.of("t1.ftl", "t2.ftl"));
+        TemplateConfiguration tc = tcb.build();
+        tc.setParentConfiguration(DEFAULT_CFG);
         assertOutputWithoutAndWithTC(tc, "<#include 't3.ftl'>", "In t3;", "In t1;In t2;In t3;");
     }
     
     @Test
     public void testStringInterpolate() throws TemplateException, IOException {
-        TemplateConfiguration tc = new TemplateConfiguration();
+        TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+        tcb.setArithmeticEngine(new DummyArithmeticEngine());
+        TemplateConfiguration tc = tcb.build();
         tc.setParentConfiguration(DEFAULT_CFG);
-        tc.setArithmeticEngine(new DummyArithmeticEngine());
         assertOutputWithoutAndWithTC(tc,
                 "<#setting locale='en_US'>${'${1} ${1+1} ${1*3}'} <#assign x = 1>${'${x + x} ${x * 3}'}",
                 "1 2 3 2 3", "11 22 33 22 33");
@@ -772,25 +792,32 @@ public class TemplateConfigurationTest {
     
     @Test
     public void testInterpret() throws TemplateException, IOException {
-        TemplateConfiguration tc = new TemplateConfiguration();
-        tc.setParentConfiguration(DEFAULT_CFG);
-        tc.setArithmeticEngine(new DummyArithmeticEngine());
-        assertOutputWithoutAndWithTC(tc,
-                "<#setting locale='en_US'><#assign src = r'${1} <#assign x = 1>${x + x}'><@src?interpret />",
-                "1 2", "11 22");
-        
-        tc.setWhitespaceStripping(false);
-        assertOutputWithoutAndWithTC(tc,
-                "<#if true>\nX</#if><#assign src = r'<#if true>\nY</#if>'><@src?interpret />",
-                "XY", "\nX\nY");
+        TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+        tcb.setArithmeticEngine(new DummyArithmeticEngine());
+        {
+            TemplateConfiguration tc = tcb.build();
+            tc.setParentConfiguration(DEFAULT_CFG);
+            assertOutputWithoutAndWithTC(tc,
+                    "<#setting locale='en_US'><#assign src = r'${1} <#assign x = 1>${x + x}'><@src?interpret />",
+                    "1 2", "11 22");
+        }
+        tcb.setWhitespaceStripping(false);
+        {
+            TemplateConfiguration tc = tcb.build();
+            tc.setParentConfiguration(DEFAULT_CFG);
+            assertOutputWithoutAndWithTC(tc,
+                    "<#if true>\nX</#if><#assign src = r'<#if true>\nY</#if>'><@src?interpret />",
+                    "XY", "\nX\nY");
+        }
     }
 
     @Test
     public void testEval() throws TemplateException, IOException {
         {
-            TemplateConfiguration tc = new TemplateConfiguration();
+            TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+            tcb.setArithmeticEngine(new DummyArithmeticEngine());
+            TemplateConfiguration tc = tcb.build();
             tc.setParentConfiguration(DEFAULT_CFG);
-            tc.setArithmeticEngine(new DummyArithmeticEngine());
             assertOutputWithoutAndWithTC(tc,
                     "<#assign x = 1>${r'1 + x'?eval?c}",
                     "2", "22");
@@ -800,34 +827,51 @@ public class TemplateConfigurationTest {
         }
         
         {
-            TemplateConfiguration tc = new TemplateConfiguration();
-            tc.setParentConfiguration(DEFAULT_CFG);
+            TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
             Charset outputEncoding = ISO_8859_2;
-            tc.setOutputEncoding(outputEncoding);
+            tcb.setOutputEncoding(outputEncoding);
 
             String legacyNCFtl = "${r'.output_encoding!\"null\"'?eval}";
             String camelCaseNCFtl = "${r'.outputEncoding!\"null\"'?eval}";
 
-            // Default is re-auto-detecting in ?eval:
-            assertOutputWithoutAndWithTC(tc, legacyNCFtl, "null", outputEncoding.name());
-            assertOutputWithoutAndWithTC(tc, camelCaseNCFtl, "null", outputEncoding.name());
-            
-            // Force camelCase:
-            tc.setNamingConvention(Configuration.CAMEL_CASE_NAMING_CONVENTION);
-            assertOutputWithoutAndWithTC(tc, legacyNCFtl, "null", null);
-            assertOutputWithoutAndWithTC(tc, camelCaseNCFtl, "null", outputEncoding.name());
-            
-            // Force legacy:
-            tc.setNamingConvention(Configuration.LEGACY_NAMING_CONVENTION);
-            assertOutputWithoutAndWithTC(tc, legacyNCFtl, "null", outputEncoding.name());
-            assertOutputWithoutAndWithTC(tc, camelCaseNCFtl, "null", null);
+            {
+                TemplateConfiguration tc = tcb.build();
+                tc.setParentConfiguration(DEFAULT_CFG);
+
+                // Default is re-auto-detecting in ?eval:
+                assertOutputWithoutAndWithTC(tc, legacyNCFtl, "null", outputEncoding.name());
+                assertOutputWithoutAndWithTC(tc, camelCaseNCFtl, "null", outputEncoding.name());
+            }
+
+            {
+                // Force camelCase:
+                tcb.setNamingConvention(Configuration.CAMEL_CASE_NAMING_CONVENTION);
+
+                TemplateConfiguration tc = tcb.build();
+                tc.setParentConfiguration(DEFAULT_CFG);
+
+                assertOutputWithoutAndWithTC(tc, legacyNCFtl, "null", null);
+                assertOutputWithoutAndWithTC(tc, camelCaseNCFtl, "null", outputEncoding.name());
+            }
+
+            {
+                // Force legacy:
+                tcb.setNamingConvention(Configuration.LEGACY_NAMING_CONVENTION);
+
+                TemplateConfiguration tc = tcb.build();
+                tc.setParentConfiguration(DEFAULT_CFG);
+
+                assertOutputWithoutAndWithTC(tc, legacyNCFtl, "null", outputEncoding.name());
+                assertOutputWithoutAndWithTC(tc, camelCaseNCFtl, "null", null);
+            }
         }
     }
     
     @Test
     public void testSetParentConfiguration() throws IOException {
-        TemplateConfiguration tc = new TemplateConfiguration();
-        
+        TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+        TemplateConfiguration tc = tcb.build();
+
         Template t = new Template(null, "", DEFAULT_CFG);
         try {
             tc.apply(t);
@@ -836,7 +880,7 @@ public class TemplateConfigurationTest {
             assertThat(e.getMessage(), containsString("Configuration"));
         }
         
-        tc.setParent(DEFAULT_CFG);
+        tc.setParentConfiguration(DEFAULT_CFG);
         
         try {
             tc.setParentConfiguration(new Configuration());
@@ -846,21 +890,13 @@ public class TemplateConfigurationTest {
         }
 
         try {
-            // Same as setParentConfiguration
-            tc.setParent(new Configuration());
-            fail();
-        } catch (IllegalStateException e) {
-            assertThat(e.getMessage(), containsString("Configuration"));
-        }
-        
-        try {
             tc.setParentConfiguration(null);
             fail();
         } catch (_NullArgumentException e) {
-            // exected
+            // expected
         }
         
-        tc.setParent(DEFAULT_CFG);
+        tc.setParentConfiguration(DEFAULT_CFG);
         
         tc.apply(t);
     }
@@ -910,22 +946,23 @@ public class TemplateConfigurationTest {
 
     @Test
     public void testIsSet() throws Exception {
-        for (PropertyDescriptor pd : getTemplateConfigurationSettingPropDescs(true)) {
-            TemplateConfiguration tc = new TemplateConfiguration();
-            checkAllIsSetFalseExcept(tc, null);
-            pd.getWriteMethod().invoke(tc, SETTING_ASSIGNMENTS.get(pd.getName()));
-            checkAllIsSetFalseExcept(tc, pd.getName());
+        for (PropertyDescriptor pd : getTemplateConfigurationSettingPropDescs(
+                TemplateConfiguration.Builder.class, true)) {
+            TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+            checkAllIsSetFalseExcept(tcb.build(), null);
+            pd.getWriteMethod().invoke(tcb, SETTING_ASSIGNMENTS.get(pd.getName()));
+            checkAllIsSetFalseExcept(tcb.build(), pd.getName());
         }
     }
 
     private void checkAllIsSetFalseExcept(TemplateConfiguration tc, String setSetting)
             throws SecurityException, IntrospectionException,
             IllegalArgumentException, IllegalAccessException, InvocationTargetException {
-        for (PropertyDescriptor pd : getTemplateConfigurationSettingPropDescs(true)) {
+        for (PropertyDescriptor pd : getTemplateConfigurationSettingPropDescs(TemplateConfiguration.class, true)) {
             String isSetMethodName = getIsSetMethodName(pd.getReadMethod().getName());
             Method isSetMethod;
             try {
-                isSetMethod = TemplateConfiguration.class.getMethod(isSetMethodName);
+                isSetMethod = tc.getClass().getMethod(isSetMethodName);
             } catch (NoSuchMethodException e) {
                 fail("Missing " + isSetMethodName + " method for \"" + pd.getName() + "\".");
                 return;
@@ -943,26 +980,23 @@ public class TemplateConfigurationTest {
      */
     @Test
     public void checkTestAssignments() throws Exception {
-        for (PropertyDescriptor pd : getTemplateConfigurationSettingPropDescs(true)) {
+        for (PropertyDescriptor pd : getTemplateConfigurationSettingPropDescs(
+                TemplateConfiguration.Builder.class, true)) {
             String propName = pd.getName();
             if (!SETTING_ASSIGNMENTS.containsKey(propName)) {
                 fail("Test case doesn't cover all settings in SETTING_ASSIGNMENTS. Missing: " + propName);
             }
             Method readMethod = pd.getReadMethod();
             String cfgMethodName = readMethod.getName();
-            if (cfgMethodName.equals("getSourceEncoding")) {
-                // Because Configuration has local-to-encoding map too, this has a different name there.
-                cfgMethodName = "getSourceEncoding";
-            }
             Method cfgMethod = DEFAULT_CFG.getClass().getMethod(cfgMethodName, readMethod.getParameterTypes());
             Object defaultSettingValue = cfgMethod.invoke(DEFAULT_CFG);
             Object assignedValue = SETTING_ASSIGNMENTS.get(propName);
             assertNotEquals("SETTING_ASSIGNMENTS must contain a non-default value for " + propName,
                     assignedValue, defaultSettingValue);
 
-            TemplateConfiguration tc = new TemplateConfiguration();
+            TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
             try {
-                pd.getWriteMethod().invoke(tc, assignedValue);
+                pd.getWriteMethod().invoke(tcb, assignedValue);
             } catch (Exception e) {
                 throw new IllegalStateException("For setting \"" + propName + "\" and assigned value of type "
                         + (assignedValue != null ? assignedValue.getClass().getName() : "Null"),

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/88baea20/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaltTemplateResolverTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaltTemplateResolverTest.java b/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaltTemplateResolverTest.java
deleted file mode 100644
index f26ce63..0000000
--- a/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaltTemplateResolverTest.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.freemarker.core;
-
-import static org.junit.Assert.*;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.util.Locale;
-
-import org.apache.freemarker.core.templateresolver.ConditionalTemplateConfigurationFactory;
-import org.apache.freemarker.core.templateresolver.FileNameGlobMatcher;
-import org.apache.freemarker.core.templateresolver.FirstMatchTemplateConfigurationFactory;
-import org.apache.freemarker.core.templateresolver.MergingTemplateConfigurationFactory;
-import org.apache.freemarker.core.templateresolver.impl.ByteArrayTemplateLoader;
-import org.apache.freemarker.core.templateresolver.impl.StringTemplateLoader;
-import org.junit.Test;
-
-public class TemplateConfigurationWithDefaltTemplateResolverTest {
-
-    private static final String TEXT_WITH_ACCENTS = "pr\u00F3ba";
-
-    private static final Object CUST_ATT_1 = new Object();
-    private static final Object CUST_ATT_2 = new Object();
-
-    private static final Charset ISO_8859_2 = Charset.forName("ISO-8859-2");
-
-    @Test
-    public void testEncoding() throws Exception {
-        Configuration cfg = createCommonEncodingTesterConfig();
-        
-        {
-            Template t = cfg.getTemplate("utf8.ftl");
-            assertEquals(StandardCharsets.UTF_8, t.getSourceEncoding());
-            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
-        }
-        {
-            Template t = cfg.getTemplate("utf16.ftl");
-            assertEquals(StandardCharsets.UTF_16LE, t.getSourceEncoding());
-            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
-        }
-        {
-            Template t = cfg.getTemplate("default.ftl");
-            assertEquals(StandardCharsets.ISO_8859_1, t.getSourceEncoding());
-            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
-        }
-        {
-            Template t = cfg.getTemplate("utf8-latin2.ftl");
-            assertEquals(ISO_8859_2, t.getSourceEncoding());
-            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
-        }
-        {
-            Template t = cfg.getTemplate("default-latin2.ftl");
-            assertEquals(ISO_8859_2, t.getSourceEncoding());
-            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
-        }
-    }
-    
-    @Test
-    public void testIncludeAndEncoding() throws Exception {
-        Configuration cfg = createCommonEncodingTesterConfig();
-        ByteArrayTemplateLoader tl = (ByteArrayTemplateLoader) cfg.getTemplateLoader();
-        tl.putTemplate("main.ftl", (
-                        "<#include 'utf8.ftl'>"
-                        + "<#include 'utf16.ftl'>"
-                        + "<#include 'default.ftl'>"
-                        + "<#include 'utf8-latin2.ftl'>"
-                ).getBytes(StandardCharsets.ISO_8859_1));
-        assertEquals(
-                TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS,
-                getTemplateOutput(cfg.getTemplate("main.ftl")));
-    }
-
-    @Test
-    public void testLocale() throws Exception {
-        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
-        cfg.setLocale(Locale.US);
-        
-        StringTemplateLoader tl = new StringTemplateLoader();
-        tl.putTemplate("(de).ftl", "${.locale}");
-        tl.putTemplate("default.ftl", "${.locale}");
-        tl.putTemplate("(de)-fr.ftl",
-                ("<#ftl locale='fr_FR'>${.locale}"));
-        tl.putTemplate("default-fr.ftl",
-                ("<#ftl locale='fr_FR'>${.locale}"));
-        cfg.setTemplateLoader(tl);
-
-        TemplateConfiguration tcDe = new TemplateConfiguration();
-        tcDe.setLocale(Locale.GERMANY);
-        cfg.setTemplateConfigurations(
-                new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(de)*"), tcDe));
-        
-        {
-            Template t = cfg.getTemplate("(de).ftl");
-            assertEquals(Locale.GERMANY, t.getLocale());
-            assertEquals("de_DE", getTemplateOutput(t));
-        }
-        {
-            Template t = cfg.getTemplate("(de).ftl", Locale.ITALY);
-            assertEquals(Locale.GERMANY, t.getLocale());
-            assertEquals("de_DE", getTemplateOutput(t));
-        }
-        {
-            Template t = cfg.getTemplate("default.ftl");
-            assertEquals(Locale.US, t.getLocale());
-            assertEquals("en_US", getTemplateOutput(t));
-        }
-        {
-            Template t = cfg.getTemplate("default.ftl", Locale.ITALY);
-            assertEquals(Locale.ITALY, t.getLocale());
-            assertEquals("it_IT", getTemplateOutput(t));
-        }
-    }
-
-    @Test
-    public void testConfigurableSettings() throws Exception {
-        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
-        cfg.setLocale(Locale.US);
-        
-        TemplateConfiguration tcFR = new TemplateConfiguration();
-        tcFR.setLocale(Locale.FRANCE);
-        TemplateConfiguration tcYN = new TemplateConfiguration();
-        tcYN.setBooleanFormat("Y,N");
-        TemplateConfiguration tc00 = new TemplateConfiguration();
-        tc00.setNumberFormat("0.00");
-        cfg.setTemplateConfigurations(
-                new MergingTemplateConfigurationFactory(
-                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(fr)*"), tcFR),
-                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(yn)*"), tcYN),
-                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(00)*"), tc00)
-                )
-        );
-        
-        String commonFTL = "${.locale} ${true?string} ${1.2}";
-        StringTemplateLoader tl = new StringTemplateLoader();
-        tl.putTemplate("default", commonFTL);
-        tl.putTemplate("(fr)", commonFTL);
-        tl.putTemplate("(yn)(00)", commonFTL);
-        tl.putTemplate("(00)(fr)", commonFTL);
-        cfg.setTemplateLoader(tl);
-        
-        assertEquals("en_US true 1.2", getTemplateOutput(cfg.getTemplate("default")));
-        assertEquals("fr_FR true 1,2", getTemplateOutput(cfg.getTemplate("(fr)")));
-        assertEquals("en_US Y 1.20", getTemplateOutput(cfg.getTemplate("(yn)(00)")));
-        assertEquals("fr_FR true 1,20", getTemplateOutput(cfg.getTemplate("(00)(fr)")));
-    }
-    
-    @Test
-    public void testCustomAttributes() throws Exception {
-        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
-        
-        TemplateConfiguration tc1 = new TemplateConfiguration();
-        tc1.setCustomAttribute("a1", "a1tc1");
-        tc1.setCustomAttribute("a2", "a2tc1");
-        tc1.setCustomAttribute("a3", "a3tc1");
-        tc1.setCustomAttribute(CUST_ATT_1, "ca1tc1");
-        tc1.setCustomAttribute(CUST_ATT_2, "ca2tc1");
-        
-        TemplateConfiguration tc2 = new TemplateConfiguration();
-        tc2.setCustomAttribute("a1", "a1tc2");
-        tc2.setCustomAttribute(CUST_ATT_1, "ca1tc2");
-        
-        cfg.setTemplateConfigurations(
-                new MergingTemplateConfigurationFactory(
-                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(tc1)*"), tc1),
-                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(tc2)*"), tc2)
-                )
-        );
-        
-        String commonFTL = "<#ftl attributes={ 'a3': 'a3temp' }>";
-        StringTemplateLoader tl = new StringTemplateLoader();
-        tl.putTemplate("(tc1)", commonFTL);
-        tl.putTemplate("(tc1)noHeader", "");
-        tl.putTemplate("(tc2)", commonFTL);
-        tl.putTemplate("(tc1)(tc2)", commonFTL);
-        cfg.setTemplateLoader(tl);
-
-        {
-            Template t = cfg.getTemplate("(tc1)");
-            assertEquals("a1tc1", t.getCustomAttribute("a1"));
-            assertEquals("a2tc1", t.getCustomAttribute("a2"));
-            assertEquals("a3temp", t.getCustomAttribute("a3"));
-            assertEquals("ca1tc1", t.getCustomAttribute(CUST_ATT_1));
-            assertEquals("ca2tc1", t.getCustomAttribute(CUST_ATT_2));
-        }
-        {
-            Template t = cfg.getTemplate("(tc1)noHeader");
-            assertEquals("a1tc1", t.getCustomAttribute("a1"));
-            assertEquals("a2tc1", t.getCustomAttribute("a2"));
-            assertEquals("a3tc1", t.getCustomAttribute("a3"));
-            assertEquals("ca1tc1", t.getCustomAttribute(CUST_ATT_1));
-            assertEquals("ca2tc1", t.getCustomAttribute(CUST_ATT_2));
-        }
-        {
-            Template t = cfg.getTemplate("(tc2)");
-            assertEquals("a1tc2", t.getCustomAttribute("a1"));
-            assertNull(t.getCustomAttribute("a2"));
-            assertEquals("a3temp", t.getCustomAttribute("a3"));
-            assertEquals("ca1tc2", t.getCustomAttribute(CUST_ATT_1));
-            assertNull(t.getCustomAttribute(CUST_ATT_2));
-        }
-        {
-            Template t = cfg.getTemplate("(tc1)(tc2)");
-            assertEquals("a1tc2", t.getCustomAttribute("a1"));
-            assertEquals("a2tc1", t.getCustomAttribute("a2"));
-            assertEquals("a3temp", t.getCustomAttribute("a3"));
-            assertEquals("ca1tc2", t.getCustomAttribute(CUST_ATT_1));
-            assertEquals("ca2tc1", t.getCustomAttribute(CUST_ATT_2));
-        }
-    }
-    
-    private String getTemplateOutput(Template t) throws TemplateException, IOException {
-        StringWriter sw = new StringWriter();
-        t.process(null, sw);
-        return sw.toString();
-    }
-
-    private Configuration createCommonEncodingTesterConfig() throws UnsupportedEncodingException {
-        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
-        cfg.setSourceEncoding(StandardCharsets.ISO_8859_1);
-        cfg.setLocale(Locale.US);
-        
-        ByteArrayTemplateLoader tl = new ByteArrayTemplateLoader();
-        tl.putTemplate("utf8.ftl", TEXT_WITH_ACCENTS.getBytes(StandardCharsets.UTF_8));
-        tl.putTemplate("utf16.ftl", TEXT_WITH_ACCENTS.getBytes(StandardCharsets.UTF_16LE));
-        tl.putTemplate("default.ftl", TEXT_WITH_ACCENTS.getBytes(ISO_8859_2));
-        tl.putTemplate("utf8-latin2.ftl",
-                ("<#ftl encoding='iso-8859-2'>" + TEXT_WITH_ACCENTS).getBytes(ISO_8859_2));
-        tl.putTemplate("default-latin2.ftl",
-                ("<#ftl encoding='iso-8859-2'>" + TEXT_WITH_ACCENTS).getBytes(ISO_8859_2));
-        cfg.setTemplateLoader(tl);
-        
-        TemplateConfiguration tcUtf8 = new TemplateConfiguration();
-        tcUtf8.setSourceEncoding(StandardCharsets.UTF_8);
-        TemplateConfiguration tcUtf16 = new TemplateConfiguration();
-        tcUtf16.setSourceEncoding(StandardCharsets.UTF_16LE);
-        cfg.setTemplateConfigurations(
-                new FirstMatchTemplateConfigurationFactory(
-                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*utf8*"), tcUtf8),
-                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*utf16*"), tcUtf16)
-                ).allowNoMatch(true));
-        return cfg;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/88baea20/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaultTemplateResolverTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaultTemplateResolverTest.java b/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaultTemplateResolverTest.java
new file mode 100644
index 0000000..b154ebb
--- /dev/null
+++ b/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaultTemplateResolverTest.java
@@ -0,0 +1,264 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.freemarker.core;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.Locale;
+
+import org.apache.freemarker.core.templateresolver.ConditionalTemplateConfigurationFactory;
+import org.apache.freemarker.core.templateresolver.FileNameGlobMatcher;
+import org.apache.freemarker.core.templateresolver.FirstMatchTemplateConfigurationFactory;
+import org.apache.freemarker.core.templateresolver.MergingTemplateConfigurationFactory;
+import org.apache.freemarker.core.templateresolver.impl.ByteArrayTemplateLoader;
+import org.apache.freemarker.core.templateresolver.impl.StringTemplateLoader;
+import org.junit.Test;
+
+public class TemplateConfigurationWithDefaultTemplateResolverTest {
+
+    private static final String TEXT_WITH_ACCENTS = "pr\u00F3ba";
+
+    private static final Object CUST_ATT_1 = new Object();
+    private static final Object CUST_ATT_2 = new Object();
+
+    private static final Charset ISO_8859_2 = Charset.forName("ISO-8859-2");
+
+    @Test
+    public void testEncoding() throws Exception {
+        Configuration cfg = createCommonEncodingTesterConfig();
+        
+        {
+            Template t = cfg.getTemplate("utf8.ftl");
+            assertEquals(StandardCharsets.UTF_8, t.getSourceEncoding());
+            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
+        }
+        {
+            Template t = cfg.getTemplate("utf16.ftl");
+            assertEquals(StandardCharsets.UTF_16LE, t.getSourceEncoding());
+            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
+        }
+        {
+            Template t = cfg.getTemplate("default.ftl");
+            assertEquals(StandardCharsets.ISO_8859_1, t.getSourceEncoding());
+            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
+        }
+        {
+            Template t = cfg.getTemplate("utf8-latin2.ftl");
+            assertEquals(ISO_8859_2, t.getSourceEncoding());
+            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
+        }
+        {
+            Template t = cfg.getTemplate("default-latin2.ftl");
+            assertEquals(ISO_8859_2, t.getSourceEncoding());
+            assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
+        }
+    }
+    
+    @Test
+    public void testIncludeAndEncoding() throws Exception {
+        Configuration cfg = createCommonEncodingTesterConfig();
+        ByteArrayTemplateLoader tl = (ByteArrayTemplateLoader) cfg.getTemplateLoader();
+        tl.putTemplate("main.ftl", (
+                        "<#include 'utf8.ftl'>"
+                        + "<#include 'utf16.ftl'>"
+                        + "<#include 'default.ftl'>"
+                        + "<#include 'utf8-latin2.ftl'>"
+                ).getBytes(StandardCharsets.ISO_8859_1));
+        assertEquals(
+                TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS,
+                getTemplateOutput(cfg.getTemplate("main.ftl")));
+    }
+
+    @Test
+    public void testLocale() throws Exception {
+        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
+        cfg.setLocale(Locale.US);
+        
+        StringTemplateLoader tl = new StringTemplateLoader();
+        tl.putTemplate("(de).ftl", "${.locale}");
+        tl.putTemplate("default.ftl", "${.locale}");
+        tl.putTemplate("(de)-fr.ftl",
+                ("<#ftl locale='fr_FR'>${.locale}"));
+        tl.putTemplate("default-fr.ftl",
+                ("<#ftl locale='fr_FR'>${.locale}"));
+        cfg.setTemplateLoader(tl);
+
+        TemplateConfiguration.Builder tcDe = new TemplateConfiguration.Builder();
+        tcDe.setLocale(Locale.GERMANY);
+        cfg.setTemplateConfigurations(
+                new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(de)*"), tcDe.build()));
+        
+        {
+            Template t = cfg.getTemplate("(de).ftl");
+            assertEquals(Locale.GERMANY, t.getLocale());
+            assertEquals("de_DE", getTemplateOutput(t));
+        }
+        {
+            Template t = cfg.getTemplate("(de).ftl", Locale.ITALY);
+            assertEquals(Locale.GERMANY, t.getLocale());
+            assertEquals("de_DE", getTemplateOutput(t));
+        }
+        {
+            Template t = cfg.getTemplate("default.ftl");
+            assertEquals(Locale.US, t.getLocale());
+            assertEquals("en_US", getTemplateOutput(t));
+        }
+        {
+            Template t = cfg.getTemplate("default.ftl", Locale.ITALY);
+            assertEquals(Locale.ITALY, t.getLocale());
+            assertEquals("it_IT", getTemplateOutput(t));
+        }
+    }
+
+    @Test
+    public void testConfigurableSettings() throws Exception {
+        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
+        cfg.setLocale(Locale.US);
+        
+        TemplateConfiguration.Builder tcFR = new TemplateConfiguration.Builder();
+        tcFR.setLocale(Locale.FRANCE);
+        TemplateConfiguration.Builder tcYN = new TemplateConfiguration.Builder();
+        tcYN.setBooleanFormat("Y,N");
+        TemplateConfiguration.Builder tc00 = new TemplateConfiguration.Builder();
+        tc00.setNumberFormat("0.00");
+        cfg.setTemplateConfigurations(
+                new MergingTemplateConfigurationFactory(
+                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(fr)*"), tcFR.build()),
+                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(yn)*"), tcYN.build()),
+                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(00)*"), tc00.build())
+                )
+        );
+        
+        String commonFTL = "${.locale} ${true?string} ${1.2}";
+        StringTemplateLoader tl = new StringTemplateLoader();
+        tl.putTemplate("default", commonFTL);
+        tl.putTemplate("(fr)", commonFTL);
+        tl.putTemplate("(yn)(00)", commonFTL);
+        tl.putTemplate("(00)(fr)", commonFTL);
+        cfg.setTemplateLoader(tl);
+        
+        assertEquals("en_US true 1.2", getTemplateOutput(cfg.getTemplate("default")));
+        assertEquals("fr_FR true 1,2", getTemplateOutput(cfg.getTemplate("(fr)")));
+        assertEquals("en_US Y 1.20", getTemplateOutput(cfg.getTemplate("(yn)(00)")));
+        assertEquals("fr_FR true 1,20", getTemplateOutput(cfg.getTemplate("(00)(fr)")));
+    }
+    
+    @Test
+    public void testCustomAttributes() throws Exception {
+        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
+        
+        TemplateConfiguration.Builder tc1 = new TemplateConfiguration.Builder();
+        tc1.setCustomAttribute("a1", "a1tc1");
+        tc1.setCustomAttribute("a2", "a2tc1");
+        tc1.setCustomAttribute("a3", "a3tc1");
+        tc1.setCustomAttribute(CUST_ATT_1, "ca1tc1");
+        tc1.setCustomAttribute(CUST_ATT_2, "ca2tc1");
+        
+        TemplateConfiguration.Builder tc2 = new TemplateConfiguration.Builder();
+        tc2.setCustomAttribute("a1", "a1tc2");
+        tc2.setCustomAttribute(CUST_ATT_1, "ca1tc2");
+        
+        cfg.setTemplateConfigurations(
+                new MergingTemplateConfigurationFactory(
+                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(tc1)*"), tc1.build()),
+                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*(tc2)*"), tc2.build())
+                )
+        );
+        
+        String commonFTL = "<#ftl attributes={ 'a3': 'a3temp' }>";
+        StringTemplateLoader tl = new StringTemplateLoader();
+        tl.putTemplate("(tc1)", commonFTL);
+        tl.putTemplate("(tc1)noHeader", "");
+        tl.putTemplate("(tc2)", commonFTL);
+        tl.putTemplate("(tc1)(tc2)", commonFTL);
+        cfg.setTemplateLoader(tl);
+
+        {
+            Template t = cfg.getTemplate("(tc1)");
+            assertEquals("a1tc1", t.getCustomAttribute("a1"));
+            assertEquals("a2tc1", t.getCustomAttribute("a2"));
+            assertEquals("a3temp", t.getCustomAttribute("a3"));
+            assertEquals("ca1tc1", t.getCustomAttribute(CUST_ATT_1));
+            assertEquals("ca2tc1", t.getCustomAttribute(CUST_ATT_2));
+        }
+        {
+            Template t = cfg.getTemplate("(tc1)noHeader");
+            assertEquals("a1tc1", t.getCustomAttribute("a1"));
+            assertEquals("a2tc1", t.getCustomAttribute("a2"));
+            assertEquals("a3tc1", t.getCustomAttribute("a3"));
+            assertEquals("ca1tc1", t.getCustomAttribute(CUST_ATT_1));
+            assertEquals("ca2tc1", t.getCustomAttribute(CUST_ATT_2));
+        }
+        {
+            Template t = cfg.getTemplate("(tc2)");
+            assertEquals("a1tc2", t.getCustomAttribute("a1"));
+            assertNull(t.getCustomAttribute("a2"));
+            assertEquals("a3temp", t.getCustomAttribute("a3"));
+            assertEquals("ca1tc2", t.getCustomAttribute(CUST_ATT_1));
+            assertNull(t.getCustomAttribute(CUST_ATT_2));
+        }
+        {
+            Template t = cfg.getTemplate("(tc1)(tc2)");
+            assertEquals("a1tc2", t.getCustomAttribute("a1"));
+            assertEquals("a2tc1", t.getCustomAttribute("a2"));
+            assertEquals("a3temp", t.getCustomAttribute("a3"));
+            assertEquals("ca1tc2", t.getCustomAttribute(CUST_ATT_1));
+            assertEquals("ca2tc1", t.getCustomAttribute(CUST_ATT_2));
+        }
+    }
+    
+    private String getTemplateOutput(Template t) throws TemplateException, IOException {
+        StringWriter sw = new StringWriter();
+        t.process(null, sw);
+        return sw.toString();
+    }
+
+    private Configuration createCommonEncodingTesterConfig() throws UnsupportedEncodingException {
+        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
+        cfg.setSourceEncoding(StandardCharsets.ISO_8859_1);
+        cfg.setLocale(Locale.US);
+        
+        ByteArrayTemplateLoader tl = new ByteArrayTemplateLoader();
+        tl.putTemplate("utf8.ftl", TEXT_WITH_ACCENTS.getBytes(StandardCharsets.UTF_8));
+        tl.putTemplate("utf16.ftl", TEXT_WITH_ACCENTS.getBytes(StandardCharsets.UTF_16LE));
+        tl.putTemplate("default.ftl", TEXT_WITH_ACCENTS.getBytes(ISO_8859_2));
+        tl.putTemplate("utf8-latin2.ftl",
+                ("<#ftl encoding='iso-8859-2'>" + TEXT_WITH_ACCENTS).getBytes(ISO_8859_2));
+        tl.putTemplate("default-latin2.ftl",
+                ("<#ftl encoding='iso-8859-2'>" + TEXT_WITH_ACCENTS).getBytes(ISO_8859_2));
+        cfg.setTemplateLoader(tl);
+        
+        TemplateConfiguration.Builder tcUtf8 = new TemplateConfiguration.Builder();
+        tcUtf8.setSourceEncoding(StandardCharsets.UTF_8);
+        TemplateConfiguration.Builder tcUtf16 = new TemplateConfiguration.Builder();
+        tcUtf16.setSourceEncoding(StandardCharsets.UTF_16LE);
+        cfg.setTemplateConfigurations(
+                new FirstMatchTemplateConfigurationFactory(
+                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*utf8*"), tcUtf8.build()),
+                        new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*utf16*"), tcUtf16.build())
+                ).allowNoMatch(true));
+        return cfg;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/88baea20/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java b/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java
index c049cde..6f8517a 100644
--- a/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java
+++ b/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java
@@ -44,10 +44,11 @@ public class TemplateGetEncodingTest {
             tl.putBinaryTemplate("bin-static", "<#test>");
             tl.putTextTemplate("text", "test");
             tl.putTextTemplate("text-static", "<#test>");
-            TemplateConfiguration staticTextTC = new TemplateConfiguration();
-            staticTextTC.setTemplateLanguage(TemplateLanguage.STATIC_TEXT);
+            TemplateConfiguration.Builder staticTextTCB = new TemplateConfiguration.Builder();
+            staticTextTCB.setTemplateLanguage(TemplateLanguage.STATIC_TEXT);
             cfg.setTemplateConfigurations(
-                    new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*-static*"), staticTextTC));
+                    new ConditionalTemplateConfigurationFactory(
+                            new FileNameGlobMatcher("*-static*"), staticTextTCB.build()));
             cfg.setTemplateLoader(tl);
             cfg.setCacheStorage(new StrongCacheStorage());
         }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/88baea20/src/test/java/org/apache/freemarker/core/templateresolver/TemplateConfigurationFactoryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/templateresolver/TemplateConfigurationFactoryTest.java b/src/test/java/org/apache/freemarker/core/templateresolver/TemplateConfigurationFactoryTest.java
index fe1eb7a..3a416d9 100644
--- a/src/test/java/org/apache/freemarker/core/templateresolver/TemplateConfigurationFactoryTest.java
+++ b/src/test/java/org/apache/freemarker/core/templateresolver/TemplateConfigurationFactoryTest.java
@@ -22,7 +22,7 @@ import static org.hamcrest.Matchers.*;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
-import java.util.Arrays;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.freemarker.core.Configuration;
@@ -159,8 +159,9 @@ public class TemplateConfigurationFactoryTest {
 
     @Test
     public void testSetConfiguration() {
-        TemplateConfiguration tc = new TemplateConfiguration();
-        ConditionalTemplateConfigurationFactory tcf = new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*"), tc);
+        TemplateConfiguration tc = new TemplateConfiguration.Builder().build();
+        ConditionalTemplateConfigurationFactory tcf = new ConditionalTemplateConfigurationFactory(
+                new FileNameGlobMatcher("*"), tc);
         assertNull(tcf.getConfiguration());
         assertNull(tc.getParentConfiguration());
         
@@ -181,10 +182,10 @@ public class TemplateConfigurationFactoryTest {
 
     @SuppressWarnings("boxing")
     private TemplateConfiguration newTemplateConfiguration(int id) {
-        TemplateConfiguration tc = new TemplateConfiguration();
-        tc.setCustomAttribute("id", id);
-        tc.setCustomAttribute("contains" + id, true);
-        return tc;
+        TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+        tcb.setCustomAttribute("id", id);
+        tcb.setCustomAttribute("contains" + id, true);
+        return tcb.build();
     }
 
     private void assertNotApplicable(TemplateConfigurationFactory tcf, String sourceName)
@@ -196,7 +197,7 @@ public class TemplateConfigurationFactoryTest {
             throws IOException, TemplateConfigurationFactoryException {
         TemplateConfiguration mergedTC = tcf.get(sourceName, DummyTemplateLoadingSource.INSTANCE);
         assertNotNull("TC should have its parents Configuration set", mergedTC.getParentConfiguration());
-        List<String> mergedTCAttNames = Arrays.asList(mergedTC.getCustomAttributeNames());
+        List<Object> mergedTCAttNames = new ArrayList<Object>(mergedTC.getCustomAttributes().keySet());
 
         for (TemplateConfiguration expectedTC : expectedTCs) {
             Integer tcId = (Integer) expectedTC.getCustomAttribute("id");
@@ -208,18 +209,18 @@ public class TemplateConfigurationFactoryTest {
             }
         }
         
-        for (String attName: mergedTCAttNames) {
-            if (!containsCustomAttr(attName, expectedTCs)) {
-                fail("The asserted TemplateConfiguration contains an unexpected custom attribute: " + attName);
+        for (Object attKey: mergedTCAttNames) {
+            if (!containsCustomAttr(attKey, expectedTCs)) {
+                fail("The asserted TemplateConfiguration contains an unexpected custom attribute: " + attKey);
             }
         }
         
         assertEquals(expectedTCs[expectedTCs.length - 1].getCustomAttribute("id"), mergedTC.getCustomAttribute("id"));
     }
 
-    private boolean containsCustomAttr(String attName, TemplateConfiguration... expectedTCs) {
+    private boolean containsCustomAttr(Object attKey, TemplateConfiguration... expectedTCs) {
         for (TemplateConfiguration expectedTC : expectedTCs) {
-            if (expectedTC.getCustomAttribute(attName) != null) {
+            if (expectedTC.getCustomAttribute(attKey) != null) {
                 return true;
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/88baea20/src/test/java/org/apache/freemarker/core/valueformat/NumberFormatTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/valueformat/NumberFormatTest.java b/src/test/java/org/apache/freemarker/core/valueformat/NumberFormatTest.java
index 40dd4d6..327bd94 100644
--- a/src/test/java/org/apache/freemarker/core/valueformat/NumberFormatTest.java
+++ b/src/test/java/org/apache/freemarker/core/valueformat/NumberFormatTest.java
@@ -245,11 +245,12 @@ public class NumberFormatTest extends TemplateTest {
                 "d", new AliasTemplateNumberFormatFactory("0.0#"),
                 "hex", HexTemplateNumberFormatFactory.INSTANCE));
         
-        TemplateConfiguration tc = new TemplateConfiguration();
-        tc.setCustomNumberFormats(ImmutableMap.of(
+        TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
+        tcb.setCustomNumberFormats(ImmutableMap.of(
                 "d", new AliasTemplateNumberFormatFactory("0.#'d'"),
                 "i", new AliasTemplateNumberFormatFactory("@hex")));
-        cfg.setTemplateConfigurations(new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*2*"), tc));
+        cfg.setTemplateConfigurations(
+                new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*2*"), tcb.build()));
         
         String commonFtl = "${1?string.@f} ${1?string.@d} "
                 + "<#setting locale='fr_FR'>${1.5?string.@d} "

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/88baea20/src/test/java/org/apache/freemarker/manualtest/ConfigureOutputFormatExamples.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/manualtest/ConfigureOutputFormatExamples.java b/src/test/java/org/apache/freemarker/manualtest/ConfigureOutputFormatExamples.java
index ed4fb21..85ffa81 100644
--- a/src/test/java/org/apache/freemarker/manualtest/ConfigureOutputFormatExamples.java
+++ b/src/test/java/org/apache/freemarker/manualtest/ConfigureOutputFormatExamples.java
@@ -46,13 +46,13 @@ public class ConfigureOutputFormatExamples extends ExamplesTest {
         
         // Example 2/a:
         {
-            TemplateConfiguration tcHTML = new TemplateConfiguration();
+            TemplateConfiguration.Builder tcHTML = new TemplateConfiguration.Builder();
             tcHTML.setOutputFormat(HTMLOutputFormat.INSTANCE);
             
             cfg.setTemplateConfigurations(
                     new ConditionalTemplateConfigurationFactory(
                             new PathGlobMatcher("mail/**"),
-                            tcHTML));
+                            tcHTML.build()));
             
             assertEquals(HTMLOutputFormat.INSTANCE, cfg.getTemplate("mail/t.ftl").getOutputFormat());
         }
@@ -68,28 +68,28 @@ public class ConfigureOutputFormatExamples extends ExamplesTest {
         
         // Example 3/a:
         {
-            TemplateConfiguration tcHTML = new TemplateConfiguration();
+            TemplateConfiguration.Builder tcHTML = new TemplateConfiguration.Builder();
             tcHTML.setOutputFormat(HTMLOutputFormat.INSTANCE);
             
-            TemplateConfiguration tcXML = new TemplateConfiguration();
+            TemplateConfiguration.Builder tcXML = new TemplateConfiguration.Builder();
             tcXML.setOutputFormat(XMLOutputFormat.INSTANCE);
 
-            TemplateConfiguration tcRTF = new TemplateConfiguration();
+            TemplateConfiguration.Builder tcRTF = new TemplateConfiguration.Builder();
             tcRTF.setOutputFormat(RTFOutputFormat.INSTANCE);
             
             cfg.setTemplateConfigurations(
                     new FirstMatchTemplateConfigurationFactory(
                             new ConditionalTemplateConfigurationFactory(
                                     new FileExtensionMatcher("xml"),
-                                    tcXML),
+                                    tcXML.build()),
                             new ConditionalTemplateConfigurationFactory(
                                     new OrMatcher(
                                             new FileExtensionMatcher("html"),
                                             new FileExtensionMatcher("htm")),
-                                    tcHTML),
+                                    tcHTML.build()),
                             new ConditionalTemplateConfigurationFactory(
                                     new FileExtensionMatcher("rtf"),
-                                    tcRTF)
+                                    tcRTF.build())
                     ).allowNoMatch(true)
             );
             

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/88baea20/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java b/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java
index 3896a2e..eded767 100644
--- a/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java
+++ b/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java
@@ -48,13 +48,13 @@ public class TemplateConfigurationExamples extends ExamplesTest {
 
         addTemplate("t.xml", "");
         
-        TemplateConfiguration tcUTF8XML = new TemplateConfiguration();
-        tcUTF8XML.setSourceEncoding(StandardCharsets.UTF_8);
-        tcUTF8XML.setOutputFormat(XMLOutputFormat.INSTANCE);
+        TemplateConfiguration.Builder tcbUTF8XML = new TemplateConfiguration.Builder();
+        tcbUTF8XML.setSourceEncoding(StandardCharsets.UTF_8);
+        tcbUTF8XML.setOutputFormat(XMLOutputFormat.INSTANCE);
 
         {
             cfg.setTemplateConfigurations(new ConditionalTemplateConfigurationFactory(
-                    new FileExtensionMatcher("xml"), tcUTF8XML));
+                    new FileExtensionMatcher("xml"), tcbUTF8XML.build()));
             
             Template t = cfg.getTemplate("t.xml");
             assertEquals(StandardCharsets.UTF_8, t.getSourceEncoding());
@@ -79,11 +79,11 @@ public class TemplateConfigurationExamples extends ExamplesTest {
         addTemplate("mail/t.subject.ftl", "");
         addTemplate("mail/t.body.ftl", "");
 
-        TemplateConfiguration tcSubject = new TemplateConfiguration();
-        tcSubject.setOutputFormat(PlainTextOutputFormat.INSTANCE);
+        TemplateConfiguration.Builder tcbSubject = new TemplateConfiguration.Builder();
+        tcbSubject.setOutputFormat(PlainTextOutputFormat.INSTANCE);
         
-        TemplateConfiguration tcBody = new TemplateConfiguration();
-        tcBody.setOutputFormat(HTMLOutputFormat.INSTANCE);
+        TemplateConfiguration.Builder tcbBody = new TemplateConfiguration.Builder();
+        tcbBody.setOutputFormat(HTMLOutputFormat.INSTANCE);
         
         cfg.setTemplateConfigurations(
                 new ConditionalTemplateConfigurationFactory(
@@ -91,10 +91,10 @@ public class TemplateConfigurationExamples extends ExamplesTest {
                         new FirstMatchTemplateConfigurationFactory(
                                 new ConditionalTemplateConfigurationFactory(
                                         new FileNameGlobMatcher("*.subject.*"),
-                                        tcSubject),
+                                        tcbSubject.build()),
                                 new ConditionalTemplateConfigurationFactory(
                                         new FileNameGlobMatcher("*.body.*"),
-                                        tcBody)
+                                        tcbBody.build())
                                 )
                                 .noMatchErrorDetails("Mail template names must contain \".subject.\" or \".body.\"!")
                         ));
@@ -125,38 +125,38 @@ public class TemplateConfigurationExamples extends ExamplesTest {
         addTemplate("t.xml", "");
         addTemplate("mail/t.html", "");
 
-        TemplateConfiguration tcStats = new TemplateConfiguration();
-        tcStats.setDateTimeFormat("iso");
-        tcStats.setDateFormat("iso");
-        tcStats.setTimeFormat("iso");
-        tcStats.setTimeZone(_DateUtil.UTC);
+        TemplateConfiguration.Builder tcbStats = new TemplateConfiguration.Builder();
+        tcbStats.setDateTimeFormat("iso");
+        tcbStats.setDateFormat("iso");
+        tcbStats.setTimeFormat("iso");
+        tcbStats.setTimeZone(_DateUtil.UTC);
 
-        TemplateConfiguration tcMail = new TemplateConfiguration();
-        tcMail.setSourceEncoding(StandardCharsets.UTF_8);
+        TemplateConfiguration.Builder tcbMail = new TemplateConfiguration.Builder();
+        tcbMail.setSourceEncoding(StandardCharsets.UTF_8);
         
-        TemplateConfiguration tcHTML = new TemplateConfiguration();
-        tcHTML.setOutputFormat(HTMLOutputFormat.INSTANCE);
+        TemplateConfiguration.Builder tcbHTML = new TemplateConfiguration.Builder();
+        tcbHTML.setOutputFormat(HTMLOutputFormat.INSTANCE);
         
-        TemplateConfiguration tcXML = new TemplateConfiguration();
-        tcXML.setOutputFormat(XMLOutputFormat.INSTANCE);
+        TemplateConfiguration.Builder tcbXML = new TemplateConfiguration.Builder();
+        tcbXML.setOutputFormat(XMLOutputFormat.INSTANCE);
         
         cfg.setTemplateConfigurations(
                 new MergingTemplateConfigurationFactory(
                         new ConditionalTemplateConfigurationFactory(
                                 new FileNameGlobMatcher("*.stats.*"),
-                                tcStats),
+                                tcbStats.build()),
                         new ConditionalTemplateConfigurationFactory(
                                 new PathGlobMatcher("mail/**"),
-                                tcMail),
+                                tcbMail.build()),
                         new FirstMatchTemplateConfigurationFactory(
                                 new ConditionalTemplateConfigurationFactory(
                                         new FileExtensionMatcher("xml"),
-                                        tcXML),
+                                        tcbXML.build()),
                                 new ConditionalTemplateConfigurationFactory(
                                         new OrMatcher(
                                                 new FileExtensionMatcher("html"),
                                                 new FileExtensionMatcher("htm")),
-                                        tcHTML)
+                                        tcbHTML.build())
                         ).allowNoMatch(true)
                 )
         );

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/88baea20/src/test/java/org/apache/freemarker/servlet/FreemarkerServletTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/servlet/FreemarkerServletTest.java b/src/test/java/org/apache/freemarker/servlet/FreemarkerServletTest.java
index d638025..85b4c13 100644
--- a/src/test/java/org/apache/freemarker/servlet/FreemarkerServletTest.java
+++ b/src/test/java/org/apache/freemarker/servlet/FreemarkerServletTest.java
@@ -547,18 +547,18 @@ public class FreemarkerServletTest {
             cfg.setSourceEncoding(CFG_DEFAULT_ENCODING);
 
             {
-                TemplateConfiguration outUtf8TC = new TemplateConfiguration();
-                outUtf8TC.setOutputEncoding(StandardCharsets.UTF_8);
+                TemplateConfiguration.Builder outUtf8TCB = new TemplateConfiguration.Builder();
+                outUtf8TCB.setOutputEncoding(StandardCharsets.UTF_8);
                 
-                TemplateConfiguration srcUtf8TC = new TemplateConfiguration();
-                srcUtf8TC.setSourceEncoding(StandardCharsets.UTF_8);
+                TemplateConfiguration.Builder srcUtf8TCB = new TemplateConfiguration.Builder();
+                srcUtf8TCB.setSourceEncoding(StandardCharsets.UTF_8);
                 
                 cfg.setTemplateConfigurations(
                         new FirstMatchTemplateConfigurationFactory(
                                 new ConditionalTemplateConfigurationFactory(
-                                        new FileNameGlobMatcher(FOO_SRC_UTF8_FTL), srcUtf8TC),
+                                        new FileNameGlobMatcher(FOO_SRC_UTF8_FTL), srcUtf8TCB.build()),
                                 new ConditionalTemplateConfigurationFactory(
-                                        new FileNameGlobMatcher(FOO_OUT_UTF8_FTL), outUtf8TC)
+                                        new FileNameGlobMatcher(FOO_OUT_UTF8_FTL), outUtf8TCB.build())
                         )
                         .allowNoMatch(true)
                 );


Mime
View raw message