@Test(groups = "unit", dataProvider = "exceptionArgProvider")
public void exception(Exception ex, Class<Exception> klass, int expectedStatusCode, Integer expectedSubStatusCode) {

    TransportClientWrapper transportClientWrapper = new TransportClientWrapper.Builder.ReplicaResponseBuilder
            .SequentialBuilder()
            .then(ex)
            .build();
    Uri primaryUri = Uri.create("primary");
    Uri secondaryUri1 = Uri.create("secondary1");
    Uri secondaryUri2 = Uri.create("secondary2");
    Uri secondaryUri3 = Uri.create("secondary3");
    AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create()
            .withPrimary(primaryUri)
            .withSecondary(ImmutableList.of(secondaryUri1, secondaryUri2, secondaryUri3))
            .build();
    sessionContainer = Mockito.mock(ISessionContainer.class);
    IAuthorizationTokenProvider authorizationTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class);
    serviceConfigReader = Mockito.mock(GatewayServiceConfigurationReader.class);
    consistencyWriter = new ConsistencyWriter(
            addressSelectorWrapper.addressSelector,
            sessionContainer,
            transportClientWrapper.transportClient,
            authorizationTokenProvider,
            serviceConfigReader,
            false);
    TimeoutHelper timeoutHelper = Mockito.mock(TimeoutHelper.class);
    RxDocumentServiceRequest dsr = Mockito.mock(RxDocumentServiceRequest.class);
    dsr.requestContext = Mockito.mock(DocumentServiceRequestContext.class);
    Single<StoreResponse> res = consistencyWriter.writeAsync(dsr, timeoutHelper, false);
    FailureValidator failureValidator = FailureValidator.builder()
            .instanceOf(klass)
            .statusCode(expectedStatusCode)
            .subStatusCode(expectedSubStatusCode)
            .build();
    TestSubscriber<StoreResponse> subscriber = new TestSubscriber<>();
    res.subscribe(subscriber);
    subscriber.awaitTerminalEvent();
    subscriber.assertNotCompleted();
    assertThat(subscriber.getOnErrorEvents()).hasSize(1);
    failureValidator.validate(subscriber.getOnErrorEvents().get(0));
}