KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > dbcp > TestDelegatingConnection


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.dbcp;
18
19 import java.sql.Connection JavaDoc;
20
21 import junit.framework.Test;
22 import junit.framework.TestCase;
23 import junit.framework.TestSuite;
24
25 /**
26  * @author Dirk Verbeeck
27  * @version $Revision: 1.6 $ $Date: 2004/02/28 11:47:51 $
28  */

29 public class TestDelegatingConnection extends TestCase {
30     public TestDelegatingConnection(String JavaDoc 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 JavaDoc delegateConn = null;
40     private Connection JavaDoc delegateConn2 = null;
41
42     public void setUp() throws Exception JavaDoc {
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 JavaDoc {
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