1 16 17 package org.apache.commons.dbcp; 18 19 import java.sql.Connection ; 20 21 import junit.framework.Test; 22 import junit.framework.TestCase; 23 import junit.framework.TestSuite; 24 25 29 public class TestDelegatingConnection extends TestCase { 30 public TestDelegatingConnection(String testName) { 31 super(testName); 32 } 33 34 public static Test suite() { 35 return new TestSuite(TestDelegatingConnection.class); 36 } 37 38 private DelegatingConnection conn = null; 39 private Connection delegateConn = null; 40 private Connection delegateConn2 = null; 41 42 public void setUp() throws Exception { 43 delegateConn = new TesterConnection("test", "test"); 44 delegateConn2 = new TesterConnection("test", "test"); 45 conn = new DelegatingConnection(delegateConn); 46 } 47 48 49 public void testGetDelegate() throws Exception { 50 assertEquals(delegateConn,conn.getDelegate()); 51 } 52 53 public void testHashCodeEqual() { 54 DelegatingConnection conn = new DelegatingConnection(delegateConn); 55 DelegatingConnection conn2 = new DelegatingConnection(delegateConn); 56 assertEquals(conn.hashCode(), conn2.hashCode()); 57 } 58 59 public void testHashCodeNotEqual() { 60 DelegatingConnection conn = new DelegatingConnection(delegateConn); 61 DelegatingConnection conn2 = new DelegatingConnection(delegateConn2); 62 assertTrue(conn.hashCode() != conn2.hashCode()); 63 } 64 65 public void testEquals() { 66 DelegatingConnection conn = new DelegatingConnection(delegateConn); 67 DelegatingConnection conn2 = new DelegatingConnection(delegateConn); 68 DelegatingConnection conn3 = new DelegatingConnection(null); 69 70 assertTrue(!conn.equals(null)); 71 assertTrue(conn.equals(conn2)); 72 assertTrue(!conn.equals(conn3)); 73 } 74 } 75 | Popular Tags |