KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.sql.Statement JavaDoc;
21
22 import junit.framework.Test;
23 import junit.framework.TestCase;
24 import junit.framework.TestSuite;
25
26 /**
27  * @author Rodney Waldhoff
28  * @author Dirk Verbeeck
29  * @version $Revision: 1.6 $ $Date: 2004/02/28 11:47:51 $
30  */

31 public class TestDelegatingStatement extends TestCase {
32     public TestDelegatingStatement(String JavaDoc 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 JavaDoc delegateConn = null;
42     private DelegatingStatement stmt = null;
43     private Statement JavaDoc delegateStmt = null;
44
45     public void setUp() throws Exception JavaDoc {
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 JavaDoc {
53         assertNull(stmt.executeQuery("null"));
54     }
55
56     public void testGetDelegate() throws Exception JavaDoc {
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