### Question:
AddressSelector { public static Uri getPrimaryUri(RxDocumentServiceRequest request, List<AddressInformation> replicaAddresses) throws GoneException { AddressInformation primaryAddress = null; if (request.getDefaultReplicaIndex() != null) { int defaultReplicaIndex = request.getDefaultReplicaIndex(); if (defaultReplicaIndex >= 0 && defaultReplicaIndex < replicaAddresses.size()) { primaryAddress = replicaAddresses.get(defaultReplicaIndex); } } else { primaryAddress = replicaAddresses.stream().filter(address -> address.isPrimary() && !address.getPhysicalUri().getURIAsString().contains("[")) .findAny().orElse(null); } if (primaryAddress == null) { throw new GoneException(String.format("The requested resource is no longer available at the server. Returned addresses are {%s}", String.join(",", replicaAddresses.stream().map(address -> address.getPhysicalUri().getURIAsString()).collect(Collectors.toList()))), null); } return primaryAddress.getPhysicalUri(); } AddressSelector(IAddressResolver addressResolver, Protocol protocol); Single<List<Uri>> resolveAllUriAsync(
        RxDocumentServiceRequest request,
        boolean includePrimary,
        boolean forceRefresh); Single<Uri> resolvePrimaryUriAsync(RxDocumentServiceRequest request, boolean forceAddressRefresh); static Uri getPrimaryUri(RxDocumentServiceRequest request, List<AddressInformation> replicaAddresses); Single<List<AddressInformation>> resolveAddressesAsync(RxDocumentServiceRequest request, boolean forceAddressRefresh);  }### Answer:
@Test(groups = "unit", expectedExceptions = GoneException.class) public void getPrimaryUri_NoAddress() throws Exception { RxDocumentServiceRequest request = Mockito.mock(RxDocumentServiceRequest.class); Mockito.doReturn(null).when(request).getDefaultReplicaIndex(); List<AddressInformation> replicaAddresses = new ArrayList<>(); AddressSelector.getPrimaryUri(request, replicaAddresses); }
@Test(groups = "unit", expectedExceptions = GoneException.class, expectedExceptionsMessageRegExp = "The requested resource is no longer available at the server. Returned addresses are \\{https: public void getPrimaryUri_NoPrimaryAddress() throws Exception { RxDocumentServiceRequest request = Mockito.mock(RxDocumentServiceRequest.class); Mockito.doReturn(null).when(request).getDefaultReplicaIndex(); List<AddressInformation> replicaAddresses = new ArrayList<>(); replicaAddresses.add(new AddressInformation(true, false, "https: replicaAddresses.add(new AddressInformation(true, false, "https: AddressSelector.getPrimaryUri(request, replicaAddresses); }
@Test(groups = "unit") public void getPrimaryUri() throws Exception { RxDocumentServiceRequest request = Mockito.mock(RxDocumentServiceRequest.class); Mockito.doReturn(null).when(request).getDefaultReplicaIndex(); List<AddressInformation> replicaAddresses = new ArrayList<>(); replicaAddresses.add(new AddressInformation(true, false, "https: replicaAddresses.add(new AddressInformation(true, true, "https: replicaAddresses.add(new AddressInformation(true, false, "https: Uri res = AddressSelector.getPrimaryUri(request, replicaAddresses); assertThat(res).isEqualTo(Uri.create("https: }
@Test(groups = "unit") public void getPrimaryUri_WithRequestReplicaIndex() throws Exception { RxDocumentServiceRequest request = Mockito.mock(RxDocumentServiceRequest.class); Mockito.doReturn(1).when(request).getDefaultReplicaIndex(); List<AddressInformation> replicaAddresses = new ArrayList<>(); replicaAddresses.add(new AddressInformation(true, false, "https: replicaAddresses.add(new AddressInformation(true, false, "https: replicaAddresses.add(new AddressInformation(true, false, "https: Uri res = AddressSelector.getPrimaryUri(request, replicaAddresses); assertThat(res).isEqualTo(Uri.create("https: }