You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2015/04/16 23:02:29 UTC
[5/6] incubator-calcite git commit: Add
CalciteAssert.assertArrayEqual for more user-friendly asserts
Add CalciteAssert.assertArrayEqual for more user-friendly asserts
Project: http://git-wip-us.apache.org/repos/asf/incubator-calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-calcite/commit/28d640af
Tree: http://git-wip-us.apache.org/repos/asf/incubator-calcite/tree/28d640af
Diff: http://git-wip-us.apache.org/repos/asf/incubator-calcite/diff/28d640af
Branch: refs/heads/master
Commit: 28d640af324e91237f82590467e2d239393b3eaa
Parents: b6283db
Author: Vladimir Sitnikov <si...@gmail.com>
Authored: Tue Feb 10 12:57:44 2015 +0300
Committer: Julian Hyde <jh...@apache.org>
Committed: Thu Apr 16 02:21:43 2015 -0700
----------------------------------------------------------------------
.../org/apache/calcite/test/CalciteAssert.java | 35 ++++++++++++++++----
1 file changed, 28 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/28d640af/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/CalciteAssert.java b/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
index 9ebb85a..f221b02 100644
--- a/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
+++ b/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
@@ -39,6 +39,7 @@ import org.apache.calcite.util.Util;
import com.google.common.base.Function;
import com.google.common.base.Functions;
+import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.cache.CacheBuilder;
@@ -470,16 +471,14 @@ public class CalciteAssert {
resultSet.close();
statement.close();
connection.close();
- } catch (Throwable e) {
+ } catch (Error e) {
// We ignore extended message for non-runtime exception, however
// it does not matter much since it is better to have AssertionError
// at the very top level of the exception stack.
- if (e instanceof RuntimeException) {
- throw (RuntimeException) e;
- }
- if (e instanceof Error) {
- throw (Error) e;
- }
+ throw e;
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Throwable e) {
throw new RuntimeException(message, e);
} finally {
for (Hook.Closeable closeable : closeableList) {
@@ -724,6 +723,28 @@ public class CalciteAssert {
}
}
+ /**
+ * Asserts that two objects are equal. If they are not, an
+ * {@link AssertionError} is thrown with the given message. If
+ * <code>expected</code> and <code>actual</code> are <code>null</code>,
+ * they are considered equal.
+ *
+ * <p>This method produces more user-friendly error messages than
+ * {@link org.junit.Assert#assertArrayEquals(String, Object[], Object[])}
+ *
+ * @param message the identifying message for the {@link AssertionError} (<code>null</code>
+ * okay)
+ * @param expected expected value
+ * @param actual actual value
+ */
+ public static void assertArrayEqual(
+ String message, Object[] expected, Object[] actual) {
+ Joiner joiner = Joiner.on('\n');
+ String strExpected = expected == null ? null : joiner.join(expected);
+ String strActual = actual == null ? null : joiner.join(actual);
+ assertEquals(message, strExpected, strActual);
+ }
+
static <F, T> Function<F, T> constantNull() {
//noinspection unchecked
return (Function<F, T>) (Function) Functions.<T>constant(null);