You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2006/11/21 13:10:39 UTC
svn commit: r477645 -
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java
Author: kahatlen
Date: Tue Nov 21 04:10:38 2006
New Revision: 477645
URL: http://svn.apache.org/viewvc?view=rev&rev=477645
Log:
DERBY-2102: JDBC.assertFullResultSet should handle byte arrays
Patch contributed by Øystein Grøvlen.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java?view=diff&rev=477645&r1=477644&r2=477645
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java Tue Nov 21 04:10:38 2006
@@ -21,6 +21,7 @@
import java.sql.*;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
@@ -644,16 +645,41 @@
boolean ok = (rs.wasNull() && (expectedRow[i] == null))
|| (!rs.wasNull()
&& (expectedRow[i] != null)
- && expectedRow[i].equals(obj));
-
+ && (expectedRow[i].equals(obj)
+ || (obj instanceof byte[] // Assumes byte arrays
+ && Arrays.equals((byte[] )obj,
+ (byte[] )expectedRow[i]))));
if (!ok)
{
+ Object expected = expectedRow[i];
+ Object found = obj;
+ if (obj instanceof byte[]) {
+ expected = bytesToString((byte[] )expectedRow[i]);
+ found = bytesToString((byte[] )obj);
+ }
Assert.fail("Column value mismatch @ column '" +
rsmd.getColumnName(i+1) + "', row " + rowNum +
- ":\n Expected: >" + expectedRow[i] +
- "<\n Found: >" + obj + "<");
+ ":\n Expected: >" + expected +
+ "<\n Found: >" + found + "<");
}
}
+ }
+
+ /**
+ * Convert byte array to String.
+ * Each byte is converted to a hexadecimal string representation.
+ *
+ * @param ba Byte array to be converted.
+ * @return Hexadecimal string representation. Returns null on null input.
+ */
+ private static String bytesToString(byte[] ba)
+ {
+ if (ba == null) return null;
+ StringBuffer s = new StringBuffer();
+ for (int i = 0; i < ba.length; ++i) {
+ s.append(Integer.toHexString(ba[i] & 0x00ff));
+ }
+ return s.toString();
}
/**