freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [04/11] incubator-freemarker git commit: Configuration is now immutable. Instead, you should use Configuration.Builder to set up the setting values, then create the Configuration with the builder's build() method. FreemarkerServlet (including some of its
Date Fri, 05 May 2017 21:00:27 GMT
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d61a45d/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 d651b9d..00b6b3c 100644
--- a/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
+++ b/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.freemarker.core;
 
+import static org.apache.freemarker.core.ParsingConfiguration.*;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
@@ -35,10 +36,13 @@ import org.apache.freemarker.core.outputformat.impl.XMLOutputFormat;
 import org.apache.freemarker.core.templateresolver.ConditionalTemplateConfigurationFactory;
 import org.apache.freemarker.core.templateresolver.FileNameGlobMatcher;
 import org.apache.freemarker.core.templateresolver.OrMatcher;
+import org.apache.freemarker.core.templateresolver.impl.NullCacheStorage;
 import org.apache.freemarker.core.userpkg.CustomHTMLOutputFormat;
 import org.apache.freemarker.core.userpkg.DummyOutputFormat;
 import org.apache.freemarker.core.userpkg.SeldomEscapedOutputFormat;
 import org.apache.freemarker.test.TemplateTest;
+import org.apache.freemarker.test.TestConfigurationBuilder;
+import org.junit.Before;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
@@ -51,34 +55,35 @@ public class OutputFormatTest extends TemplateTest {
         addTemplate("t.xml", "${.outputFormat}");
         addTemplate("tWithHeader", "<#ftl outputFormat='HTML'>${.outputFormat}");
         
-        Configuration cfg = getConfiguration();
+        TestConfigurationBuilder cfgB = createDefaultConfigurationBuilder();
         for (OutputFormat cfgOutputFormat
                 : new OutputFormat[] { UndefinedOutputFormat.INSTANCE, RTFOutputFormat.INSTANCE } ) {
             if (!cfgOutputFormat.equals(UndefinedOutputFormat.INSTANCE)) {
-                cfg.setOutputFormat(cfgOutputFormat);
+                cfgB.setOutputFormat(cfgOutputFormat);
             }
-            
-            assertEquals(cfgOutputFormat, cfg.getOutputFormat());
+            setConfiguration(cfgB.build());
+
+            assertEquals(cfgOutputFormat, getConfiguration().getOutputFormat());
             
             {
-                Template t = cfg.getTemplate("t");
+                Template t = getConfiguration().getTemplate("t");
                 assertEquals(cfgOutputFormat, t.getOutputFormat());
                 assertOutput(t, t.getOutputFormat().getName());
             }
             
             {
-                Template t = cfg.getTemplate("t.xml");
+                Template t = getConfiguration().getTemplate("t.xml");
                 assertEquals(XMLOutputFormat.INSTANCE, t.getOutputFormat());
                 assertOutput(t, t.getOutputFormat().getName());
             }
             
             {
-                Template t = cfg.getTemplate("tWithHeader");
+                Template t = getConfiguration().getTemplate("tWithHeader");
                 assertEquals(HTMLOutputFormat.INSTANCE, t.getOutputFormat());
                 assertOutput(t, t.getOutputFormat().getName());
             }
             
-            cfg.clearTemplateCache();
+            getConfiguration().clearTemplateCache();
         }
     }
     
