FederatedByAgencyIdMethodInvocationHandlerImpl implements
    FederatedServiceMethodInvocationHandler { public Object invoke(FederatedServiceCollection collection, Method method, Object[] args) throws ServiceException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { Object value = (Object) args[_argumentIndex]; if (_expression != null) value = _expression.invoke(value); String agencyId = (String) value; FederatedService service = collection.getServiceForAgencyId(agencyId); return method.invoke(service, args); } FederatedByAgencyIdMethodInvocationHandlerImpl(Method method, int argumentIndex, String expression); int getArgumentIndex(); 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.getServiceForAgencyId("agency")).thenReturn( mockService); Method method = SimpleFederatedService.class.getDeclaredMethod( "getValueForId", String.class); Object[] args = {"agency_entity"}; FederatedServiceMethodInvocationHandler handler = new FederatedByEntityIdMethodInvocationHandlerImpl( method, 0, ""); handler.invoke(mockCollection, method, args); Mockito.verify(mockService).getValueForId("agency_entity"); }
@Test public void testArgumentIndex() throws Exception { SimpleFederatedService mockService = Mockito.mock(SimpleFederatedService.class); FederatedServiceCollection mockCollection = Mockito.mock(FederatedServiceCollectionImpl.class); Mockito.when(mockCollection.getServiceForAgencyId("agency")).thenReturn( mockService); Method method = SimpleFederatedService.class.getDeclaredMethod( "getValueForValueAndId", String.class, String.class); Object[] args = {"value", "agency_entity"}; FederatedServiceMethodInvocationHandler handler = new FederatedByEntityIdMethodInvocationHandlerImpl( method, 1, ""); handler.invoke(mockCollection, method, args); Mockito.verify(mockService).getValueForValueAndId("value", "agency_entity"); }
@Test public void testPropertyExpression() throws Exception { SimpleFederatedService mockService = Mockito.mock(SimpleFederatedService.class); FederatedServiceCollection mockCollection = Mockito.mock(FederatedServiceCollectionImpl.class); Mockito.when(mockCollection.getServiceForAgencyId("agency")).thenReturn( mockService); Method method = SimpleFederatedService.class.getDeclaredMethod( "getValueForValueBean", EntityIdTestBean.class); EntityIdTestBean value = new EntityIdTestBean("agency_entity"); Object[] args = {value}; FederatedServiceMethodInvocationHandler handler = new FederatedByEntityIdMethodInvocationHandlerImpl( method, 0, "id"); handler.invoke(mockCollection, method, args); Mockito.verify(mockService).getValueForValueBean(value); }