MultiMetaServer implements InvocationHandler { public static MetaServer newProxy(MetaServer dstServer, List<MetaServer> otherServers) { return (MetaServer) Proxy.newProxyInstance(MultiMetaServer.class.getClassLoader(), new Class[] { MetaServer.class }, new MultiMetaServer(dstServer, otherServers)); } MultiMetaServer(MetaServer dstServer, List<MetaServer> otherServers);  MultiMetaServer(MetaServer dstServer, List<MetaServer> otherServers, Executor executors); static MetaServer newProxy(MetaServer dstServer, List<MetaServer> otherServers); @Override Object invoke(Object proxy, final Method method, final Object[] rawArgs);  }
@Test public void testMultiProxy(){ int serversCount = 10; List<MetaServer> servers = new LinkedList<>(); for(int i=0; i < serversCount - 1 ; i++){ servers.add(mock(MetaServer.class)); } MetaServer metaServer = MultiMetaServer.newProxy(mock(MetaServer.class), servers); final ForwardInfo forwardInfo = new ForwardInfo(); metaServer.clusterDeleted(getClusterId(), forwardInfo); for(MetaServer mockServer : servers){ verify(mockServer).clusterDeleted(eq(getClusterId()), argThat(new BaseMatcher<ForwardInfo>() { @Override public boolean matches(Object item) { if(item == forwardInfo){ return false; } return true; } @Override public void describeTo(Description description) { } })); } }