@@ -95,7 +100,7 @@ public class OutputFormatTest extends TemplateTest {
         addTemplate("t.fTlX", commonContent);
         addTemplate("tWithHeader.ftlx", "<#ftl outputFormat='HTML'>" + commonContent);
         
-        Configuration cfg = getConfiguration();
+        TestConfigurationBuilder cfgB = createDefaultConfigurationBuilder();
         for (int setupNumber = 1; setupNumber <= 3; setupNumber++) {
             final OutputFormat cfgOutputFormat;
             final OutputFormat ftlhOutputFormat;
@@ -108,16 +113,16 @@ public class OutputFormatTest extends TemplateTest {
                 break;
             case 2:
                 cfgOutputFormat = RTFOutputFormat.INSTANCE;
-                cfg.setOutputFormat(cfgOutputFormat);
+                cfgB.setOutputFormat(cfgOutputFormat);
                 ftlhOutputFormat = HTMLOutputFormat.INSTANCE;
                 ftlxOutputFormat = XMLOutputFormat.INSTANCE;
                 break;
             case 3:
                 cfgOutputFormat = UndefinedOutputFormat.INSTANCE;
-                cfg.unsetOutputFormat();
+                cfgB.unsetOutputFormat();
                 TemplateConfiguration.Builder tcbXML = new TemplateConfiguration.Builder();
                 tcbXML.setOutputFormat(XMLOutputFormat.INSTANCE);
-                cfg.setTemplateConfigurations(
+                cfgB.setTemplateConfigurations(
                         new ConditionalTemplateConfigurationFactory(
                                 new OrMatcher(
                                         new FileNameGlobMatcher("*.ftlh"),
@@ -130,40 +135,41 @@ public class OutputFormatTest extends TemplateTest {
             default:
                 throw new AssertionError();
             }
-            
-            assertEquals(cfgOutputFormat, cfg.getOutputFormat());
+
+            setConfiguration(cfgB.build());
+            assertEquals(cfgOutputFormat, getConfiguration().getOutputFormat());
             
             {
-                Template t = cfg.getTemplate("t");
+                Template t = getConfiguration().getTemplate("t");
                 assertEquals(cfgOutputFormat, t.getOutputFormat());
                 assertOutput(t, t.getOutputFormat().getName());
             }
             
             {
-                Template t = cfg.getTemplate("t.ftl");
+                Template t = getConfiguration().getTemplate("t.ftl");
                 assertEquals(cfgOutputFormat, t.getOutputFormat());
                 assertOutput(t, t.getOutputFormat().getName());
             }
             
             for (String name : new String[] { "t.ftlh", "t.FTLH", "t.fTlH" }) {
-                Template t = cfg.getTemplate(name);
+                Template t = getConfiguration().getTemplate(name);
                 assertEquals(ftlhOutputFormat, t.getOutputFormat());
                 assertOutput(t, t.getOutputFormat().getName());
             }
             
             for (String name : new String[] { "t.ftlx", "t.FTLX", "t.fTlX" }) {
-                Template t = cfg.getTemplate(name);
+                Template t = getConfiguration().getTemplate(name);
                 assertEquals(ftlxOutputFormat, t.getOutputFormat());
                 assertOutput(t, t.getOutputFormat().getName());
             }
 
             {
-                Template t = cfg.getTemplate("tWithHeader.ftlx");
+                Template t = getConfiguration().getTemplate("tWithHeader.ftlx");
                 assertEquals(HTMLOutputFormat.INSTANCE, t.getOutputFormat());
                 assertOutput(t, t.getOutputFormat().getName());
             }
-            
-            cfg.clearTemplateCache();
+
+            getConfiguration().clearTemplateCache();
         }
     }
     
@@ -174,49 +180,62 @@ public class OutputFormatTest extends TemplateTest {
         addTemplate("t.ftl",
                 "${'{}'} ${'{}'?esc} ${'{}'?noEsc}");
         
-        TemplateConfiguration.Builder tcbHTML = new TemplateConfiguration.Builder();
-        tcbHTML.setOutputFormat(HTMLOutputFormat.INSTANCE);
         ConditionalTemplateConfigurationFactory tcfHTML = new ConditionalTemplateConfigurationFactory(
-                new FileNameGlobMatcher("t.*"), tcbHTML.build());
+                new FileNameGlobMatcher("t.*"),
+                new TemplateConfiguration.Builder()
+                        .outputFormat(HTMLOutputFormat.INSTANCE)
+                        .build());
 
-        TemplateConfiguration.Builder tcbNoAutoEsc = new TemplateConfiguration.Builder();
-        tcbNoAutoEsc.setAutoEscapingPolicy(Configuration.DISABLE_AUTO_ESCAPING_POLICY);
         ConditionalTemplateConfigurationFactory tcfNoAutoEsc = new ConditionalTemplateConfigurationFactory(
-                new FileNameGlobMatcher("t.*"), tcbNoAutoEsc.build());
+                new FileNameGlobMatcher("t.*"),
+                new TemplateConfiguration.Builder()
+                        .autoEscapingPolicy(DISABLE_AUTO_ESCAPING_POLICY)
+                        .build());
 
-        Configuration cfg = getConfiguration();
-        cfg.setOutputFormat(HTMLOutputFormat.INSTANCE);
-        assertOutputForNamed("t.ftlx", "&apos; &apos; '");  // Can't override it
-        cfg.setTemplateConfigurations(tcfHTML);
-        assertOutputForNamed("t.ftlx", "&apos; &apos; '");  // Can't override it
-        cfg.setTemplateConfigurations(tcfNoAutoEsc);
-        assertOutputForNamed("t.ftlx", "&apos; &apos; '");  // Can't override it
-        
-        cfg.setTemplateConfigurations(null);
-        cfg.unsetOutputFormat();
-        cfg.setRecognizeStandardFileExtensions(false);
-        assertErrorContainsForNamed("t.ftlx", UndefinedOutputFormat.INSTANCE.getName());
-        cfg.setOutputFormat(HTMLOutputFormat.INSTANCE);
-        assertOutputForNamed("t.ftlx", "&#39; &#39; '");
-        cfg.setOutputFormat(XMLOutputFormat.INSTANCE);
-        assertOutputForNamed("t.ftlx", "&apos; &apos; '");
-        cfg.setTemplateConfigurations(tcfHTML);
-        assertOutputForNamed("t.ftlx", "&#39; &#39; '");
-        cfg.setTemplateConfigurations(tcfNoAutoEsc);
-        assertOutputForNamed("t.ftlx", "' &apos; '");
-        
-        cfg.setRecognizeStandardFileExtensions(true);
-        cfg.setTemplateConfigurations(tcfHTML);
-        assertOutputForNamed("t.ftlx", "&apos; &apos; '");  // Can't override it
-        cfg.setTemplateConfigurations(tcfNoAutoEsc);
-        assertOutputForNamed("t.ftlx", "&apos; &apos; '");  // Can't override it
-        
-        cfg.setTemplateConfigurations(null);
-        cfg.unsetOutputFormat();
-        cfg.setTemplateConfigurations(tcfHTML);
-        assertOutputForNamed("t.ftlx", "&apos; &apos; '");  // Can't override it
-        cfg.setRecognizeStandardFileExtensions(false);
-        assertOutputForNamed("t.ftlx", "&#39; &#39; '");
+        {
+            TestConfigurationBuilder cfgB = createDefaultConfigurationBuilder();
+
+            setConfiguration(cfgB.outputFormat(HTMLOutputFormat.INSTANCE).build());
+            assertOutputForNamed("t.ftlx", "&apos; &apos; '");  // Can't override it
+            setConfiguration(cfgB.templateConfigurations(tcfHTML).build());
+            assertOutputForNamed("t.ftlx", "&apos; &apos; '");  // Can't override it
+            setConfiguration(cfgB.templateConfigurations(tcfNoAutoEsc).build());
+            assertOutputForNamed("t.ftlx", "&apos; &apos; '");  // Can't override it
+        }
+
+        {
+            TestConfigurationBuilder cfgB = createDefaultConfigurationBuilder();
+
+            setConfiguration(cfgB.recognizeStandardFileExtensions(false).build());
+            assertErrorContainsForNamed("t.ftlx", UndefinedOutputFormat.INSTANCE.getName());
+            setConfiguration(cfgB.outputFormat(HTMLOutputFormat.INSTANCE).build());
+            assertOutputForNamed("t.ftlx", "&#39; &#39; '");
+            setConfiguration(cfgB.outputFormat(XMLOutputFormat.INSTANCE).build());
+            assertOutputForNamed("t.ftlx", "&apos; &apos; '");
+            setConfiguration(cfgB.templateConfigurations(tcfHTML).build());
+            assertOutputForNamed("t.ftlx", "&#39; &#39; '");
+            setConfiguration(cfgB.templateConfigurations(tcfNoAutoEsc).build());
+            assertOutputForNamed("t.ftlx", "' &apos; '");
+        }
+
+        {
+            TestConfigurationBuilder cfgB = createDefaultConfigurationBuilder();
+            cfgB.setRecognizeStandardFileExtensions(true);
+
+            setConfiguration(cfgB.templateConfigurations(tcfHTML).build());
+            assertOutputForNamed("t.ftlx", "&apos; &apos; '");  // Can't override it
+            setConfiguration(cfgB.templateConfigurations(tcfNoAutoEsc).build());
+            assertOutputForNamed("t.ftlx", "&apos; &apos; '");  // Can't override it
+        }
+
+        {
+            TestConfigurationBuilder cfgB = createDefaultConfigurationBuilder();
+
+            setConfiguration(cfgB.templateConfigurations(tcfHTML).build());
+            assertOutputForNamed("t.ftlx", "&apos; &apos; '");  // Can't override it
+            setConfiguration(cfgB.recognizeStandardFileExtensions(false).build());
+            assertOutputForNamed("t.ftlx", "&#39; &#39; '");
+        }
     }
 
     @Test
@@ -249,10 +268,17 @@ public class OutputFormatTest extends TemplateTest {
     @Test
     public void testStandardFileExtensionsFormatterImplOverriding() throws Exception {
         addTemplate("t.ftlh", "${'a&x'}");
+
         assertOutputForNamed("t.ftlh", "a&amp;x");
-        getConfiguration().setRegisteredCustomOutputFormats(Collections.singleton(CustomHTMLOutputFormat.INSTANCE));
+
+        setConfiguration(new TestConfigurationBuilder()
+                .registeredCustomOutputFormats(Collections.singleton(CustomHTMLOutputFormat.INSTANCE))
+                .build());
         assertOutputForNamed("t.ftlh", "a&amp;X");
-        getConfiguration().setRegisteredCustomOutputFormats(Collections.<OutputFormat>emptyList());
+
+        setConfiguration(new TestConfigurationBuilder()
+                .registeredCustomOutputFormats(Collections.<OutputFormat>emptyList())
+                .build());
         assertOutputForNamed("t.ftlh", "a&amp;x");
     }
     
@@ -262,47 +288,47 @@ public class OutputFormatTest extends TemplateTest {
         addTemplate("tWithHeaderFalse", "<#ftl autoEsc=false>${'a&b'}");
         addTemplate("tWithHeaderTrue", "<#ftl autoEsc=true>${'a&b'}");
         
-        Configuration cfg = getConfiguration();
-        
-        assertEquals(Configuration.ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY, cfg.getAutoEscapingPolicy());
-        
-        cfg.setOutputFormat(XMLOutputFormat.INSTANCE);
-        
+        TestConfigurationBuilder cfgB = createDefaultConfigurationBuilder().outputFormat(XMLOutputFormat.INSTANCE);
+        assertEquals(ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY, cfgB.getAutoEscapingPolicy());
+
         for (boolean cfgAutoEscaping : new boolean[] { true, false }) {
             if (!cfgAutoEscaping) {
-                cfg.setAutoEscapingPolicy(Configuration.DISABLE_AUTO_ESCAPING_POLICY);
+                cfgB.setAutoEscapingPolicy(DISABLE_AUTO_ESCAPING_POLICY);
             }
-            
+            setConfiguration(cfgB.build());
+
             {
-                Template t = cfg.getTemplate("t");
+                Template t = getConfiguration().getTemplate("t");
                 if (cfgAutoEscaping) {
-                    assertEquals(Configuration.ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY, t.getAutoEscapingPolicy());
+                    assertEquals(ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY, t.getAutoEscapingPolicy());
                     assertOutput(t, "a&amp;b");
                 } else {
-                    assertEquals(Configuration.DISABLE_AUTO_ESCAPING_POLICY, t.getAutoEscapingPolicy());
+                    assertEquals(DISABLE_AUTO_ESCAPING_POLICY, t.getAutoEscapingPolicy());
                     assertOutput(t, "a&b");
                 }
             }
             
             {
-                Template t = cfg.getTemplate("tWithHeaderFalse");
-                assertEquals(Configuration.DISABLE_AUTO_ESCAPING_POLICY, t.getAutoEscapingPolicy());
+                Template t = getConfiguration().getTemplate("tWithHeaderFalse");
+                assertEquals(DISABLE_AUTO_ESCAPING_POLICY, t.getAutoEscapingPolicy());
                 assertOutput(t, "a&b");
             }
             
             {
-                Template t = cfg.getTemplate("tWithHeaderTrue");
-                assertEquals(Configuration.ENABLE_IF_SUPPORTED_AUTO_ESCAPING_POLICY, t.getAutoEscapingPolicy());
+                Template t = getConfiguration().getTemplate("tWithHeaderTrue");
+                assertEquals(ENABLE_IF_SUPPORTED_AUTO_ESCAPING_POLICY, t.getAutoEscapingPolicy());
                 assertOutput(t, "a&amp;b");
             }
-            
-            cfg.clearTemplateCache();
+
+            getConfiguration().clearTemplateCache();
         }
     }
     
     @Test
     public void testNumericalInterpolation() throws IOException, TemplateException {
-        getConfiguration().setRegisteredCustomOutputFormats(Collections.singleton(DummyOutputFormat.INSTANCE));
+        setConfiguration(new TestConfigurationBuilder()
+                .registeredCustomOutputFormats(Collections.singleton(DummyOutputFormat.INSTANCE))
+                .build());
         assertOutput(
                 "<#ftl outputFormat='dummy'>#{1.5}; #{1.5; m3}; ${'a.b'}",
                 "1\\.5; 1\\.500; a\\.b");
@@ -331,13 +357,15 @@ public class OutputFormatTest extends TemplateTest {
     
     @Test
     public void testAutoEscapingOnMOs() throws IOException, TemplateException {
-        for (int autoEsc = 0; autoEsc < 2; autoEsc++) {
+        for (boolean cfgAutoEscaping : new boolean[] { true, false }) {
             String commonAutoEscFtl = "<#ftl outputFormat='HTML'>${'&'}";
-            if (autoEsc == 0) {
+            if (cfgAutoEscaping) {
                 // Cfg default is autoEscaping true
                 assertOutput(commonAutoEscFtl, "&amp;");
             } else {
-                getConfiguration().setAutoEscapingPolicy(Configuration.DISABLE_AUTO_ESCAPING_POLICY);
+                setConfiguration(createDefaultConfigurationBuilder()
+                        .autoEscapingPolicy(DISABLE_AUTO_ESCAPING_POLICY)
+                        .build());
                 assertOutput(commonAutoEscFtl, "&");
             }
             
@@ -408,7 +436,7 @@ public class OutputFormatTest extends TemplateTest {
         }
         
         {
-            getConfiguration().setOutputFormat(HTMLOutputFormat.INSTANCE);
+            setConfiguration(new TestConfigurationBuilder().outputFormat(HTMLOutputFormat.INSTANCE).build());
             Template t = Template.createPlainTextTemplate("x", content, getConfiguration());
             Writer sw = new StringWriter();
             t.process(null, sw);
@@ -621,7 +649,9 @@ public class OutputFormatTest extends TemplateTest {
         assertErrorContains(
                 "<#outputFormat 'dummy'></#outputFormat>",
                 "dummy", "nregistered");
-        getConfiguration().setRegisteredCustomOutputFormats(Collections.singleton(DummyOutputFormat.INSTANCE));
+        setConfiguration(new TestConfigurationBuilder()
+                .registeredCustomOutputFormats(Collections.singleton(DummyOutputFormat.INSTANCE))
+                .build());
         assertOutput(
                 "<#outputFormat 'dummy'>${.outputFormat}</#outputFormat>",
                 "dummy");
@@ -692,7 +722,9 @@ public class OutputFormatTest extends TemplateTest {
                 "<#noautoEsc></#noautoEsc>",
                 "Unknown directive");
 
-        getConfiguration().setOutputFormat(XMLOutputFormat.INSTANCE);
+        setConfiguration(new TestConfigurationBuilder()
+                .outputFormat(XMLOutputFormat.INSTANCE)
+                .build());
         
         // Empty block:
         assertOutput(
@@ -746,36 +778,41 @@ public class OutputFormatTest extends TemplateTest {
 
     @Test
     public void testAutoEscPolicy() throws Exception {
-        Configuration cfg = getConfiguration();
-        cfg.setRegisteredCustomOutputFormats(ImmutableList.of(
+        TestConfigurationBuilder cfgB = createDefaultConfigurationBuilder();
+        cfgB.setRegisteredCustomOutputFormats(ImmutableList.of(
                 SeldomEscapedOutputFormat.INSTANCE, DummyOutputFormat.INSTANCE));
-        assertEquals(Configuration.ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY, cfg.getAutoEscapingPolicy());
+        assertEquals(ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY, cfgB.getAutoEscapingPolicy());
         
         String commonFTL = "${'.'} ${.autoEsc?c}";
         String notEsced = ". false";
         String esced = "\\. true";
 
         for (int autoEscPolicy : new int[] {
-                Configuration.ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY,
-                Configuration.ENABLE_IF_SUPPORTED_AUTO_ESCAPING_POLICY,
-                Configuration.DISABLE_AUTO_ESCAPING_POLICY }) {
-            cfg.setAutoEscapingPolicy(autoEscPolicy);
+                ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY,
+                ENABLE_IF_SUPPORTED_AUTO_ESCAPING_POLICY,
+                DISABLE_AUTO_ESCAPING_POLICY }) {
+            cfgB.setAutoEscapingPolicy(autoEscPolicy);
             
-            String sExpted = autoEscPolicy == Configuration.ENABLE_IF_SUPPORTED_AUTO_ESCAPING_POLICY ? esced : notEsced;
-            cfg.setOutputFormat(SeldomEscapedOutputFormat.INSTANCE);
+            String sExpted = autoEscPolicy == ENABLE_IF_SUPPORTED_AUTO_ESCAPING_POLICY ? esced : notEsced;
+            cfgB.setOutputFormat(SeldomEscapedOutputFormat.INSTANCE);
+            setConfiguration(cfgB.build());
             assertOutput(commonFTL, sExpted);
-            cfg.setOutputFormat(UndefinedOutputFormat.INSTANCE);
+            cfgB.setOutputFormat(UndefinedOutputFormat.INSTANCE);
+            setConfiguration(cfgB.build());
             assertOutput("<#ftl outputFormat='seldomEscaped'>" + commonFTL, sExpted);
             assertOutput("<#outputFormat 'seldomEscaped'>" + commonFTL + "</#outputFormat>", sExpted);
             
-            String dExpted = autoEscPolicy == Configuration.DISABLE_AUTO_ESCAPING_POLICY ? notEsced : esced;
-            cfg.setOutputFormat(DummyOutputFormat.INSTANCE);
+            String dExpted = autoEscPolicy == DISABLE_AUTO_ESCAPING_POLICY ? notEsced : esced;
+            cfgB.setOutputFormat(DummyOutputFormat.INSTANCE);
+            setConfiguration(cfgB.build());
             assertOutput(commonFTL, dExpted);
-            cfg.setOutputFormat(UndefinedOutputFormat.INSTANCE);
+            cfgB.setOutputFormat(UndefinedOutputFormat.INSTANCE);
+            setConfiguration(cfgB.build());
             assertOutput("<#ftl outputFormat='dummy'>" + commonFTL, dExpted);
             assertOutput("<#outputFormat 'dummy'>" + commonFTL + "</#outputFormat>", dExpted);
             
-            cfg.setOutputFormat(DummyOutputFormat.INSTANCE);
+            cfgB.setOutputFormat(DummyOutputFormat.INSTANCE);
+            setConfiguration(cfgB.build());
             assertOutput(
                     commonFTL
                     + "<#outputFormat 'seldomEscaped'>"
@@ -882,8 +919,6 @@ public class OutputFormatTest extends TemplateTest {
     @Test
     public void testBannedBIsWhenAutoEscaping() throws Exception {
         for (String biName : new String[] { "html", "xhtml", "rtf", "xml" }) {
-            getConfiguration().setIncompatibleImprovements(Configuration.VERSION_3_0_0);
-            
             String commonFTL = "${'x'?" + biName + "}";
             assertOutput(commonFTL, "x");
             assertErrorContains("<#ftl outputFormat='HTML'>" + commonFTL,
@@ -1003,24 +1038,31 @@ public class OutputFormatTest extends TemplateTest {
         assertOutput("${m1?isMarkupOutput?c} ${m2?isMarkupOutput?c} ${s?isMarkupOutput?c}", "true true false");
         assertOutput("${m1?is_markup_output?c}", "true");
     }
-    
-    @Override
-    protected Configuration createConfiguration() throws TemplateModelException {
-        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
-        
-        TemplateConfiguration.Builder tcbXML = new TemplateConfiguration.Builder();
-        tcbXML.setOutputFormat(XMLOutputFormat.INSTANCE);
-        cfg.setTemplateConfigurations(
-                new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*.xml"), tcbXML.build()));
 
-        cfg.setSharedVariable("rtfPlain", RTFOutputFormat.INSTANCE.fromPlainTextByEscaping("\\par a & b"));
-        cfg.setSharedVariable("rtfMarkup", RTFOutputFormat.INSTANCE.fromMarkup("\\par c"));
-        cfg.setSharedVariable("htmlPlain", HTMLOutputFormat.INSTANCE.fromPlainTextByEscaping("a < {h'}"));
-        cfg.setSharedVariable("htmlMarkup", HTMLOutputFormat.INSTANCE.fromMarkup("<p>c"));
-        cfg.setSharedVariable("xmlPlain", XMLOutputFormat.INSTANCE.fromPlainTextByEscaping("a < {x'}"));
-        cfg.setSharedVariable("xmlMarkup", XMLOutputFormat.INSTANCE.fromMarkup("<p>c</p>"));
-        
-        return cfg;
+    private TestConfigurationBuilder createDefaultConfigurationBuilder() throws TemplateModelException {
+        return new TestConfigurationBuilder()
+                .templateConfigurations(
+                        new ConditionalTemplateConfigurationFactory(
+                                new FileNameGlobMatcher("*.xml"),
+                                new TemplateConfiguration.Builder()
+                                        .outputFormat(XMLOutputFormat.INSTANCE)
+                                        .build()))
+                .cacheStorage(NullCacheStorage.INSTANCE); // Prevent caching as we change the cfgB between build().
+    }
+
+    @Before
+    public void addCommonDataModelVariables() throws TemplateModelException {
+        addToDataModel("rtfPlain", RTFOutputFormat.INSTANCE.fromPlainTextByEscaping("\\par a & b"));
+        addToDataModel("rtfMarkup", RTFOutputFormat.INSTANCE.fromMarkup("\\par c"));
+        addToDataModel("htmlPlain", HTMLOutputFormat.INSTANCE.fromPlainTextByEscaping("a < {h'}"));
+        addToDataModel("htmlMarkup", HTMLOutputFormat.INSTANCE.fromMarkup("<p>c"));
+        addToDataModel("xmlPlain", XMLOutputFormat.INSTANCE.fromPlainTextByEscaping("a < {x'}"));
+        addToDataModel("xmlMarkup", XMLOutputFormat.INSTANCE.fromMarkup("<p>c</p>"));
+    }
+
+    @Override
+    protected Configuration createDefaultConfiguration() throws TemplateModelException {
+        return createDefaultConfigurationBuilder().build();
     }
     
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d61a45d/src/test/java/org/apache/freemarker/core/ParsingErrorMessagesTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/ParsingErrorMessagesTest.java b/src/test/java/org/apache/freemarker/core/ParsingErrorMessagesTest.java
index 8190e6e..8f20d6c 100644
--- a/src/test/java/org/apache/freemarker/core/ParsingErrorMessagesTest.java
+++ b/src/test/java/org/apache/freemarker/core/ParsingErrorMessagesTest.java
@@ -24,15 +24,15 @@ import static org.junit.Assert.*;
 import java.io.IOException;
 
 import org.apache.freemarker.core.util._StringUtil;
+import org.apache.freemarker.test.TestConfigurationBuilder;
 import org.junit.Test;
 
 public class ParsingErrorMessagesTest {
 
-    private Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
-    {
-        cfg.setTagSyntax(Configuration.AUTO_DETECT_TAG_SYNTAX);
-    }
-    
+    private Configuration cfg = new TestConfigurationBuilder()
+            .tagSyntax(ParsingConfiguration.AUTO_DETECT_TAG_SYNTAX)
+            .build();
+
     @Test
     public void testNeedlessInterpolation() {
         assertErrorContains("<#if ${x} == 3></#if>", "instead of ${");
@@ -89,7 +89,7 @@ public class ParsingErrorMessagesTest {
                 ftl = ftl.replace('<', '[').replace('>', ']');
             }
             new Template("adhoc", ftl, cfg);
-            fail("The tempalte had to fail");
+            fail("The template had to fail");
         } catch (ParseException e) {
             String msg = e.getMessage();
             for (String needle: expectedSubstrings) {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d61a45d/src/test/java/org/apache/freemarker/core/SQLTimeZoneTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/SQLTimeZoneTest.java b/src/test/java/org/apache/freemarker/core/SQLTimeZoneTest.java
index aae82f6..cf14b93 100644
--- a/src/test/java/org/apache/freemarker/core/SQLTimeZoneTest.java
+++ b/src/test/java/org/apache/freemarker/core/SQLTimeZoneTest.java
@@ -132,10 +132,12 @@ public class SQLTimeZoneTest extends TemplateTest {
         TimeZone prevSysDefTz = TimeZone.getDefault();
         TimeZone.setDefault(GMT_P02);
         try {
-            Configuration cfg = getConfiguration();
-            cfg.unsetTimeZone();
-            assertNull(cfg.getSQLDateAndTimeTimeZone());
-            assertEquals(TimeZone.getDefault(), cfg.getTimeZone());
+            Configuration.ExtendableBuilder<?> cfgB = createConfigurationBuilder();
+            cfgB.unsetTimeZone();
+            setConfiguration(cfgB.build());
+
+            assertNull(getConfiguration().getSQLDateAndTimeTimeZone());
+            assertEquals(TimeZone.getDefault(), getConfiguration().getTimeZone());
             
             assertOutput(FTL, OUTPUT_BEFORE_SETTING_GMT_CFG_GMT2 + OUTPUT_AFTER_SETTING_GMT_CFG_SQL_SAME);
         } finally {
@@ -148,10 +150,10 @@ public class SQLTimeZoneTest extends TemplateTest {
         TimeZone prevSysDefTz = TimeZone.getDefault();
         TimeZone.setDefault(GMT_P02);
         try {
-            Configuration cfg = getConfiguration();
-            cfg.unsetTimeZone();
-            cfg.setSQLDateAndTimeTimeZone(GMT_P02);
-            
+            Configuration.ExtendableBuilder<?> cfgB = createConfigurationBuilder();
+            cfgB.sqlDateAndTimeTimeZone(GMT_P02).unsetTimeZone();
+            setConfiguration(cfgB.build());
+
             assertOutput(FTL, OUTPUT_BEFORE_SETTING_GMT_CFG_GMT2 + OUTPUT_AFTER_SETTING_GMT_CFG_SQL_DIFFERENT);
         } finally {
             TimeZone.setDefault(prevSysDefTz);
@@ -160,48 +162,53 @@ public class SQLTimeZoneTest extends TemplateTest {
     
     @Test
     public void testWithGMT1AndNullSQL() throws Exception {
-        Configuration cfg = getConfiguration();
-        assertNull(cfg.getSQLDateAndTimeTimeZone());
-        cfg.setTimeZone(TimeZone.getTimeZone("GMT+01:00"));
-        
+        setConfiguration(createConfigurationBuilder()
+                .timeZone(TimeZone.getTimeZone("GMT+01:00"))
+                .build());
+        assertNull(getConfiguration().getSQLDateAndTimeTimeZone());
+
         assertOutput(FTL, OUTPUT_BEFORE_SETTING_GMT_CFG_GMT1_SQL_SAME + OUTPUT_AFTER_SETTING_GMT_CFG_SQL_SAME);
     }
 
     @Test
     public void testWithGMT1AndGMT2SQL() throws Exception {
-        Configuration cfg = getConfiguration();
-        cfg.setSQLDateAndTimeTimeZone(GMT_P02);
-        cfg.setTimeZone(TimeZone.getTimeZone("GMT+01:00"));
-        
+        setConfiguration(createConfigurationBuilder()
+                .sqlDateAndTimeTimeZone(GMT_P02)
+                .timeZone(TimeZone.getTimeZone("GMT+01:00"))
+                .build());
+
         assertOutput(FTL, OUTPUT_BEFORE_SETTING_GMT_CFG_GMT1_SQL_DIFFERENT + OUTPUT_AFTER_SETTING_GMT_CFG_SQL_DIFFERENT);
     }
 
     @Test
     public void testWithGMT2AndNullSQL() throws Exception {
-        Configuration cfg = getConfiguration();
-        assertNull(cfg.getSQLDateAndTimeTimeZone());
-        cfg.setTimeZone(TimeZone.getTimeZone("GMT+02"));
-        
+        setConfiguration(createConfigurationBuilder()
+                .timeZone(TimeZone.getTimeZone("GMT+02"))
+                .build());
+        assertNull(getConfiguration().getSQLDateAndTimeTimeZone());
+
         assertOutput(FTL, OUTPUT_BEFORE_SETTING_GMT_CFG_GMT2 + OUTPUT_AFTER_SETTING_GMT_CFG_SQL_SAME);
     }
 
     @Test
     public void testWithGMT2AndGMT2SQL() throws Exception {
-        Configuration cfg = getConfiguration();
-        cfg.setSQLDateAndTimeTimeZone(GMT_P02);
-        cfg.setTimeZone(TimeZone.getTimeZone("GMT+02"));
+        setConfiguration(createConfigurationBuilder()
+            .sqlDateAndTimeTimeZone(GMT_P02)
+            .timeZone(TimeZone.getTimeZone("GMT+02"))
+            .build());
         
         assertOutput(FTL, OUTPUT_BEFORE_SETTING_GMT_CFG_GMT2 + OUTPUT_AFTER_SETTING_GMT_CFG_SQL_DIFFERENT);
     }
     
     @Test
     public void testCacheFlushings() throws Exception {
-        Configuration cfg = getConfiguration();
-        cfg.setTimeZone(_DateUtil.UTC);
-        cfg.setDateFormat("yyyy-MM-dd E");
-        cfg.setTimeFormat("HH:mm:ss E");
-        cfg.setDateTimeFormat("yyyy-MM-dd'T'HH:mm:ss E");
-        
+        Configuration.ExtendableBuilder<?> cfgB = createConfigurationBuilder()
+                .timeZone(_DateUtil.UTC)
+                .dateFormat("yyyy-MM-dd E")
+                .timeFormat("HH:mm:ss E")
+                .dateTimeFormat("yyyy-MM-dd'T'HH:mm:ss E");
+
+        setConfiguration(cfgB.build());
         assertOutput(
                 "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n"
                 + "<#setting locale='de'>\n"
@@ -226,8 +233,8 @@ public class SQLTimeZoneTest extends TemplateTest {
                 + "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n",
                 "2014-07-11 Fri, 10:30:05 Thu, 2014-07-12T10:30:05 Sat, 2014-07-12T10:30:05 Sat, 2014-07-12 Sat, 10:30:05 Sat\n"
                 + "2014-07-11 Fri, 10:30:05 Thu, 2014-07-12T10:30:05, 2014-07-12T10:30:05, 2014-07-12 Sat, 10:30:05 Sat\n");
-        
-        cfg.setSQLDateAndTimeTimeZone(GMT_P02);
+
+        setConfiguration(cfgB.sqlDateAndTimeTimeZone(GMT_P02).build());
         assertOutput(
                 "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n"
                 + "<#setting locale='de'>\n"
@@ -256,9 +263,11 @@ public class SQLTimeZoneTest extends TemplateTest {
 
     @Test
     public void testDateAndTimeBuiltInsHasNoEffect() throws Exception {
-        Configuration cfg = getConfiguration();
-        cfg.setTimeZone(_DateUtil.UTC);
-        cfg.setSQLDateAndTimeTimeZone(GMT_P02);
+        setConfiguration(createConfigurationBuilder()
+                .timeZone(_DateUtil.UTC)
+                .sqlDateAndTimeTimeZone(GMT_P02)
+                .build());
+
         assertOutput(
                 "${javaDayErrorDate?date} ${javaDayErrorDate?time} ${sqlTimestamp?date} ${sqlTimestamp?time} "
                 + "${sqlDate?date} ${sqlTime?time}\n"
@@ -275,10 +284,11 @@ public class SQLTimeZoneTest extends TemplateTest {
 
     @Test
     public void testChangeSettingInTemplate() throws Exception {
-        Configuration cfg = getConfiguration();
-        cfg.setTimeZone(_DateUtil.UTC);
-        
-        assertNull(cfg.getSQLDateAndTimeTimeZone());
+        setConfiguration(createConfigurationBuilder()
+                .timeZone(_DateUtil.UTC)
+                .build());
+
+        assertNull(getConfiguration().getSQLDateAndTimeTimeZone());
 
         assertOutput(
                 "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}\n"
@@ -311,9 +321,10 @@ public class SQLTimeZoneTest extends TemplateTest {
     
     @Test
     public void testFormatUTCFlagHasNoEffect() throws Exception {
-        Configuration cfg = getConfiguration();
-        cfg.setSQLDateAndTimeTimeZone(GMT_P02);
-        cfg.setTimeZone(TimeZone.getTimeZone("GMT-01"));
+        setConfiguration(createConfigurationBuilder()
+                .sqlDateAndTimeTimeZone(GMT_P02)
+                .timeZone(TimeZone.getTimeZone("GMT-01"))
+                .build());
         
         assertOutput(
                 "<#setting date_format='xs fz'><#setting time_format='xs fz'>\n"
@@ -335,17 +346,15 @@ public class SQLTimeZoneTest extends TemplateTest {
                 + "2014-07-11-01:00, 09:30:05-01:00, 09:30:05-01:00\n"
                 + "2014-07-11Z, 10:30:05Z, 10:30:05Z\n");
     }
-    
-    @Override
-    protected Configuration createConfiguration() {
-        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
-        cfg.setLocale(Locale.US);
-        cfg.setDateFormat("yyyy-MM-dd");
-        cfg.setTimeFormat("HH:mm:ss");
-        cfg.setDateTimeFormat("yyyy-MM-dd'T'HH:mm:ss");
-        return cfg;
+
+    private Configuration.ExtendableBuilder<?> createConfigurationBuilder() {
+        return new Configuration.Builder(Configuration.VERSION_3_0_0)
+                .locale(Locale.US)
+                .dateFormat("yyyy-MM-dd")
+                .timeFormat("HH:mm:ss")
+                .dateTimeFormat("yyyy-MM-dd'T'HH:mm:ss");
     }
-    
+
     @Override
     protected Object createDataModel() {
         return this;

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d61a45d/src/test/java/org/apache/freemarker/core/SpecialVariableTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/SpecialVariableTest.java b/src/test/java/org/apache/freemarker/core/SpecialVariableTest.java
index 468f069..7e17fc7 100644
--- a/src/test/java/org/apache/freemarker/core/SpecialVariableTest.java
+++ b/src/test/java/org/apache/freemarker/core/SpecialVariableTest.java
@@ -49,11 +49,12 @@ public class SpecialVariableTest extends TemplateTest {
 
     @Test
     public void testIncompationImprovements() throws Exception {
+        setConfiguration(new Configuration.Builder(Configuration.VERSION_3_0_0).build());
         assertOutput(
                 "${.incompatibleImprovements}",
                 getConfiguration().getIncompatibleImprovements().toString());
         
-        getConfiguration().setIncompatibleImprovements(new Version(3, 0, 0));
+        setConfiguration(new Configuration.Builder(Configuration.getVersion()).build());
         assertOutput(
                 "${.incompatible_improvements}",
                 getConfiguration().getIncompatibleImprovements().toString());
@@ -61,30 +62,41 @@ public class SpecialVariableTest extends TemplateTest {
 
     @Test
     public void testAutoEsc() throws Exception {
-        Configuration cfg = getConfiguration();
-        
+        Configuration.Builder cfgB = new Configuration.Builder(Configuration.VERSION_3_0_0);
+
         for (int autoEscaping : new int[] {
-                Configuration.ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY, Configuration.ENABLE_IF_SUPPORTED_AUTO_ESCAPING_POLICY }) {
-            cfg.setAutoEscapingPolicy(autoEscaping);
-            cfg.setOutputFormat(HTMLOutputFormat.INSTANCE);
+                ParsingConfiguration.ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY, ParsingConfiguration.ENABLE_IF_SUPPORTED_AUTO_ESCAPING_POLICY }) {
+            cfgB.setAutoEscapingPolicy(autoEscaping);
+            cfgB.setOutputFormat(HTMLOutputFormat.INSTANCE);
+            setConfiguration(cfgB.build());
             assertOutput("${.autoEsc?c}", "true");
             assertOutput("<#ftl autoEsc=false>${.autoEsc?c}", "false");
-            cfg.setOutputFormat(PlainTextOutputFormat.INSTANCE);
+
+            cfgB.setOutputFormat(PlainTextOutputFormat.INSTANCE);
+            setConfiguration(cfgB.build());
             assertOutput("${.autoEsc?c}", "false");
-            cfg.setOutputFormat(UndefinedOutputFormat.INSTANCE);
+
+            cfgB.setOutputFormat(UndefinedOutputFormat.INSTANCE);
+            setConfiguration(cfgB.build());
             assertOutput("${.autoEsc?c}", "false");
         }
         
-        cfg.setAutoEscapingPolicy(Configuration.DISABLE_AUTO_ESCAPING_POLICY);
-        cfg.setOutputFormat(HTMLOutputFormat.INSTANCE);
+        cfgB.setAutoEscapingPolicy(ParsingConfiguration.DISABLE_AUTO_ESCAPING_POLICY);
+        cfgB.setOutputFormat(HTMLOutputFormat.INSTANCE);
+        setConfiguration(cfgB.build());
         assertOutput("${.autoEsc?c}", "false");
         assertOutput("<#ftl autoEsc=true>${.autoEsc?c}", "true");
-        cfg.setOutputFormat(PlainTextOutputFormat.INSTANCE);
+
+        cfgB.setOutputFormat(PlainTextOutputFormat.INSTANCE);
+        setConfiguration(cfgB.build());
         assertOutput("${.autoEsc?c}", "false");
-        cfg.setOutputFormat(UndefinedOutputFormat.INSTANCE);
+
+        cfgB.setOutputFormat(UndefinedOutputFormat.INSTANCE);
+        setConfiguration(cfgB.build());
         assertOutput("${.autoEsc?c}", "false");
 
-        cfg.setAutoEscapingPolicy(Configuration.ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY);
+        cfgB.setAutoEscapingPolicy(ParsingConfiguration.ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY);
+        setConfiguration(cfgB.build());
         assertOutput(
                 "${.autoEsc?c} "
                 + "<#outputFormat 'HTML'>${.autoEsc?c}</#outputFormat> "

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d61a45d/src/test/java/org/apache/freemarker/core/StringLiteralInterpolationTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/StringLiteralInterpolationTest.java b/src/test/java/org/apache/freemarker/core/StringLiteralInterpolationTest.java
index bad9905..5dc4da6 100644
--- a/src/test/java/org/apache/freemarker/core/StringLiteralInterpolationTest.java
+++ b/src/test/java/org/apache/freemarker/core/StringLiteralInterpolationTest.java
@@ -24,6 +24,7 @@ import java.util.Collections;
 import org.apache.freemarker.core.outputformat.impl.RTFOutputFormat;
 import org.apache.freemarker.core.userpkg.PrintfGTemplateNumberFormatFactory;
 import org.apache.freemarker.test.TemplateTest;
+import org.apache.freemarker.test.TestConfigurationBuilder;
 import org.junit.Test;
 
 @SuppressWarnings("boxing")
@@ -103,10 +104,11 @@ public class StringLiteralInterpolationTest extends TemplateTest {
     
     @Test
     public void markup() throws IOException, TemplateException {
-        Configuration cfg = getConfiguration();
-        cfg.setCustomNumberFormats(Collections.singletonMap("G", PrintfGTemplateNumberFormatFactory.INSTANCE));
-        cfg.setNumberFormat("@G 3");
-        
+        setConfiguration(new TestConfigurationBuilder()
+                .customNumberFormats(Collections.singletonMap("G", PrintfGTemplateNumberFormatFactory.INSTANCE))
+                .numberFormat("@G 3")
+                .build());
+
         assertOutput("${\"${1000}\"}", "1.00*10<sup>3</sup>");
         assertOutput("${\"&_${1000}\"}", "&amp;_1.00*10<sup>3</sup>");
         assertOutput("${\"${1000}_&\"}", "1.00*10<sup>3</sup>_&amp;");

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d61a45d/src/test/java/org/apache/freemarker/core/TabSizeTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/TabSizeTest.java b/src/test/java/org/apache/freemarker/core/TabSizeTest.java
index 56691cb..7945b5e 100644
--- a/src/test/java/org/apache/freemarker/core/TabSizeTest.java
+++ b/src/test/java/org/apache/freemarker/core/TabSizeTest.java
@@ -23,13 +23,14 @@ import static org.junit.Assert.*;
 import java.io.IOException;
 
 import org.apache.freemarker.test.TemplateTest;
+import org.apache.freemarker.test.TestConfigurationBuilder;
 import org.junit.Test;
 
 public class TabSizeTest extends TemplateTest {
 
     @Override
-    protected Configuration createConfiguration() throws Exception {
-        return super.createConfiguration();
+    protected Configuration createDefaultConfiguration() throws Exception {
+        return super.createDefaultConfiguration();
     }
 
     @Test
@@ -38,8 +39,8 @@ public class TabSizeTest extends TemplateTest {
         assertErrorColumnNumber(8 + 3, "\t${*}");
         assertErrorColumnNumber(16 + 3, "\t\t${*}");
         assertErrorColumnNumber(16 + 3, "  \t  \t${*}");
-        
-        getConfiguration().setTabSize(1);
+
+        setConfiguration(new TestConfigurationBuilder().tabSize(1).build());
         assertErrorColumnNumber(3, "${*}");
         assertErrorColumnNumber(1 + 3, "\t${*}");
         assertErrorColumnNumber(2 + 3, "\t\t${*}");
@@ -49,14 +50,14 @@ public class TabSizeTest extends TemplateTest {
     @Test
     public void testEvalBI() throws Exception {
         assertErrorContains("${r'\t~'?eval}", "column 9");
-        getConfiguration().setTabSize(4);
+        setConfiguration(new TestConfigurationBuilder().tabSize(4).build());
         assertErrorContains("${r'\t~'?eval}", "column 5");
     }
 
     @Test
     public void testInterpretBI() throws Exception {
         assertErrorContains("<@'\\t$\\{*}'?interpret />", "column 11");
-        getConfiguration().setTabSize(4);
+        setConfiguration(new TestConfigurationBuilder().tabSize(4).build());
         assertErrorContains("<@'\\t$\\{*}'?interpret />", "column 7");
     }
     
@@ -64,7 +65,7 @@ public class TabSizeTest extends TemplateTest {
     public void testStringLiteralInterpolation() throws Exception {
         assertErrorColumnNumber(6, "${'${*}'}");
         assertErrorColumnNumber(9, "${'${\t*}'}");
-        getConfiguration().setTabSize(16);
+        setConfiguration(new TestConfigurationBuilder().tabSize(16).build());
         assertErrorColumnNumber(17, "${'${\t*}'}");
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d61a45d/src/test/java/org/apache/freemarker/core/TagSyntaxVariationsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/TagSyntaxVariationsTest.java b/src/test/java/org/apache/freemarker/core/TagSyntaxVariationsTest.java
index 07b39e4..fa21c76 100644
--- a/src/test/java/org/apache/freemarker/core/TagSyntaxVariationsTest.java
+++ b/src/test/java/org/apache/freemarker/core/TagSyntaxVariationsTest.java
@@ -24,6 +24,7 @@ import java.io.StringReader;
 import java.io.StringWriter;
 
 import org.apache.freemarker.core.util._StringUtil;
+import org.apache.freemarker.test.TestConfigurationBuilder;
 
 import junit.framework.TestCase;
 
@@ -59,93 +60,101 @@ public class TagSyntaxVariationsTest extends TestCase {
 
     public final void test()
             throws TemplateException, IOException {
-        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
-
-        // Permutations 
+        // Permutations
         for (int ifOrAssign = 0; ifOrAssign < 2; ifOrAssign++) {
-            String dir_ang = ifOrAssign == 0 ? IF_ANG : ASSIGN_ANG; 
-            String dir_squ = ifOrAssign == 0 ? IF_SQU : ASSIGN_SQU; 
-            String dir_out = ifOrAssign == 0 ? IF_OUT : ASSIGN_OUT; 
-            
+            String dir_ang = ifOrAssign == 0 ? IF_ANG : ASSIGN_ANG;
+            String dir_squ = ifOrAssign == 0 ? IF_SQU : ASSIGN_SQU;
+            String dir_out = ifOrAssign == 0 ? IF_OUT : ASSIGN_OUT;
+
             // Permutations 
             for (int angOrSqu = 0; angOrSqu < 2; angOrSqu++) {
-                cfg.setTagSyntax(angOrSqu == 0
-                        ? Configuration.ANGLE_BRACKET_TAG_SYNTAX
-                        : Configuration.SQUARE_BRACKET_TAG_SYNTAX);
-                
+                Configuration cfg = new TestConfigurationBuilder()
+                        .tagSyntax(angOrSqu == 0
+                                ? ParsingConfiguration.ANGLE_BRACKET_TAG_SYNTAX
+                                : ParsingConfiguration.SQUARE_BRACKET_TAG_SYNTAX)
+                        .build();
+
                 String dir_xxx = angOrSqu == 0 ? dir_ang : dir_squ;
                 String cust_xxx = angOrSqu == 0 ? CUST_ANG : CUST_SQU;
                 String hdr_xxx = angOrSqu == 0 ? HDR_ANG : HDR_SQU;
                 String wrong_xxx = angOrSqu == 0 ? WRONG_ANG : WRONG_SQU;
                 String wrongc_xxx = angOrSqu == 0 ? WRONGC_ANG : WRONGC_SQU;
-                
+
                 test(cfg,
                         dir_xxx + cust_xxx,
                         dir_out + CUST_OUT);
-                
+
                 // Permutations 
                 for (int wrongOrWrongc = 0; wrongOrWrongc < 2; wrongOrWrongc++) {
                     String wrongx_xxx = wrongOrWrongc == 0 ? wrong_xxx : wrongc_xxx;
-                    
+
                     test(cfg,
                             wrongx_xxx + dir_xxx,
                             null);
-    
+
                     test(cfg,
                             dir_xxx + wrongx_xxx,
                             null);
-                    
+
                     test(cfg,
                             hdr_xxx + wrongx_xxx,
                             null);
-                    
+
                     test(cfg,
                             cust_xxx + wrongx_xxx + dir_xxx,
                             null);
                 } // for wrongc
             } // for squ
-            
-            cfg.setTagSyntax(Configuration.AUTO_DETECT_TAG_SYNTAX);
-            for (int perm = 0; perm < 4; perm++) {
-                // All 4 permutations
-                String wrong_xxx = (perm & 1) == 0 ? WRONG_ANG : WRONG_SQU;
-                String dir_xxx = (perm & 2) == 0 ? dir_ang : dir_squ;
-                
-                test(cfg,
-                        wrong_xxx + dir_xxx,
-                        null);
-            } // for perm
-    
-            // Permutations 
-            for (int angOrSquStart = 0; angOrSquStart < 2; angOrSquStart++) {
-                String hdr_xxx = angOrSquStart == 0 ? HDR_ANG : HDR_SQU;
-                String cust_xxx = angOrSquStart == 0 ? CUST_ANG : CUST_SQU;
-                String wrong_yyy = angOrSquStart != 0 ? WRONG_ANG : WRONG_SQU;
-                String dir_xxx = angOrSquStart == 0 ? dir_ang : dir_squ;
-                String dir_yyy = angOrSquStart != 0 ? dir_ang : dir_squ;
-                
-                test(cfg,
-                        cust_xxx + wrong_yyy + dir_xxx,
-                        CUST_OUT + wrong_yyy + dir_out);
-                
-                test(cfg,
-                        hdr_xxx + wrong_yyy + dir_xxx,
-                        wrong_yyy + dir_out);
-                
-                test(cfg,
-                        cust_xxx + wrong_yyy + dir_yyy,
-                        CUST_OUT + wrong_yyy + dir_yyy);
-                
-                test(cfg,
-                        hdr_xxx + wrong_yyy + dir_yyy,
-                        wrong_yyy + dir_yyy);
-                
-                test(cfg,
-                        dir_xxx + wrong_yyy + dir_yyy,
-                        dir_out + wrong_yyy + dir_yyy);
-            } // for squStart
-            
-        } // for assign
+
+            {
+                Configuration cfg = new TestConfigurationBuilder()
+                        .tagSyntax(ParsingConfiguration.AUTO_DETECT_TAG_SYNTAX)
+                        .build();
+                for (int perm = 0; perm < 4; perm++) {
+                    // All 4 permutations
+                    String wrong_xxx = (perm & 1) == 0 ? WRONG_ANG : WRONG_SQU;
+                    String dir_xxx = (perm & 2) == 0 ? dir_ang : dir_squ;
+
+                    test(cfg,
+                            wrong_xxx + dir_xxx,
+                            null);
+                } // for perm
+            }
+
+            {
+                Configuration cfg = new TestConfigurationBuilder()
+                        .tagSyntax(ParsingConfiguration.AUTO_DETECT_TAG_SYNTAX)
+                        .build();
+                // Permutations
+                for (int angOrSquStart = 0; angOrSquStart < 2; angOrSquStart++) {
+                    String hdr_xxx = angOrSquStart == 0 ? HDR_ANG : HDR_SQU;
+                    String cust_xxx = angOrSquStart == 0 ? CUST_ANG : CUST_SQU;
+                    String wrong_yyy = angOrSquStart != 0 ? WRONG_ANG : WRONG_SQU;
+                    String dir_xxx = angOrSquStart == 0 ? dir_ang : dir_squ;
+                    String dir_yyy = angOrSquStart != 0 ? dir_ang : dir_squ;
+
+                    test(cfg,
+                            cust_xxx + wrong_yyy + dir_xxx,
+                            CUST_OUT + wrong_yyy + dir_out);
+
+                    test(cfg,
+                            hdr_xxx + wrong_yyy + dir_xxx,
+                            wrong_yyy + dir_out);
+
+                    test(cfg,
+                            cust_xxx + wrong_yyy + dir_yyy,
+                            CUST_OUT + wrong_yyy + dir_yyy);
+
+                    test(cfg,
+                            hdr_xxx + wrong_yyy + dir_yyy,
+                            wrong_yyy + dir_yyy);
+
+                    test(cfg,
+                            dir_xxx + wrong_yyy + dir_yyy,
+                            dir_out + wrong_yyy + dir_yyy);
+                } // for squStart
+            } // for assign
+        }
     }
     
     /**

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d61a45d/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 593b912..5b1cda9 100644
--- a/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java
+++ b/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java
@@ -62,6 +62,7 @@ import org.apache.freemarker.core.userpkg.LocaleSensitiveTemplateNumberFormatFac
 import org.apache.freemarker.core.valueformat.TemplateDateFormatFactory;
 import org.apache.freemarker.core.valueformat.TemplateNumberFormatFactory;
 import org.apache.freemarker.test.MonitoredTemplateLoader;
+import org.apache.freemarker.test.TestConfigurationBuilder;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
@@ -110,15 +111,18 @@ public class TemplateConfigurationTest {
         }
     }
 
-    private static final Version ICI = Configuration.VERSION_3_0_0;
-
-    private static final Configuration DEFAULT_CFG = new Configuration(ICI);
+    private static final Configuration DEFAULT_CFG;
     static {
+        TestConfigurationBuilder cfgB = new TestConfigurationBuilder();
         StringTemplateLoader stl = new StringTemplateLoader();
         stl.putTemplate("t1.ftl", "<#global loaded = (loaded!) + 't1;'>In t1;");
         stl.putTemplate("t2.ftl", "<#global loaded = (loaded!) + 't2;'>In t2;");
         stl.putTemplate("t3.ftl", "<#global loaded = (loaded!) + 't3;'>In t3;");
-        DEFAULT_CFG.setTemplateLoader(stl);
+        try {
+            DEFAULT_CFG = cfgB.templateLoader(stl).build();
+        } catch (ConfigurationException e) {
+            throw new IllegalStateException("Faild to create default configuration", e);
+        }
     }
 
     private static final TimeZone NON_DEFAULT_TZ;
@@ -158,7 +162,8 @@ public class TemplateConfigurationTest {
         SETTING_ASSIGNMENTS.put("logTemplateExceptions", true);
         SETTING_ASSIGNMENTS.put("newBuiltinClassResolver", TemplateClassResolver.ALLOWS_NOTHING_RESOLVER);
         SETTING_ASSIGNMENTS.put("numberFormat", "0.0000");
-        SETTING_ASSIGNMENTS.put("objectWrapper", new RestrictedObjectWrapper.Builder(ICI).build());
+        SETTING_ASSIGNMENTS.put("objectWrapper",
+                new RestrictedObjectWrapper.Builder(Configuration.VERSION_3_0_0).build());
         SETTING_ASSIGNMENTS.put("outputEncoding", StandardCharsets.UTF_16);
         SETTING_ASSIGNMENTS.put("showErrorTips", false);
         SETTING_ASSIGNMENTS.put("templateExceptionHandler", TemplateExceptionHandler.IGNORE_HANDLER);
@@ -173,11 +178,11 @@ public class TemplateConfigurationTest {
 
         // Parser-only settings:
         SETTING_ASSIGNMENTS.put("templateLanguage", TemplateLanguage.STATIC_TEXT);
-        SETTING_ASSIGNMENTS.put("tagSyntax", Configuration.SQUARE_BRACKET_TAG_SYNTAX);
-        SETTING_ASSIGNMENTS.put("namingConvention", Configuration.LEGACY_NAMING_CONVENTION);
+        SETTING_ASSIGNMENTS.put("tagSyntax", ParsingConfiguration.SQUARE_BRACKET_TAG_SYNTAX);
+        SETTING_ASSIGNMENTS.put("namingConvention", ParsingConfiguration.LEGACY_NAMING_CONVENTION);
         SETTING_ASSIGNMENTS.put("whitespaceStripping", false);
         SETTING_ASSIGNMENTS.put("strictSyntaxMode", false);
-        SETTING_ASSIGNMENTS.put("autoEscapingPolicy", Configuration.DISABLE_AUTO_ESCAPING_POLICY);
+        SETTING_ASSIGNMENTS.put("autoEscapingPolicy", ParsingConfiguration.DISABLE_AUTO_ESCAPING_POLICY);
         SETTING_ASSIGNMENTS.put("outputFormat", HTMLOutputFormat.INSTANCE);
         SETTING_ASSIGNMENTS.put("recognizeStandardFileExtensions", false);
         SETTING_ASSIGNMENTS.put("tabSize", 1);
@@ -215,7 +220,6 @@ public class TemplateConfigurationTest {
         }
 
         Collections.sort(settingPropDescs, new Comparator<PropertyDescriptor>() {
-
             @Override
             public int compare(PropertyDescriptor o1, PropertyDescriptor o2) {
                 return o1.getName().compareToIgnoreCase(o2.getName());
@@ -483,7 +487,7 @@ public class TemplateConfigurationTest {
             Method tReaderMethod = Template.class.getMethod(pd.getReadMethod().getName());
 
             // Without TC
-            assertNotEquals("For \"" + pd.getName() + "\"", newValue,
+            assertNotEquals("For \"" + pd.getName() + "\"",
                     tReaderMethod.invoke(new Template(null, "", DEFAULT_CFG)));
             // With TC
             assertEquals("For \"" + pd.getName() + "\"", newValue,
@@ -493,10 +497,11 @@ public class TemplateConfigurationTest {
     
     @Test
     public void testConfigureCustomAttributes() throws Exception {
-        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
-        cfg.setCustomAttribute("k1", "c");
-        cfg.setCustomAttribute("k2", "c");
-        cfg.setCustomAttribute("k3", "c");
+        Configuration cfg = new TestConfigurationBuilder()
+                .customAttribute("k1", "c")
+                .customAttribute("k2", "c")
+                .customAttribute("k3", "c")
+                .build();
 
         TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
         tcb.setCustomAttribute("k2", "tc");
@@ -536,18 +541,18 @@ public class TemplateConfigurationTest {
         
         {
             TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
-            tcb.setTagSyntax(Configuration.SQUARE_BRACKET_TAG_SYNTAX);
+            tcb.setTagSyntax(ParsingConfiguration.SQUARE_BRACKET_TAG_SYNTAX);
             TemplateConfiguration tc = tcb.build();
             assertOutputWithoutAndWithTC(tc, "[#if true]y[/#if]", "[#if true]y[/#if]", "y");
-            testedProps.add(Configuration.TAG_SYNTAX_KEY_CAMEL_CASE);
+            testedProps.add(Configuration.ExtendableBuilder.TAG_SYNTAX_KEY_CAMEL_CASE);
         }
         
         {
             TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
-            tcb.setNamingConvention(Configuration.CAMEL_CASE_NAMING_CONVENTION);
+            tcb.setNamingConvention(ParsingConfiguration.CAMEL_CASE_NAMING_CONVENTION);
             TemplateConfiguration tc = tcb.build();
             assertOutputWithoutAndWithTC(tc, "<#if true>y<#elseif false>n</#if>", "y", null);
-            testedProps.add(Configuration.NAMING_CONVENTION_KEY_CAMEL_CASE);
+            testedProps.add(Configuration.ExtendableBuilder.NAMING_CONVENTION_KEY_CAMEL_CASE);
         }
         
         {
@@ -555,7 +560,7 @@ public class TemplateConfigurationTest {
             tcb.setWhitespaceStripping(false);
             TemplateConfiguration tc = tcb.build();
             assertOutputWithoutAndWithTC(tc, "<#if true>\nx\n</#if>\n", "x\n", "\nx\n\n");
-            testedProps.add(Configuration.WHITESPACE_STRIPPING_KEY_CAMEL_CASE);
+            testedProps.add(Configuration.ExtendableBuilder.WHITESPACE_STRIPPING_KEY_CAMEL_CASE);
         }
 
         {
@@ -563,7 +568,7 @@ public class TemplateConfigurationTest {
             tcb.setArithmeticEngine(new DummyArithmeticEngine());
             TemplateConfiguration tc = tcb.build();
             assertOutputWithoutAndWithTC(tc, "${1} ${1+1}", "1 2", "11 22");
-            testedProps.add(Configuration.ARITHMETIC_ENGINE_KEY_CAMEL_CASE);
+            testedProps.add(Configuration.ExtendableBuilder.ARITHMETIC_ENGINE_KEY_CAMEL_CASE);
         }
 
         {
@@ -573,16 +578,16 @@ public class TemplateConfigurationTest {
             assertOutputWithoutAndWithTC(tc, "${.outputFormat} ${\"a'b\"}",
                     UndefinedOutputFormat.INSTANCE.getName() + " a'b",
                     XMLOutputFormat.INSTANCE.getName() + " a&apos;b");
-            testedProps.add(Configuration.OUTPUT_FORMAT_KEY_CAMEL_CASE);
+            testedProps.add(Configuration.ExtendableBuilder.OUTPUT_FORMAT_KEY_CAMEL_CASE);
         }
 
         {
             TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
             tcb.setOutputFormat(XMLOutputFormat.INSTANCE);
-            tcb.setAutoEscapingPolicy(Configuration.DISABLE_AUTO_ESCAPING_POLICY);
+            tcb.setAutoEscapingPolicy(ParsingConfiguration.DISABLE_AUTO_ESCAPING_POLICY);
             TemplateConfiguration tc = tcb.build();
             assertOutputWithoutAndWithTC(tc, "${'a&b'}", "a&b", "a&b");
-            testedProps.add(Configuration.AUTO_ESCAPING_POLICY_KEY_CAMEL_CASE);
+            testedProps.add(Configuration.ExtendableBuilder.AUTO_ESCAPING_POLICY_KEY_CAMEL_CASE);
         }
         
         {
@@ -592,7 +597,7 @@ public class TemplateConfigurationTest {
             tc.setParentConfiguration(new Configuration(new Version(2, 3, 0)));
             assertOutputWithoutAndWithTC(tc, "<#foo>", null, "<#foo>");
             */
-            testedProps.add(Configuration.INCOMPATIBLE_IMPROVEMENTS_KEY_CAMEL_CASE);
+            testedProps.add(Configuration.ExtendableBuilder.INCOMPATIBLE_IMPROVEMENTS_KEY_CAMEL_CASE);
         }
 
         {
@@ -601,7 +606,7 @@ public class TemplateConfigurationTest {
             TemplateConfiguration tc = tcb.build();
             assertOutputWithoutAndWithTC(tc, "adhoc.ftlh", "${.outputFormat}",
                     HTMLOutputFormat.INSTANCE.getName(), UndefinedOutputFormat.INSTANCE.getName());
-            testedProps.add(Configuration.RECOGNIZE_STANDARD_FILE_EXTENSIONS_KEY_CAMEL_CASE);
+            testedProps.add(Configuration.ExtendableBuilder.RECOGNIZE_STANDARD_FILE_EXTENSIONS_KEY_CAMEL_CASE);
         }
 
         {
@@ -614,7 +619,7 @@ public class TemplateConfigurationTest {
                     + "${.error?replace('(?s).*?column ([0-9]+).*', '$1', 'r')}"
                     + "</#attempt>",
                     "13", "8");
-            testedProps.add(Configuration.TAB_SIZE_KEY_CAMEL_CASE);
+            testedProps.add(Configuration.ExtendableBuilder.TAB_SIZE_KEY_CAMEL_CASE);
         }
 
         {
@@ -624,15 +629,17 @@ public class TemplateConfigurationTest {
             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"), tcb.build()));
+            TestConfigurationBuilder cfgB = new TestConfigurationBuilder();
+            cfgB.setTemplateConfigurations(
+                    new ConditionalTemplateConfigurationFactory(new FileExtensionMatcher("txt"), tcb.build()));
 
             StringTemplateLoader templateLoader = new StringTemplateLoader();
             templateLoader.putTemplate("adhoc.ftl", "${1+1}");
             templateLoader.putTemplate("adhoc.txt", "${1+1}");
-            cfg.setTemplateLoader(templateLoader);
+            cfgB.setTemplateLoader(templateLoader);
 
+            Configuration cfg = cfgB.build();
+            
             {
                 StringWriter out = new StringWriter();
                 cfg.getTemplate("adhoc.ftl").process(null, out);
@@ -644,7 +651,7 @@ public class TemplateConfigurationTest {
                 assertEquals("${1+1}", out.toString());
             }
 
-            testedProps.add(Configuration.TEMPLATE_LANGUAGE_KEY_CAMEL_CASE);
+            testedProps.add(Configuration.ExtendableBuilder.TEMPLATE_LANGUAGE_KEY_CAMEL_CASE);
         }
 
         {
@@ -654,16 +661,18 @@ public class TemplateConfigurationTest {
             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"), tcb.build()));
+            TestConfigurationBuilder cfgB = new TestConfigurationBuilder();
+            cfgB.setSourceEncoding(StandardCharsets.UTF_8);
+            cfgB.setTemplateConfigurations(new ConditionalTemplateConfigurationFactory(
+                    new FileNameGlobMatcher("latin1.ftl"), tcb.build()));
 
             MonitoredTemplateLoader templateLoader = new MonitoredTemplateLoader();
             templateLoader.putBinaryTemplate("utf8.ftl", "próba", StandardCharsets.UTF_8, 1);
             templateLoader.putBinaryTemplate("latin1.ftl", "próba", StandardCharsets.ISO_8859_1, 1);
-            cfg.setTemplateLoader(templateLoader);
+            cfgB.setTemplateLoader(templateLoader);
 
+            Configuration cfg = cfgB.build();
+            
             {
                 StringWriter out = new StringWriter();
                 cfg.getTemplate("utf8.ftl").process(null, out);
@@ -675,7 +684,7 @@ public class TemplateConfigurationTest {
                 assertEquals("próba", out.toString());
             }
 
-            testedProps.add(Configuration.SOURCE_ENCODING_KEY_CAMEL_CASE);
+            testedProps.add(Configuration.ExtendableBuilder.SOURCE_ENCODING_KEY_CAMEL_CASE);
         }
 
         if (!PARSER_PROP_NAMES.equals(testedProps)) {
@@ -780,7 +789,7 @@ public class TemplateConfigurationTest {
 
             {
                 // Force camelCase:
-                tcb.setNamingConvention(Configuration.CAMEL_CASE_NAMING_CONVENTION);
+                tcb.setNamingConvention(ParsingConfiguration.CAMEL_CASE_NAMING_CONVENTION);
 
                 TemplateConfiguration tc = tcb.build();
 
@@ -790,7 +799,7 @@ public class TemplateConfigurationTest {
 
             {
                 // Force legacy:
-                tcb.setNamingConvention(Configuration.LEGACY_NAMING_CONVENTION);
+                tcb.setNamingConvention(ParsingConfiguration.LEGACY_NAMING_CONVENTION);
 
                 TemplateConfiguration tc = tcb.build();
 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d61a45d/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
index 24c7ec6..4cd50eb 100644
--- a/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaultTemplateResolverTest.java
+++ b/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaultTemplateResolverTest.java
@@ -33,6 +33,7 @@ import org.apache.freemarker.core.templateresolver.FirstMatchTemplateConfigurati
 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.apache.freemarker.test.TestConfigurationBuilder;
 import org.junit.Test;
 
 public class TemplateConfigurationWithDefaultTemplateResolverTest {
@@ -92,23 +93,24 @@ public class TemplateConfigurationWithDefaultTemplateResolverTest {
 
     @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",
+        StringTemplateLoader loader = new StringTemplateLoader();
+        loader.putTemplate("(de).ftl", "${.locale}");
+        loader.putTemplate("default.ftl", "${.locale}");
+        loader.putTemplate("(de)-fr.ftl",
                 ("<#ftl locale='fr_FR'>${.locale}"));
-        tl.putTemplate("default-fr.ftl",
+        loader.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()));
-        
+        Configuration cfg = new TestConfigurationBuilder()
+                .templateLoader(loader)
+                .templateConfigurations(
+                        new ConditionalTemplateConfigurationFactory(
+                                new FileNameGlobMatcher("*(de)*"),
+                                new TemplateConfiguration.Builder()
+                                        .locale(Locale.GERMANY)
+                                        .build()))
+                .build();
+
         {
             Template t = cfg.getTemplate("(de).ftl");
             assertEquals(Locale.GERMANY, t.getLocale());
@@ -133,31 +135,28 @@ public class TemplateConfigurationWithDefaultTemplateResolverTest {
 
     @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);
-        
+        StringTemplateLoader loader = new StringTemplateLoader();
+        loader.putTemplate("default", commonFTL);
+        loader.putTemplate("(fr)", commonFTL);
+        loader.putTemplate("(yn)(00)", commonFTL);
+        loader.putTemplate("(00)(fr)", commonFTL);
+
+        Configuration cfg = new TestConfigurationBuilder()
+                .templateConfigurations(
+                        new MergingTemplateConfigurationFactory(
+                                new ConditionalTemplateConfigurationFactory(
+                                        new FileNameGlobMatcher("*(fr)*"),
+                                        new TemplateConfiguration.Builder().locale(Locale.FRANCE).build()),
+                                new ConditionalTemplateConfigurationFactory(
+                                        new FileNameGlobMatcher("*(yn)*"),
+                                        new TemplateConfiguration.Builder().booleanFormat("Y,N").build()),
+                                new ConditionalTemplateConfigurationFactory(
+                                        new FileNameGlobMatcher("*(00)*"),
+                                        new TemplateConfiguration.Builder().numberFormat("0.00").build())))
+                .templateLoader(loader)
+                .build();
+
         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)")));
@@ -166,33 +165,33 @@ public class TemplateConfigurationWithDefaultTemplateResolverTest {
     
     @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);
+
+        Configuration cfg = new TestConfigurationBuilder()
+                .templateConfigurations(
+                        new MergingTemplateConfigurationFactory(
+                                new ConditionalTemplateConfigurationFactory(
+                                        new FileNameGlobMatcher("*(tc1)*"),
+                                        new TemplateConfiguration.Builder()
+                                                .customAttribute("a1", "a1tc1")
+                                                .customAttribute("a2", "a2tc1")
+                                                .customAttribute("a3", "a3tc1")
+                                                .customAttribute(CUST_ATT_1, "ca1tc1")
+                                                .customAttribute(CUST_ATT_2, "ca2tc1")
+                                                .build()),
+                                new ConditionalTemplateConfigurationFactory(
+                                        new FileNameGlobMatcher("*(tc2)*"),
+                                        new TemplateConfiguration.Builder()
+                                                .customAttribute("a1", "a1tc2")
+                                                .customAttribute(CUST_ATT_1, "ca1tc2")
+                                                .build())))
+                .templateLoader(tl)
+                .build();
 
         {
             Template t = cfg.getTemplate("(tc1)");
@@ -235,10 +234,6 @@ public class TemplateConfigurationWithDefaultTemplateResolverTest {
     }
 
     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));
@@ -247,18 +242,26 @@ public class TemplateConfigurationWithDefaultTemplateResolverTest {
                 ("<#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;
+
+        return new TestConfigurationBuilder()
+                .sourceEncoding(StandardCharsets.ISO_8859_1)
+                .locale(Locale.US)
+                .templateLoader(tl)
+                .templateConfigurations(
+                        new FirstMatchTemplateConfigurationFactory(
+                                new ConditionalTemplateConfigurationFactory(
+                                        new FileNameGlobMatcher("*utf8*"),
+                                        new TemplateConfiguration.Builder()
+                                                .sourceEncoding(StandardCharsets.UTF_8)
+                                                .build()),
+                                new ConditionalTemplateConfigurationFactory(
+                                        new FileNameGlobMatcher("*utf16*"),
+                                        new TemplateConfiguration.Builder()
+                                                .sourceEncoding(StandardCharsets.UTF_16LE)
+                                                .build())
+                        )
+                        .allowNoMatch(true))
+                .build();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d61a45d/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java b/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java
index 93a57b1..97c43ad 100644
--- a/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java
+++ b/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java
@@ -28,6 +28,7 @@ import java.io.StringReader;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 
+import org.apache.freemarker.test.TestConfigurationBuilder;
 import org.junit.Test;
 public class TemplateConstructorsTest {
 
@@ -36,8 +37,7 @@ public class TemplateConstructorsTest {
     
     @Test
     public void test() throws IOException {
-        final Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
-        cfg.setSourceEncoding(StandardCharsets.ISO_8859_1);
+        final Configuration cfg = new TestConfigurationBuilder().sourceEncoding(StandardCharsets.ISO_8859_1).build();
         
         final String name = "foo/bar.ftl";
         final String sourceName = "foo/bar_de.ftl";

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7d61a45d/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 d678a67..4b5bf59 100644
--- a/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java
+++ b/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java
@@ -35,10 +35,9 @@ public class TemplateGetEncodingTest {
 
     @Test
     public void test() throws IOException {
-
-        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
+        Configuration.Builder cfgB = new Configuration.Builder(Configuration.VERSION_3_0_0);
         {
-            cfg.setSourceEncoding(ISO_8859_2);
+            cfgB.setSourceEncoding(ISO_8859_2);
             MonitoredTemplateLoader tl = new MonitoredTemplateLoader();
             tl.putBinaryTemplate("bin", "test");
             tl.putBinaryTemplate("bin-static", "<#test>");
@@ -46,13 +45,14 @@ public class TemplateGetEncodingTest {
             tl.putTextTemplate("text-static", "<#test>");
             TemplateConfiguration.Builder staticTextTCB = new TemplateConfiguration.Builder();
             staticTextTCB.setTemplateLanguage(TemplateLanguage.STATIC_TEXT);
-            cfg.setTemplateConfigurations(
+            cfgB.setTemplateConfigurations(
                     new ConditionalTemplateConfigurationFactory(
                             new FileNameGlobMatcher("*-static*"), staticTextTCB.build()));
-            cfg.setTemplateLoader(tl);
-            cfg.setCacheStorage(new StrongCacheStorage());
+            cfgB.setTemplateLoader(tl);
+            cfgB.setCacheStorage(new StrongCacheStorage());
         }
 
+        Configuration cfg = cfgB.build();
         assertEquals(ISO_8859_2, cfg.getTemplate("bin").getActualSourceEncoding());
         assertEquals(ISO_8859_2, cfg.getTemplate("bin-static").getActualSourceEncoding());
         assertNull(cfg.getTemplate("text").getActualSourceEncoding());


Mime
View raw message