Fix tests

This commit is contained in:
James 2016-08-23 07:49:18 -04:00
parent aa16a46b74
commit 1ca39a9e71
1 changed files with 16 additions and 13 deletions

View File

@ -10,7 +10,7 @@ package ca.uhn.fhir.util;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@ -39,12 +39,12 @@ public class TestUtil {
/**
* <b>THIS IS FOR UNIT TESTS ONLY - DO NOT CALL THIS METHOD FROM USER CODE</b>
*
* When we run the unit tests in cobertura, JUnit doesn't seem to clean up static fields which leads to
* When we run the unit tests in cobertura, JUnit doesn't seem to clean up static fields which leads to
* tons of memory being used by the end and the JVM crashes in Travis. Manually clearing all of the
* static fields seems to solve this.
*/
public static void clearAllStaticFieldsForUnitTest() {
Class<?> theType;
try {
throw new Exception();
@ -58,7 +58,7 @@ public class TestUtil {
throw new Error(e);
}
}
for (Field next : Arrays.asList(theType.getDeclaredFields())) {
if (Modifier.isStatic(next.getModifiers())) {
if (!Modifier.isFinal(next.getModifiers()) && !next.getType().isPrimitive()) {
@ -82,7 +82,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
* environment
*/
Locale[] availableLocales = { Locale.CANADA, Locale.GERMANY, Locale.TAIWAN };
Locale.setDefault(availableLocales[(int) (Math.random() * availableLocales.length)]);
@ -96,21 +96,24 @@ public class TestUtil {
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)];
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());
/*
* If we're running a CI build, set all loggers to TRACE level to ensure coverage
* on trace blocks
* on trace blocks
*/
if ("true".equals(System.getProperty("ci"))) {
for (Logger next : ((LoggerContext)LoggerFactory.getILoggerFactory()).getLoggerList()) {
next.setLevel(Level.TRACE);
try {
if ("true".equals(System.getProperty("ci"))) {
for (Logger next : ((LoggerContext) LoggerFactory.getILoggerFactory()).getLoggerList()) {
next.setLevel(Level.TRACE);
}
}
} catch (NoClassDefFoundError e) {
// ignore
}
}
}