Package org.apache.calcite.util
Class TestUtil
java.lang.Object
org.apache.calcite.util.TestUtil
Static utilities for JUnit tests.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
assertEqualsVerbose
(String expected, String actual) static String
Removes floating-point rounding errors from the end of a string.static String
Quotes a string for Java or JSON.static StringBuilder
escapeString
(StringBuilder buf, String s) Quotes a string for Java or JSON, into a builder.static String
Combines an array of strings, each representing a line, into a single string containing line separators.static int
Returns the Guava major version.static int
Returns the Java major version: 7 for JDK 1.7, 8 for JDK 8, 10 for JDK 10, etc.static String
Returns the JVM vendor.static boolean
hasMessage
(Throwable t, String substring) Checks if exceptions have give substring.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.static String
Returns string representation of the givenThrowable
.static String
Converts a string (which may contain quotes and newlines) into a java literal.static String
Quotes a pattern.static <E extends Throwable>
RuntimeExceptionRethrows given exception keeping stacktraces clean and compact.static <E extends Throwable>
RuntimeExceptionRethrows given exception keeping stacktraces clean and compact.static String
Rounds all decimal fractions inside a string to a given number of decimal places.static String
Converts a string (which may contain quotes and newlines) into a java literal.
-
Constructor Details
-
TestUtil
public TestUtil()
-
-
Method Details
-
assertEqualsVerbose
-
quoteForJava
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" + NL + "across lines"
-
toJavaString
Converts a string (which may contain quotes and newlines) into a java literal.For example,
string with "quotes" split across lines
becomes
TestUtil.fold( "string with \"quotes\" split\n", + "across lines")
-
fold
Combines an array of strings, each representing a line, into a single string containing line separators. -
escapeString
Quotes a string for Java or JSON. -
escapeString
Quotes a string for Java or JSON, into a builder. -
quotePattern
Quotes a pattern. -
correctRoundedFloat
Removes floating-point rounding errors from the end of a string.12.300000006
becomes12.3
;-12.37999999991
becomes-12.38
. -
roundGeom
Rounds all decimal fractions inside a string to a given number of decimal places.For example,
round("POINT(-1.23456, 9.87654)", 3)
returns "POINT(-1.235, 9.877)". -
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 propertyjava.version
. -
getGuavaMajorVersion
public static int getGuavaMajorVersion()Returns the Guava major version. -
getJavaVirtualMachineVendor
Returns the JVM vendor. -
outOfOrderItems
Given a list, returns the number of elements that are not between an element that is less and an element that is greater. -
hasMessage
Checks if exceptions have give substring. That is handy to prevent logging SQL text twice -
rethrow
Rethrows given exception keeping stacktraces clean and compact.- Throws:
E extends Throwable
-
rethrow
Rethrows given exception keeping stacktraces clean and compact.- Throws:
E extends Throwable
-
printStackTrace
Returns string representation of the givenThrowable
.
-