db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r423800 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/
Date Thu, 20 Jul 2006 06:25:01 GMT
Author: kahatlen
Date: Wed Jul 19 23:25:01 2006
New Revision: 423800

URL: http://svn.apache.org/viewvc?rev=423800&view=rev
Log:
DERBY-1536: Extend tests for Wrapper interface

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/DataSourceTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ParameterMetaDataWrapperTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetMetaDataTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementTest.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java?rev=423800&r1=423799&r2=423800&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java
Wed Jul 19 23:25:01 2006
@@ -23,7 +23,6 @@
 import junit.framework.*;
 
 import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
-import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
 
 import java.io.IOException;
 import java.io.Reader;
@@ -472,65 +471,53 @@
             // We are fine, do nothing.
         }
     }
-    
-    /**
-     *
-     * Tests the wrapper methods isWrapperFor and unwrap. Test
-     * for the case when isWrapperFor returns true and we call unwrap
-     * The test is right now being run in the embedded case only
-     *
-     */
-    public void testisWrapperReturnsTrue() throws SQLException {
-        Class<CallableStatement> wrap_class = CallableStatement.class;
-        
-        //The if should return true enabling us  to call the unwrap method
-        //without throwing  an exception
-        if(cStmt.isWrapperFor(wrap_class)) {
-            try {
-                CallableStatement stmt1 =
-                        (CallableStatement)cStmt.unwrap(wrap_class);
-            }
-            catch(SQLException sqle) {
-                fail("Unwrap wrongly throws a SQLException");
-            }
-        } else {
-            fail("isWrapperFor wrongly returns false");
-        }
+
+    /** Helper method for testIsWrapperFor*Statement test cases. */
+    private void testIsWrapperForXXXStatement(Class klass) throws SQLException {
+        assertTrue("The CallableStatement is not a wrapper for "
+                       + klass.getName(),
+                   cStmt.isWrapperFor(klass));
     }
-    
-    /**
-     *
-     * Tests the wrapper methods isWrapperFor and unwrap. Test
-     * for the case when isWrapperFor returns false and we call unwrap
-     * The test is right now being run in the embedded case only
-     *
-     */
-    public void testisWrapperReturnsFalse() throws SQLException {
-        //test for the case when isWrapper returns false
-        //using some class that will return false when
-        //passed to isWrapperFor
-        Class<ResultSet> wrap_class = ResultSet.class;
-        
-        //returning false is the correct behaviour in this case
-        //Generate a message if it returns true
-        if(cStmt.isWrapperFor(wrap_class)) {
-            fail("isWrapperFor wrongly returns true");
-        } else {
-            try {
-                ResultSet rs1 = (ResultSet)
-                cStmt.unwrap(wrap_class);
-                fail("unwrap does not throw the expected " +
-                        "exception");
-            } catch (SQLException sqle) {
-                //calling unwrap in this case throws an SQLException
-                //check that this SQLException has the correct SQLState
-                if(!SQLStateConstants.UNABLE_TO_UNWRAP.equals(sqle.getSQLState())) {
-                    throw sqle;
-                }
-            }
-        }
+
+    public void testIsWrapperForStatement() throws SQLException {
+        testIsWrapperForXXXStatement(Statement.class);
     }
 
+    public void testIsWrapperForPreparedStatement() throws SQLException {
+        testIsWrapperForXXXStatement(PreparedStatement.class);
+    }
+
+    public void testIsWrapperForCallableStatement() throws SQLException {
+        testIsWrapperForXXXStatement(CallableStatement.class);
+    }
+
+    public void testIsNotWrapperForResultSet() throws SQLException {
+        assertFalse(cStmt.isWrapperFor(ResultSet.class));
+    }
+
+    public void testUnwrapStatement() throws SQLException {
+        Statement stmt = cStmt.unwrap(Statement.class);
+        assertSame("Unwrap returned wrong object.", cStmt, stmt);
+    }
+
+    public void testUnwrapPreparedStatement() throws SQLException {
+        PreparedStatement ps = cStmt.unwrap(PreparedStatement.class);
+        assertSame("Unwrap returned wrong object.", cStmt, ps);
+    }
+
+    public void testUnwrapCallableStatement() throws SQLException {
+        Statement cs = cStmt.unwrap(CallableStatement.class);
+        assertSame("Unwrap returned wrong object.", cStmt, cs);
+    }
+
+    public void testUnwrapResultSet() {
+        try {
+            ResultSet rs = cStmt.unwrap(ResultSet.class);
+            fail("Unwrap didn't fail.");
+        } catch (SQLException e) {
+            assertSQLState("XJ128", e);
+        }
+    }
 
     /**
      *

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/DataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/DataSourceTest.java?rev=423800&r1=423799&r2=423800&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/DataSourceTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/DataSourceTest.java
Wed Jul 19 23:25:01 2006
@@ -24,7 +24,6 @@
 
 import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
 import org.apache.derbyTesting.functionTests.util.TestDataSourceFactory;
-import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
 
 import java.sql.*;
 import javax.sql.*;
@@ -64,62 +63,56 @@
     public void tearDown() {
         ds = null;
     }
-    
-    /**
-     *
-     * Tests the wrapper methods isWrapperFor and unwrap. Test
-     * for the case when isWrapperFor returns true and we call unwrap
-     * The test is right now being run in the embedded case only
-     *
-     */
-    public void testisWrapperReturnsTrue() throws SQLException {
-        Class<DataSource> wrap_class = DataSource.class;
-        
-        //The if should return true enabling us  to call the unwrap method
-        //without throwing  an exception
-        if(ds.isWrapperFor(wrap_class)) {
-            try {
-                DataSource stmt1 =
-                        (DataSource)ds.unwrap(wrap_class);
-            }
-            catch(SQLException sqle) {
-                fail("Unwrap wrongly throws a SQLException");
-            }
-        } else {
-            fail("isWrapperFor wrongly returns false");
+
+    public void testIsWrapperForDataSource() throws SQLException {
+        assertTrue(ds.isWrapperFor(DataSource.class));
+    }
+
+    public void testIsNotWrapperForPoolDataSource() throws SQLException {
+        assertFalse(ds.isWrapperFor(ConnectionPoolDataSource.class));
+    }
+
+    public void testIsNotWrapperForXADataSource() throws SQLException {
+        assertFalse(ds.isWrapperFor(XADataSource.class));
+    }
+
+    public void testIsNotWrapperForResultSet() throws SQLException {
+        assertFalse(ds.isWrapperFor(ResultSet.class));
+    }
+
+    public void testUnwrapDataSource() throws SQLException {
+        DataSource ds2 = ds.unwrap(DataSource.class);
+        assertSame("Unwrap returned wrong object.", ds, ds2);
+    }
+
+    public void testUnwrapConnectionPoolDataSource() {
+        try {
+            ConnectionPoolDataSource cpds =
+                ds.unwrap(ConnectionPoolDataSource.class);
+            fail("Unwrap didn't fail.");
+        } catch (SQLException e) {
+            assertSQLState("XJ128", e);
         }
     }
-    
-    /**
-     *
-     * Tests the wrapper methods isWrapperFor and unwrap. Test
-     * for the case when isWrapperFor returns false and we call unwrap
-     * The test is right now being run in the embedded case only
-     *
-     */
-    public void testisWrapperReturnsFalse() throws SQLException {
-        Class<ResultSet> wrap_class = ResultSet.class;
-        
-        //returning false is the correct behaviour in this case
-        //Generate a message if it returns true
-        if(ds.isWrapperFor(wrap_class)) {
-            fail("isWrapperFor wrongly returns true");
-        } else {
-            try {
-                ResultSet rs1 = (ResultSet)
-                ds.unwrap(wrap_class);
-                fail("unwrap does not throw the expected " +
-                        "exception");
-            } catch (SQLException sqle) {
-                //calling unwrap in this case throws an SQLException
-                //check that this SQLException has the correct SQLState
-                if(!SQLStateConstants.UNABLE_TO_UNWRAP.equals(sqle.getSQLState())) {
-                    throw sqle;
-                }
-            }
+
+    public void testUnwrapXADataSource() {
+        try {
+            XADataSource xads = ds.unwrap(XADataSource.class);
+            fail("Unwrap didn't fail.");
+        } catch (SQLException e) {
+            assertSQLState("XJ128", e);
         }
     }
-    
+
+    public void testUnwrapResultSet() {
+        try {
+            ResultSet rs = ds.unwrap(ResultSet.class);
+            fail("Unwrap didn't fail.");
+        } catch (SQLException e) {
+            assertSQLState("XJ128", e);
+        }
+    }
+
     /**
      * Return suite with all tests of the class.
      */

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ParameterMetaDataWrapperTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ParameterMetaDataWrapperTest.java?rev=423800&r1=423799&r2=423800&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ParameterMetaDataWrapperTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ParameterMetaDataWrapperTest.java
Wed Jul 19 23:25:01 2006
@@ -23,7 +23,6 @@
 import javax.sql.*;
 import junit.framework.*;
 import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
-import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
 
 /**
  * Tests of the <code>java.sql.ParameterMetaData</code> JDBC40 API
@@ -72,65 +71,29 @@
         if(conn != null && !conn.isClosed())
             conn.close();
     }
-    
-    /**
-     *
-     * Tests the wrapper methods isWrapperFor and unwrap. Test
-     * for the case when isWrapperFor returns true and we call unwrap
-     * The test is right now being run in the embedded case only
-     *
-     */
-    public void testisWrapperReturnsTrue() throws SQLException {
-        Class<ParameterMetaData> wrap_class = ParameterMetaData.class;
-        
-        //The if should return true enabling us  to call the unwrap method
-        //without throwing  an exception
-        if(pmd.isWrapperFor(wrap_class)) {
-            try {
-                ParameterMetaData pmd1 =
-                        (ParameterMetaData)pmd.unwrap(wrap_class);
-            }
-            catch(SQLException sqle) {
-                fail("Unwrap wrongly throws a SQLException");
-            }
-        } else {
-            fail("isWrapperFor wrongly returns false");
-        }
+
+    public void testIsWrapperForParameterMetaData() throws SQLException {
+        assertTrue(pmd.isWrapperFor(ParameterMetaData.class));
     }
-    
-    /**
-     *
-     * Tests the wrapper methods isWrapperFor and unwrap. Test
-     * for the case when isWrapperFor returns false and we call unwrap
-     * The test is right now being run in the embedded case only
-     *
-     */
-    public void testisWrapperReturnsFalse() throws SQLException {
-        //test for the case when isWrapper returns false
-        //using some class that will return false when
-        //passed to isWrapperFor
-        Class<ResultSet> wrap_class = ResultSet.class;
-        
-        //returning false is the correct behaviour in this case
-        //Generate a message if it returns true
-        if(pmd.isWrapperFor(wrap_class)) {
-            fail("isWrapperFor wrongly returns true");
-        } else {
-            try {
-                ResultSet rs1 = (ResultSet)
-                pmd.unwrap(wrap_class);
-                fail("unwrap does not throw the expected " +
-                        "exception");
-            } catch (SQLException sqle) {
-                //calling unwrap in this case throws an SQLException
-                //check that this SQLException has the correct SQLState
-                if(!SQLStateConstants.UNABLE_TO_UNWRAP.equals(sqle.getSQLState())) {
-                    throw sqle;
-                }
-            }
+
+    public void testUnwrapParameterMetaData() throws SQLException {
+        ParameterMetaData pmd2 = pmd.unwrap(ParameterMetaData.class);
+        assertSame("Unwrap returned wrong object.", pmd, pmd2);
+    }
+
+    public void testIsNotWrapperForResultSet() throws SQLException {
+        assertFalse(pmd.isWrapperFor(ResultSet.class));
+    }
+
+    public void testUnwrapResultSet() {
+        try {
+            ResultSet rs = pmd.unwrap(ResultSet.class);
+            fail("Unwrap didn't fail.");
+        } catch (SQLException e) {
+            assertSQLState("XJ128", e);
         }
     }
-    
+
     /**
      * Return suite with all tests of the class.
      */

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java?rev=423800&r1=423799&r2=423800&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
Wed Jul 19 23:25:01 2006
@@ -23,7 +23,6 @@
 import junit.framework.*;
 
 import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
-import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
 
 import java.io.*;
 import java.sql.*;
@@ -259,68 +258,48 @@
     //--------------------------------------------------------------------------
     //Now test the methods that are implemented in the PreparedStatement 
     //interface
-    
-    /**
-     *
-     * Tests the wrapper methods isWrapperFor and unwrap. Test
-     * for the case when isWrapperFor returns true and we call unwrap
-     * The test is right now being run in the embedded case only
-     *
-     * @throws SQLException upon any failure that occurs in the 
-     *                      call to the method.
-     *
-     */
-    public void testisWrapperReturnsTrue() throws SQLException {
-        Class<PreparedStatement> wrap_class = PreparedStatement.class;
-        
-        //The if should return true enabling us  to call the unwrap method
-        //without throwing  an exception
-        if(ps.isWrapperFor(wrap_class)) {
-            try {
-                PreparedStatement stmt1 =
-                        (PreparedStatement)ps.unwrap(wrap_class);
-            }
-            catch(SQLException sqle) {
-                fail("Unwrap wrongly throws a SQLException");
-            }
-        } else {
-            fail("isWrapperFor wrongly returns false");
+
+    public void testIsWrapperForStatement() throws SQLException {
+        assertTrue(ps.isWrapperFor(Statement.class));
+    }
+
+    public void testIsWrapperForPreparedStatement() throws SQLException {
+        assertTrue(ps.isWrapperFor(PreparedStatement.class));
+    }
+
+    public void testIsNotWrapperForCallableStatement() throws SQLException {
+        assertFalse(ps.isWrapperFor(CallableStatement.class));
+    }
+
+    public void testIsNotWrapperForResultSet() throws SQLException {
+        assertFalse(ps.isWrapperFor(ResultSet.class));
+    }
+
+    public void testUnwrapStatement() throws SQLException {
+        Statement stmt = ps.unwrap(Statement.class);
+        assertSame("Unwrap returned wrong object.", ps, stmt);
+    }
+
+    public void testUnwrapPreparedStatement() throws SQLException {
+        PreparedStatement ps2 = ps.unwrap(PreparedStatement.class);
+        assertSame("Unwrap returned wrong object.", ps, ps2);
+    }
+
+    public void testUnwrapCallableStatement() {
+        try {
+            CallableStatement cs = ps.unwrap(CallableStatement.class);
+            fail("Unwrap didn't fail.");
+        } catch (SQLException e) {
+            assertSQLState("XJ128", e);
         }
     }
-    
-    /**
-     *
-     * Tests the wrapper methods isWrapperFor and unwrap. Test
-     * for the case when isWrapperFor returns false and we call unwrap
-     * The test is right now being run in the embedded case only
-     *
-     * @throws SQLException upon any failure that occurs in the 
-     *                      call to the method.
-     *
-     */
-    public void testisWrapperReturnsFalse() throws SQLException {
-        //test for the case when isWrapper returns false
-        //using some class that will return false when
-        //passed to isWrapperFor
-        Class<ResultSet> wrap_class = ResultSet.class;
-        
-        //returning false is the correct behaviour in this case
-        //Generate a message if it returns true
-        if(ps.isWrapperFor(wrap_class)) {
-            fail("isWrapperFor wrongly returns true");
-        } else {
-            try {
-                ResultSet rs1 = (ResultSet)
-                ps.unwrap(wrap_class);
-                fail("unwrap does not throw the expected " +
-                        "exception");
-            } catch (SQLException sqle) {
-                //calling unwrap in this case throws an SQLException
-                //check that this SQLException has the correct SQLState
-                if(!SQLStateConstants.UNABLE_TO_UNWRAP.equals(sqle.getSQLState())) {
-                    throw sqle;
-                }
-            }
+
+    public void testUnwrapResultSet() {
+        try {
+            ResultSet rs = ps.unwrap(ResultSet.class);
+            fail("Unwrap didn't fail.");
+        } catch (SQLException e) {
+            assertSQLState("XJ128", e);
         }
     }
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetMetaDataTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetMetaDataTest.java?rev=423800&r1=423799&r2=423800&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetMetaDataTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetMetaDataTest.java
Wed Jul 19 23:25:01 2006
@@ -72,62 +72,29 @@
             conn.close();
         }
     }
-    
-    /**
-     *
-     * Tests the wrapper methods isWrapperFor and unwrap. Test
-     * for the case when isWrapperFor returns true and we call unwrap
-     * The test is right now being run in the embedded case only
-     *
-     */
-    public void testisWrapperReturnsTrue() throws SQLException {
-        Class<ResultSetMetaData> wrap_class = ResultSetMetaData.class;
-        
-        //The if should return true enabling us  to call the unwrap method
-        //without throwing  an exception
-        if(rsmd.isWrapperFor(wrap_class)) {
-            try {
-                ResultSetMetaData rsmd1 =
-                        (ResultSetMetaData)rsmd.unwrap(wrap_class);
-            }
-            catch(SQLException sqle) {
-                fail("Unwrap wrongly throws a SQLException");
-            }
-        } else {
-            fail("isWrapperFor wrongly returns false");
-        }
+
+    public void testIsWrapperForResultSetMetaData() throws SQLException {
+        assertTrue(rsmd.isWrapperFor(ResultSetMetaData.class));
+    }
+
+    public void testUnwrapResultSetMetaData() throws SQLException {
+        ResultSetMetaData rsmd2 = rsmd.unwrap(ResultSetMetaData.class);
+        assertSame("Unwrap returned wrong object.", rsmd, rsmd2);
+    }
+
+    public void testIsWrapperForResultSet() throws SQLException {
+        assertFalse(rsmd.isWrapperFor(ResultSet.class));
     }
-    
-    /**
-     *
-     * Tests the wrapper methods isWrapperFor and unwrap. Test
-     * for the case when isWrapperFor returns false and we call unwrap
-     * The test is right now being run in the embedded case only
-     *
-     */
-    public void testisWrapperReturnsFalse() throws SQLException {
-        Class<ResultSet> wrap_class = ResultSet.class;
-        
-        //returning false is the correct behaviour in this case
-        //Generate a message if it returns true
-        if(rsmd.isWrapperFor(wrap_class)) {
-            fail("isWrapperFor wrongly returns true");
-        } else {
-            try {
-                ResultSet rs1 = (ResultSet)
-                rsmd.unwrap(wrap_class);
-                fail("unwrap does not throw the expected " +
-                        "exception");
-            } catch (SQLException sqle) {
-                //calling unwrap in this case throws an SQLException
-                //check that this SQLException has the correct SQLState
-                if(!SQLStateConstants.UNABLE_TO_UNWRAP.equals(sqle.getSQLState())) {
-                    throw sqle;
-                }
-            }
+
+    public void testUnwrapResultSet() {
+        try {
+            ResultSet rs = rsmd.unwrap(ResultSet.class);
+            fail("Unwrap didn't fail.");
+        } catch (SQLException e) {
+            assertSQLState("XJ128", e);
         }
     }
-    
+
     /**
      * Return suite with all tests of the class.
      */

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementTest.java?rev=423800&r1=423799&r2=423800&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementTest.java
Wed Jul 19 23:25:01 2006
@@ -221,62 +221,52 @@
         assertTrue("Statement should be closed, because " +
                 "the connection has been closed", stmt.isClosed()); 
     }
-    
-    /**
-     *
-     * Tests the wrapper methods isWrapperFor and unwrap. Test
-     * for the case when isWrapperFor returns true and we call unwrap
-     * The test is right now being run in the embedded case only
-     *
-     */
-    public void testisWrapperReturnsTrue() throws SQLException {
-        Class<Statement> wrap_class = Statement.class;
-        
-        //The if should return true enabling us  to call the unwrap method
-        //without throwing  an exception
-        if(stmt.isWrapperFor(wrap_class)) {
-            try {
-                Statement stmt1 =
-                        (Statement)stmt.unwrap(wrap_class);
-            }
-            catch(SQLException sqle) {
-                fail("Unwrap wrongly throws a SQLException");
-            }
-        } else {
-            fail("isWrapperFor wrongly returns false");
+
+    public void testIsWrapperForStatement() throws SQLException {
+        assertTrue(stmt.isWrapperFor(Statement.class));
+    }
+
+    public void testIsNotWrapperForPreparedStatement() throws SQLException {
+        assertFalse(stmt.isWrapperFor(PreparedStatement.class));
+    }
+
+    public void testIsNotWrapperForCallableStatement() throws SQLException {
+        assertFalse(stmt.isWrapperFor(CallableStatement.class));
+    }
+
+    public void testIsNotWrapperForResultSet() throws SQLException {
+        assertFalse(stmt.isWrapperFor(ResultSet.class));
+    }
+
+    public void testUnwrapStatement() throws SQLException {
+        Statement stmt2 = stmt.unwrap(Statement.class);
+        assertSame("Unwrap returned wrong object.", stmt, stmt2);
+    }
+
+    public void testUnwrapPreparedStatement() {
+        try {
+            PreparedStatement ps = stmt.unwrap(PreparedStatement.class);
+            fail("Unwrap didn't fail.");
+        } catch (SQLException e) {
+            assertSQLState("XJ128", e);
+        }
+    }
+
+    public void testUnwrapCallableStatement() {
+        try {
+            CallableStatement cs = stmt.unwrap(CallableStatement.class);
+            fail("Unwrap didn't fail.");
+        } catch (SQLException e) {
+            assertSQLState("XJ128", e);
         }
     }
-    
-    /**
-     *
-     * Tests the wrapper methods isWrapperFor and unwrap. Test
-     * for the case when isWrapperFor returns false and we call unwrap
-     * The test is right now being run in the embedded case only.
-     *
-     */
-    public void testisWrapperReturnsFalse() throws SQLException {
-        //test for the case when isWrapper returns false
-        //using some class that will return false when
-        //passed to isWrapperFor
-        Class<ResultSet> wrap_class = ResultSet.class;
-        
-        //returning false is the correct behaviour in this case
-        //Generate a message if it returns true
-        if(stmt.isWrapperFor(wrap_class)) {
-            fail("isWrapperFor wrongly returns true");
-        } else {
-            try {
-                ResultSet rs1 = (ResultSet)
-                stmt.unwrap(wrap_class);
-                fail("unwrap does not throw the expected " +
-                        "exception");
-            } catch (SQLException sqle) {
-                //calling unwrap in this case throws an SQLException
-                //check that this SQLException has the correct SQLState
-                if(!SQLStateConstants.UNABLE_TO_UNWRAP.equals(sqle.getSQLState())) {
-                    throw sqle;
-                }
-            }
+
+    public void testUnwrapResultSet() throws SQLException {
+        try {
+            ResultSet rs = stmt.unwrap(ResultSet.class);
+            fail("Unwrap didn't fail.");
+        } catch (SQLException e) {
+            assertSQLState("XJ128", e);
         }
     }
 



Mime
View raw message