You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2017/03/15 12:31:46 UTC

[04/10] incubator-freemarker git commit: Ensure that the configuration settings don't depend on the machine that runs the test.

Ensure that the configuration settings don't depend on the machine that runs the test.


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/649d85d1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/649d85d1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/649d85d1

Branch: refs/heads/2.3
Commit: 649d85d180cdd3df87a79e2357d9d77a384dcccf
Parents: 0fa4299
Author: ddekany <dd...@apache.org>
Authored: Tue Mar 14 21:43:22 2017 +0100
Committer: ddekany <dd...@apache.org>
Committed: Tue Mar 14 21:43:22 2017 +0100

----------------------------------------------------------------------
 .../java/freemarker/core/SQLTimeZoneTest.java    |  2 ++
 src/test/java/freemarker/test/TemplateTest.java  | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/649d85d1/src/test/java/freemarker/core/SQLTimeZoneTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/SQLTimeZoneTest.java b/src/test/java/freemarker/core/SQLTimeZoneTest.java
index 3ef114c..b4002f6 100644
--- a/src/test/java/freemarker/core/SQLTimeZoneTest.java
+++ b/src/test/java/freemarker/core/SQLTimeZoneTest.java
@@ -135,6 +135,7 @@ public class SQLTimeZoneTest extends TemplateTest {
         TimeZone.setDefault(GMT_P02);
         try {
             Configuration cfg = getConfiguration();
+            cfg.unsetTimeZone();
             assertNull(cfg.getSQLDateAndTimeTimeZone());
             assertEquals(TimeZone.getDefault(), cfg.getTimeZone());
             
@@ -150,6 +151,7 @@ public class SQLTimeZoneTest extends TemplateTest {
         TimeZone.setDefault(GMT_P02);
         try {
             Configuration cfg = getConfiguration();
+            cfg.unsetTimeZone();
             cfg.setSQLDateAndTimeTimeZone(GMT_P02);
             
             assertOutput(FTL, OUTPUT_BEFORE_SETTING_GMT_CFG_GMT2 + OUTPUT_AFTER_SETTING_GMT_CFG_SQL_DIFFERENT);

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/649d85d1/src/test/java/freemarker/test/TemplateTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/test/TemplateTest.java b/src/test/java/freemarker/test/TemplateTest.java
index 4747ed0..99e2db1 100644
--- a/src/test/java/freemarker/test/TemplateTest.java
+++ b/src/test/java/freemarker/test/TemplateTest.java
@@ -25,9 +25,12 @@ import static org.junit.Assert.*;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringWriter;
+import java.nio.charset.StandardCharsets;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
+import java.util.TimeZone;
 
 import org.apache.commons.io.IOUtils;
 import org.junit.Ignore;
@@ -59,6 +62,7 @@ public abstract class TemplateTest {
             try {
                 configuration = createConfiguration();
                 addCommonTemplates();
+                applyEnvironmentIndependentDefaults();
             } catch (Exception e) {
                 throw new RuntimeException("Failed to set up configuration for the test", e);
             }
@@ -66,6 +70,21 @@ public abstract class TemplateTest {
         return configuration;
     }
 
+    /**
+     * Ensure that the configuration settings don't depend on the machine that runs the test.
+     */
+    private void applyEnvironmentIndependentDefaults() {
+        if (!configuration.isLocaleExplicitlySet()) {
+            configuration.setLocale(Locale.US);
+        }
+        if (!configuration.isDefaultEncodingExplicitlySet()) {
+            configuration.setDefaultEncoding(StandardCharsets.UTF_8.name());
+        }
+        if (!configuration.isTimeZoneExplicitlySet()) {
+            configuration.setTimeZone(TimeZone.getTimeZone("GMT+1"));
+        }
+    }
+
     protected final void setConfiguration(Configuration configuration) {
         this.configuration = configuration;
     }