Class TestUtil

java.lang.Object
ca.uhn.fhir.util.TestUtil

public class TestUtil extends Object
  • Constructor Details

  • Method Details

    • setShouldRandomizeTimezones

      public static void setShouldRandomizeTimezones(boolean theShouldRandomizeTimezones)
    • randomizeLocaleAndTimezone

      public static void randomizeLocaleAndTimezone()
      THIS IS FOR UNIT TESTS ONLY - DO NOT CALL THIS METHOD FROM USER CODE

      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.

    • doRandomizeLocaleAndTimezone

      public static void doRandomizeLocaleAndTimezone()
      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
    • waitForSize

      public static void waitForSize(int theTarget, AtomicInteger theInteger)
      THIS IS FOR UNIT TESTS ONLY - DO NOT CALL THIS METHOD FROM USER CODE

      Wait for an atomicinteger to hit a given site and fail if it never does

    • waitForSize

      public static void waitForSize(int theTarget, Callable<Integer> theSource) throws Exception
      THIS IS FOR UNIT TESTS ONLY - DO NOT CALL THIS METHOD FROM USER CODE

      Wait for an atomicinteger to hit a given site and fail if it never does

      Throws:
      Exception
    • stripReturns

      public static String stripReturns(String theString)
      THIS IS FOR UNIT TESTS ONLY - DO NOT CALL THIS METHOD FROM USER CODE

      Strip \r chars from a string to account for line ending platform differences

    • stripWhitespace

      public static String stripWhitespace(String theString)
      THIS IS FOR UNIT TESTS ONLY - DO NOT CALL THIS METHOD FROM USER CODE

      Strip \r chars from a string to account for line ending platform differences

    • sleepAtLeast

      public static void sleepAtLeast(long theMillis)
      In production code, instead of this static method, it is better to use an instance of SleepUtil. Since SleepUtil isn't using static methods, it is easier to mock for unit test and avoid unnecessary waits in unit tests
    • sleepAtLeast

      public static void sleepAtLeast(long theMillis, boolean theLogProgress)
      In production code, instead of this static method, it is better to use an instance of SleepUtil. Since SleepUtil isn't using static methods, it is easier to mock for unit test and avoid unnecessary waits in unit tests