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