KickJava   Java API By Example, From Geeks To Geeks.

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


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.PreparedStatement 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 TestDelegatingPreparedStatement extends TestCase {
32     public TestDelegatingPreparedStatement(String JavaDoc 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 JavaDoc delegateConn = null;
42     private DelegatingPreparedStatement stmt = null;
43     private PreparedStatement JavaDoc delegateStmt = null;
44
45     public void setUp() throws Exception JavaDoc {
46         delegateConn = new TesterConnection("test", "test");
47         conn = new DelegatingConnection(delegateConn);
48     }
49
50     public void testExecuteQueryReturnsNull() throws Exception JavaDoc {
51         delegateStmt = new TesterPreparedStatement(delegateConn,"null");
52         stmt = new DelegatingPreparedStatement(conn,delegateStmt);
53         assertNull(stmt.executeQuery());
54     }
55
56     public void testExecuteQueryReturnsNotNull() throws Exception JavaDoc {
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 JavaDoc {
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