JdbcWrapper { Context createContextProxy(final Context context) { assert context != null; final InvocationHandler invocationHandler = new AbstractInvocationHandler<Context>( context) { private static final long serialVersionUID = 1L; @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object result = method.invoke(context, args); if (result instanceof DataSource) { result = createDataSourceProxy((DataSource) result); } return result; } }; return createProxy(context, invocationHandler); } private  JdbcWrapper(Counter sqlCounter); static int getUsedConnectionCount(); static int getActiveConnectionCount(); static long getTransactionCount(); static int getActiveThreadCount(); static int getRunningBuildCount(); static int getBuildQueueLength(); static long getBuildQueueWaitingDurationsSum(); static List<ConnectionInformations> getConnectionInformationsList(); Counter getSqlCounter(); static int getMaxConnectionCount(); static Map<String, Map<String, Object>> getBasicDataSourceProperties(); static Map<String, DataSource> getJndiAndSpringDataSources(); static void registerSpringDataSource(String name, DataSource dataSource); DataSource createDataSourceProxy(DataSource dataSource); DataSource createDataSourceProxy(String name, final DataSource dataSource); Connection createConnectionProxy(Connection connection); static final JdbcWrapper SINGLETON; }
@Test public void testCreateContextProxy() throws NamingException { final Context context = jdbcWrapper.createContextProxy(new InitialContext()); assertNotNull("createContextProxy", context); context.close(); final Context mockContext = createNiceMock(Context.class); final Context proxyContext = JdbcWrapper.SINGLETON.createContextProxy(mockContext); final DataSource dataSource = createNiceMock(DataSource.class); final String jndiName = "java:comp/env/jdbc/DataSource"; expect(mockContext.lookup(jndiName)).andReturn(dataSource).anyTimes(); replay(mockContext); proxyContext.lookup(jndiName); verify(mockContext); }