### Question:
GlobalAddressResolver implements IAddressResolver { Completable openAsync(DocumentCollection collection) { Single<CollectionRoutingMap> routingMap = this.routingMapProvider.tryLookupAsync(collection.getId(), null, null); return routingMap.flatMapCompletable(collectionRoutingMap -> { if (collectionRoutingMap == null) { return Completable.complete(); } List<PartitionKeyRangeIdentity> ranges = ((List<PartitionKeyRange>)collectionRoutingMap.getOrderedPartitionKeyRanges()).stream().map(range -> new PartitionKeyRangeIdentity(collection.getResourceId(), range.getId())).collect(Collectors.toList()); List<Completable> tasks = new ArrayList<>(); for (EndpointCache endpointCache : this.addressCacheByEndpoint.values()) { tasks.add(endpointCache.addressCache.openAsync(collection, ranges)); } return Completable.mergeDelayError(tasks); }); } GlobalAddressResolver(
            CompositeHttpClient<ByteBuf, ByteBuf> httpClient,
            GlobalEndpointManager endpointManager,
            Protocol protocol,
            IAuthorizationTokenProvider tokenProvider,
            RxCollectionCache collectionCache,
            RxPartitionKeyRangeCache routingMapProvider,
            UserAgentContainer userAgentContainer,
            GatewayServiceConfigurationReader serviceConfigReader,
            ConnectionPolicy connectionPolicy); @Override Single<AddressInformation[]> resolveAsync(RxDocumentServiceRequest request, boolean forceRefresh); void dispose();  }### Answer:
@Test(groups = "unit") public void openAsync() throws Exception { GlobalAddressResolver globalAddressResolver = new GlobalAddressResolver(httpClient, endpointManager, Protocol.Https, authorizationTokenProvider, collectionCache, routingMapProvider, userAgentContainer, serviceConfigReader, connectionPolicy); Map<URL, GlobalAddressResolver.EndpointCache> addressCacheByEndpoint = Mockito.spy(globalAddressResolver.addressCacheByEndpoint); GlobalAddressResolver.EndpointCache endpointCache = new GlobalAddressResolver.EndpointCache(); GatewayAddressCache gatewayAddressCache = Mockito.mock(GatewayAddressCache.class); AtomicInteger numberOfTaskCompleted = new AtomicInteger(0); endpointCache.addressCache = gatewayAddressCache; globalAddressResolver.addressCacheByEndpoint.clear(); globalAddressResolver.addressCacheByEndpoint.put(urlforRead1, endpointCache); globalAddressResolver.addressCacheByEndpoint.put(urlforRead2, endpointCache); DocumentCollection documentCollection = new DocumentCollection(); documentCollection.setId("TestColl"); documentCollection.setResourceId("IXYFAOHEBPM="); CollectionRoutingMap collectionRoutingMap = Mockito.mock(CollectionRoutingMap.class); PartitionKeyRange range = new PartitionKeyRange("0", PartitionKeyInternalHelper.MinimumInclusiveEffectivePartitionKey, PartitionKeyInternalHelper.MaximumExclusiveEffectivePartitionKey); List<PartitionKeyRange> partitionKeyRanges = new ArrayList<>(); partitionKeyRanges.add(range); Mockito.when(collectionRoutingMap.getOrderedPartitionKeyRanges()).thenReturn(partitionKeyRanges); Single<CollectionRoutingMap> collectionRoutingMapSingle = Single.just(collectionRoutingMap); Mockito.when(routingMapProvider.tryLookupAsync(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(collectionRoutingMapSingle); List<PartitionKeyRangeIdentity> ranges = new ArrayList<>(); for (PartitionKeyRange partitionKeyRange : (List<PartitionKeyRange>) collectionRoutingMap.getOrderedPartitionKeyRanges()) { PartitionKeyRangeIdentity partitionKeyRangeIdentity = new PartitionKeyRangeIdentity(documentCollection.getResourceId(), partitionKeyRange.getId()); ranges.add(partitionKeyRangeIdentity); } Completable completable = Completable.fromAction(new Action0() { @Override public void call() { numberOfTaskCompleted.getAndIncrement(); } }); Mockito.when(gatewayAddressCache.openAsync(documentCollection, ranges)).thenReturn(completable); globalAddressResolver.openAsync(documentCollection).await(); assertThat(numberOfTaskCompleted.get()).isEqualTo(2); }