1 16 17 package org.apache.commons.dbcp; 18 19 import java.sql.Connection ; 20 import java.sql.PreparedStatement ; 21 22 import junit.framework.Test; 23 import junit.framework.TestCase; 24 import junit.framework.TestSuite; 25 26 31 public class TestDelegatingPreparedStatement extends TestCase { 32 public TestDelegatingPreparedStatement(String testName) { 33 super(testName); 34 } 35 36 public static Test suite() { 37 return new TestSuite(TestDelegatingPreparedStatement.class); 38 } 39 40 private DelegatingConnection conn = null; 41 private Connection delegateConn = null; 42 private DelegatingPreparedStatement stmt = null; 43 private PreparedStatement delegateStmt = null; 44 45 public void setUp() throws Exception { 46 delegateConn = new TesterConnection("test", "test"); 47 conn = new DelegatingConnection(delegateConn); 48 } 49 50 public void testExecuteQueryReturnsNull() throws Exception { 51 delegateStmt = new TesterPreparedStatement(delegateConn,"null"); 52 stmt = new DelegatingPreparedStatement(conn,delegateStmt); 53 assertNull(stmt.executeQuery()); 54 } 55 56 public void testExecuteQueryReturnsNotNull() throws Exception { 57 delegateStmt = new TesterPreparedStatement(delegateConn,"select * from foo"); 58 stmt = new DelegatingPreparedStatement(conn,delegateStmt); 59 assertTrue(null != stmt.executeQuery()); 60 } 61 62 public void testGetDelegate() throws Exception { 63 delegateStmt = new TesterPreparedStatement(delegateConn,"select * from foo"); 64 stmt = new DelegatingPreparedStatement(conn,delegateStmt); 65 assertEquals(delegateStmt,stmt.getDelegate()); 66 } 67 68 public void testHashCodeNull() { 69 stmt = new DelegatingPreparedStatement(conn, null); 70 assertEquals(0, stmt.hashCode()); 71 } 72 73 public void testHashCode() { 74 delegateStmt = new TesterPreparedStatement(delegateConn,"select * from foo"); 75 DelegatingPreparedStatement stmt = new DelegatingPreparedStatement(conn,delegateStmt); 76 DelegatingPreparedStatement stmt2 = new DelegatingPreparedStatement(conn,delegateStmt); 77 assertEquals(stmt.hashCode(), stmt2.hashCode()); 78 } 79 80 public void testEquals() { 81 delegateStmt = new TesterPreparedStatement(delegateConn,"select * from foo"); 82 DelegatingPreparedStatement stmt = new DelegatingPreparedStatement(conn, delegateStmt); 83 DelegatingPreparedStatement stmt2 = new DelegatingPreparedStatement(conn, delegateStmt); 84 DelegatingPreparedStatement stmt3 = new DelegatingPreparedStatement(conn, null); 85 86 assertTrue(!stmt.equals(null)); 87 assertTrue(stmt.equals(stmt2)); 88 assertTrue(!stmt.equals(stmt3)); 89 } 90 91 } 92 | Popular Tags |