Proxies { @SuppressWarnings("unchecked") static <T> T newProxyInstance(T o, InvocationHandler h) { checkNotNull(o); checkNotNull(h); return (T) Proxy.newProxyInstance(o.getClass().getClassLoader(), Proxies.getInterfaces(o), h); } private  Proxies();   }
@Test public void newProxyInstance() throws Exception { InvocationHandler mockInvocationHandler = new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { assertThat(method.getName()).isEqualTo("vendorSpecificMethod"); return method.invoke(mockStatement, args); } }; Object proxy = Proxies.newProxyInstance(mockStatement, mockInvocationHandler); assertThat(proxy instanceof VendorSpecificPreparedStatement).isTrue(); ((VendorSpecificPreparedStatement) proxy).vendorSpecificMethod(); verify(mockStatement).vendorSpecificMethod(); }