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/03/29 14:38:08 UTC
svn commit: r389783 -
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java
Author: kahatlen
Date: Wed Mar 29 04:38:04 2006
New Revision: 389783
URL: http://svn.apache.org/viewcvs?rev=389783&view=rev
Log:
DERBY-1162: Add mechanism to assert/compare SQLStates
Adding method 'assertSQLState' to BaseJDBCTestCase. Patch contributed
by Kristian Waagan.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java?rev=389783&r1=389782&r2=389783&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java Wed Mar 29 04:38:04 2006
@@ -201,6 +201,33 @@
}
/**
+ * Assert that SQLState is as expected.
+ * The expected SQLState is truncated to five characters if required.
+ *
+ * @param message message to print on failure.
+ * @param expected the expected SQLState.
+ * @param exception the exception to check the SQLState of.
+ *
+ * @throws IllegalArgumentException if exception is <code>null</code>.
+ */
+ public static void assertSQLState(String message,
+ String expected,
+ SQLException exception) {
+ // Make sure exception is not null. We want to separate between a
+ // null-exception object, and a null-SQLState.
+ if (exception == null) {
+ throw new IllegalArgumentException("Exception cannot be null " +
+ "when asserting SQLState");
+ }
+ // Make sure the expected SQLState is 5 characters long, if not null.
+ // If it is too short, we let it be.
+ if (expected != null && expected.length() > 5) {
+ expected = expected.substring(0, 5);
+ }
+ assertEquals(message, expected, exception.getSQLState());
+ }
+
+ /**
* Load the specified JDBC driver
*
* @param driverClass name of the JDBC driver class.