Test refactor

This commit is contained in:
jamesagnew 2016-12-10 08:44:00 -05:00
parent 0def3d5a72
commit 1fba4ff265

View File

@ -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());
}
}