FederatedByBoundsMethodInvocationHandlerImpl implements FederatedServiceMethodInvocationHandler { public Object invoke(FederatedServiceCollection collection, Method method, Object[] args) throws ServiceAreaServiceException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { double lat1 = arg(args, _lat1ArgumentIndex); double lon1 = arg(args, _lon1ArgumentIndex); double lat2 = arg(args, _lat2ArgumentIndex); double lon2 = arg(args, _lon2ArgumentIndex); FederatedService service = collection.getServiceForBounds(lat1, lon1, lat2, lon2); return method.invoke(service, args); } FederatedByBoundsMethodInvocationHandlerImpl(int lat1ArgumentIndex, int lon1ArgumentIndex,
      int lat2ArgumentIndex, int lon2ArgumentIndex); int getLat1ArgumentIndex(); int getLon1ArgumentIndex(); int getLat2ArgumentIndex(); int getLon2ArgumentIndex(); 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.getServiceForBounds(0.0,1.0,2.0,3.0)).thenReturn(mockService); Method method = SimpleFederatedService.class.getDeclaredMethod("getValueForBounds", Double.TYPE,Double.TYPE,Double.TYPE,Double.TYPE); Object[] args = {0.0,1.0,2.0,3.0}; FederatedServiceMethodInvocationHandler handler = new FederatedByBoundsMethodInvocationHandlerImpl(0,1,2,3); handler.invoke(mockCollection, method, args); Mockito.verify(mockService).getValueForBounds(0.0,1.0,2.0,3.0); }