Class TestUtil

java.lang.Object
org.apache.calcite.util.TestUtil

public abstract class TestUtil extends Object
Static utilities for JUnit tests.
  • Field Details

    • AVATICA_VERSION

      public static final Version AVATICA_VERSION
  • Constructor Details

    • TestUtil

      public TestUtil()
  • Method Details

    • assertEqualsVerbose

      public static void assertEqualsVerbose(String expected, String actual)
    • assertThatScientific

      public static void assertThatScientific(String value, org.hamcrest.Matcher<String> matcher)
    • quoteForJava

      public static String quoteForJava(String s)
      Converts a string (which may contain quotes and newlines) into a java literal.

      For example,

      
       string with "quotes" split
       across lines

      becomes

      
       "string with \"quotes\" split" + "\n"
         + "across lines"
    • toJavaString

      public static String toJavaString(String s)
      Converts a string (which may contain quotes and newlines) into a java literal.

      For example,

      {code
       string with "quotes" split
       across lines}

      becomes

      
       TestUtil.fold("string with \"quotes\" split\n",
           + "across lines")
    • fold

      public static String fold(String... strings)
      Combines an array of strings, each representing a line, into a single string containing line separators.
    • escapeString

      public static String escapeString(String s)
      Quotes a string for Java or JSON.
    • escapeString

      public static StringBuilder escapeString(StringBuilder buf, String s)
      Quotes a string for Java or JSON, into a builder.
    • quotePattern

      public static String quotePattern(String s)
      Quotes a pattern.
    • correctRoundedFloat

      public static String correctRoundedFloat(String s)
      Removes floating-point rounding errors from the end of a string.

      12.300000006 becomes 12.3; -12.37999999991 becomes -12.38.

    • getJavaMajorVersion

      public static int getJavaMajorVersion()
      Returns the Java major version: 7 for JDK 1.7, 8 for JDK 8, 10 for JDK 10, etc. depending on current system property java.version.
    • getGuavaMajorVersion

      public static int getGuavaMajorVersion()
      Returns the Guava major version.
    • getJavaVirtualMachineVendor

      public static String getJavaVirtualMachineVendor()
      Returns the JVM vendor.
    • getBaseDir

      public static File getBaseDir(Class<?> klass)
      Returns the root directory of the source tree.
    • outOfOrderItems

      public static <E extends Comparable<E>> SortedSet<E> outOfOrderItems(List<E> list)
      Given a list, returns the number of elements that are not between an element that is less and an element that is greater.
    • hasMessage

      public static boolean hasMessage(Throwable t, String substring)
      Checks if exceptions have give substring. That is handy to prevent logging SQL text twice
    • rethrow

      public static <E extends Throwable> RuntimeException rethrow(Throwable e) throws E
      Rethrows given exception keeping stacktraces clean and compact.
      Throws:
      E extends Throwable
    • rethrow

      public static <E extends Throwable> RuntimeException rethrow(Throwable e, String message) throws E
      Rethrows given exception keeping stacktraces clean and compact.
      Throws:
      E extends Throwable
    • printStackTrace

      public static String printStackTrace(Throwable t)
      Returns string representation of the given Throwable.