FederatedByLocationMethodInvocationHandlerImpl implements FederatedServiceMethodInvocationHandler { public Object invoke(FederatedServiceCollection collection, Method method, Object[] args) throws ServiceAreaServiceException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { double lat = arg(args, _latArgumentIndex); double lon = arg(args, _lonArgumentIndex); FederatedService service = collection.getServiceForLocation(lat, lon); return method.invoke(service, args); } FederatedByLocationMethodInvocationHandlerImpl(int latArgumentIndex, int lonArgumentIndex); int getLatArgumentIndex(); int getLonArgumentIndex(); Object invoke(FederatedServiceCollection collection, Method method, Object[] args);  }
@Test public void testSimple() throws Exception { SimpleFederatedService mockService = Mockito.mock(SimpleFederatedService.class); FederatedServiceCollection mockCollection = Mockito.mock(FederatedServiceCollectionImpl.class); Mockito.when(mockCollection.getServiceForLocation(0.0,1.0)).thenReturn(mockService); Method method = SimpleFederatedService.class.getDeclaredMethod("getValueForLocation", Double.TYPE,Double.TYPE); Object[] args = {0.0,1.0}; FederatedServiceMethodInvocationHandler handler = new FederatedByLocationMethodInvocationHandlerImpl(0,1); handler.invoke(mockCollection, method, args); Mockito.verify(mockService).getValueForLocation(0.0,1.0); }