From 1fba4ff265fb65f5912249adcfc61a5aaf8aab1d Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Sat, 10 Dec 2016 08:44:00 -0500 Subject: [PATCH] Test refactor --- .../main/java/ca/uhn/fhir/util/TestUtil.java | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/TestUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/TestUtil.java index eab1e317d52..20837333fd7 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/TestUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/TestUtil.java @@ -79,27 +79,7 @@ public class TestUtil { } - /* - * Set some system properties randomly after each test.. this is kind of hackish, - * but it helps us make sure we don't have any tests that depend on a particular - * environment - */ - Locale[] availableLocales = { Locale.CANADA, Locale.GERMANY, Locale.TAIWAN }; - Locale.setDefault(availableLocales[(int) (Math.random() * availableLocales.length)]); - ourLog.info("Tests are running in locale: " + Locale.getDefault().getDisplayName()); - if (Math.random() < 0.5) { - ourLog.info("Tests are using WINDOWS line endings and ISO-8851-1"); - System.setProperty("file.encoding", "ISO-8859-1"); - System.setProperty("line.separator", "\r\n"); - } else { - ourLog.info("Tests are using UNIX line endings and UTF-8"); - System.setProperty("file.encoding", "UTF-8"); - System.setProperty("line.separator", "\n"); - } - String availableTimeZones[] = { "GMT+08:00", "GMT-05:00", "GMT+00:00", "GMT+03:30" }; - String timeZone = availableTimeZones[(int) (Math.random() * availableTimeZones.length)]; - TimeZone.setDefault(TimeZone.getTimeZone(timeZone)); - ourLog.info("Tests are using time zone: {}", TimeZone.getDefault().getID()); + randomizeLocale(); /* * If we're running a CI build, set all loggers to TRACE level to ensure coverage @@ -116,4 +96,28 @@ public class TestUtil { } } + /** + * Set some system properties randomly after each test.. this is kind of hackish, + * but it helps us make sure we don't have any tests that depend on a particular + * environment + */ + public static void randomizeLocale() { + Locale[] availableLocales = { Locale.CANADA, Locale.GERMANY, Locale.TAIWAN }; + Locale.setDefault(availableLocales[(int) (Math.random() * availableLocales.length)]); + ourLog.info("Tests are running in locale: " + Locale.getDefault().getDisplayName()); + if (Math.random() < 0.5) { + ourLog.info("Tests are using WINDOWS line endings and ISO-8851-1"); + System.setProperty("file.encoding", "ISO-8859-1"); + System.setProperty("line.separator", "\r\n"); + } else { + ourLog.info("Tests are using UNIX line endings and UTF-8"); + System.setProperty("file.encoding", "UTF-8"); + System.setProperty("line.separator", "\n"); + } + String availableTimeZones[] = { "GMT+08:00", "GMT-05:00", "GMT+00:00", "GMT+03:30" }; + String timeZone = availableTimeZones[(int) (Math.random() * availableTimeZones.length)]; + TimeZone.setDefault(TimeZone.getTimeZone(timeZone)); + ourLog.info("Tests are using time zone: {}", TimeZone.getDefault().getID()); + } + }