use of org.apache.aries.unittest.mocks.MethodCallHandler in project aries by apache.
the class ServiceRegistryContextTest method registerProxyManager.
private void registerProxyManager() {
ProxyManager mgr = Skeleton.newMock(ProxyManager.class);
// public Object createDelegatingProxy(Bundle clientBundle, Collection<Class<?>> classes, Callable<Object> dispatcher, Object template) throws UnableToProxyException;
Skeleton.getSkeleton(mgr).registerMethodCallHandler(new MethodCall(ProxyManager.class, "createDelegatingProxy", Bundle.class, Collection.class, Callable.class, Object.class), new MethodCallHandler() {
public Object handle(MethodCall methodCall, Skeleton skeleton) throws Exception {
@SuppressWarnings("unchecked") Collection<Class<?>> interfaceClasses = (Collection<Class<?>>) methodCall.getArguments()[1];
Class<?>[] classes = new Class<?>[interfaceClasses.size()];
Iterator<Class<?>> it = interfaceClasses.iterator();
for (int i = 0; it.hasNext(); i++) {
classes[i] = it.next();
}
@SuppressWarnings("unchecked") final Callable<Object> target = (Callable<Object>) methodCall.getArguments()[2];
return Proxy.newProxyInstance(this.getClass().getClassLoader(), classes, new InvocationHandler() {
public Object invoke(Object mock, Method method, Object[] arguments) throws Throwable {
return method.invoke(target.call(), arguments);
}
});
}
});
bc.registerService(ProxyManager.class.getName(), mgr, null);
}
Aggregations