1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.dbutils;
18  
19  import java.lang.reflect.InvocationHandler;
20  import java.lang.reflect.Method;
21  import java.sql.CallableStatement;
22  import java.sql.Connection;
23  import java.sql.Driver;
24  import java.sql.PreparedStatement;
25  import java.sql.ResultSet;
26  import java.sql.ResultSetMetaData;
27  import java.sql.Statement;
28  
29  /**
30   * ProxyFactoryTest performs simple type checking on proxy objects returned
31   * from a ProxyFactory.
32   */
33  public class ProxyFactoryTest extends BaseTestCase {
34  
35  	private static final InvocationHandler stub = new InvocationHandler() {
36  
37  		public Object invoke(Object proxy, Method method, Object[] args)
38  			throws Throwable {
39  
40  			return null;
41  		}
42  	};
43  
44  	/**
45  	 * Constructor for ProxyFactoryTest.
46  	 */
47  	public ProxyFactoryTest(String name) {
48  		super(name);
49  	}
50  
51  	public void testCreateConnection() {
52  		assertTrue(
53  			ProxyFactory.instance().createConnection(stub)
54  				instanceof Connection);
55  	}
56  
57  	public void testCreateDriver() {
58  		assertTrue(
59  			ProxyFactory.instance().createDriver(stub) instanceof Driver);
60  	}
61  
62  	public void testCreatePreparedStatement() {
63  		assertTrue(
64  			ProxyFactory.instance().createPreparedStatement(stub)
65  				instanceof PreparedStatement);
66  	}
67  
68  	public void testCreateResultSet() {
69  		assertTrue(
70  			ProxyFactory.instance().createResultSet(stub) instanceof ResultSet);
71  	}
72  
73  	public void testCreateResultSetMetaData() {
74  		assertTrue(
75  			ProxyFactory.instance().createResultSetMetaData(stub)
76  				instanceof ResultSetMetaData);
77  	}
78  
79  	public void testCreateStatement() {
80  		assertTrue(
81  			ProxyFactory.instance().createStatement(stub) instanceof Statement);
82  	}
83  
84  	public void testCreateCallableStatement() {
85  		assertTrue(
86  			ProxyFactory.instance().createCallableStatement(stub)
87  				instanceof CallableStatement);
88  	}
89  
90  }