### Question:
RenameCollectionAwareClientRetryPolicy implements IDocumentClientRetryPolicy { @Override public Single<ShouldRetryResult> shouldRetry(Exception e) { return this.retryPolicy.shouldRetry(e).flatMap(shouldRetryResult -> { if (!shouldRetryResult.shouldRetry && !this.hasTriggered) { DocumentClientException clientException = Utils.as(e, DocumentClientException.class); if (this.request == null) { logger.error("onBeforeSendRequest is not invoked, encountered failure due to request being null", e); return Single.just(ShouldRetryResult.error(e)); } if (clientException != null && this.request.getIsNameBased() && Exceptions.isStatusCode(clientException, HttpConstants.StatusCodes.NOTFOUND) && Exceptions.isSubStatusCode(clientException, HttpConstants.SubStatusCodes.READ_SESSION_NOT_AVAILABLE)) { logger.warn("Clear the token for named base request {}", request.getResourceAddress()); this.sessionContainer.clearTokenByCollectionFullName(request.getResourceAddress()); this.hasTriggered = true; String oldCollectionRid = request.requestContext.resolvedCollectionRid; request.forceNameCacheRefresh = true; request.requestContext.resolvedCollectionRid = null; Single<DocumentCollection> collectionObs = this.collectionCache.resolveCollectionAsync(request); return collectionObs.flatMap(collectionInfo -> { if (collectionInfo == null) { logger.warn("Can't recover from session unavailable exception because resolving collection name {} returned null", request.getResourceAddress()); } else if (!StringUtils.isEmpty(oldCollectionRid) && !StringUtils.isEmpty(collectionInfo.getResourceId())) { return Single.just(ShouldRetryResult.retryAfter(Duration.ZERO)); } return Single.just(shouldRetryResult); }).onErrorResumeNext(throwable -> { logger.warn("Can't recover from session unavailable exception because resolving collection name {} failed with {}", request.getResourceAddress(), throwable.getMessage()); if (throwable instanceof Exception) { return Single.just(ShouldRetryResult.error((Exception) throwable)); } return Single.error(throwable); }); } } return Single.just(shouldRetryResult); }); } RenameCollectionAwareClientRetryPolicy(ISessionContainer sessionContainer, RxClientCollectionCache collectionCache, IDocumentClientRetryPolicy retryPolicy); @Override void onBeforeSendRequest(RxDocumentServiceRequest request); @Override Single<ShouldRetryResult> shouldRetry(Exception e);  }### Answer:
@Test(groups = "unit", timeOut = TIMEOUT) public void onBeforeSendRequestNotInvoked() { GlobalEndpointManager endpointManager = Mockito.mock(GlobalEndpointManager.class); Mockito.doReturn(Completable.complete()).when(endpointManager).refreshLocationAsync(Mockito.eq(null), Mockito.eq(false)); IRetryPolicyFactory retryPolicyFactory = new RetryPolicy(endpointManager, ConnectionPolicy.GetDefault()); RxClientCollectionCache rxClientCollectionCache = Mockito.mock(RxClientCollectionCache.class); ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); RenameCollectionAwareClientRetryPolicy renameCollectionAwareClientRetryPolicy = new RenameCollectionAwareClientRetryPolicy(sessionContainer , rxClientCollectionCache , retryPolicyFactory.getRequestPolicy()); Exception exception = ReadTimeoutException.INSTANCE; RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName( OperationType.Create, "/dbs/db/colls/col/docs/docId", ResourceType.Document); dsr.requestContext = Mockito.mock(DocumentServiceRequestContext.class); Single<IRetryPolicy.ShouldRetryResult> shouldRetry = renameCollectionAwareClientRetryPolicy.shouldRetry(exception); validateSuccess(shouldRetry, ShouldRetryValidator.builder() .withException(exception) .shouldRetry(false) .build()); Mockito.verifyZeroInteractions(endpointManager); }