@Test(expected = ConnectionException.class)
  public void testCreateBatchWithConnectionException() throws Exception {
    SalesforceConnector connector = new SalesforceConnector();
    BulkConnection bulkConnection = Mockito.mock(BulkConnection.class);
    AsyncApiException exception = Mockito.mock(AsyncApiException.class);
    connector.setBulkConnection(bulkConnection);

    JobInfo jobInfo = new JobInfo();
    List<Map<String, Object>> objects = new ArrayList<Map<String, Object>>();

    Mockito.when(exception.getExceptionCode()).thenReturn(AsyncExceptionCode.InvalidSessionId);
    Mockito.when(bulkConnection.createBatch(jobInfo)).thenThrow(exception);
    connector.createBatch(jobInfo, objects);
  }
  @Test(expected = ConnectionException.class)
  public void testCreateBatchForQueryWithConnectionException() throws Exception {
    SalesforceConnector connector = new SalesforceConnector();
    BulkConnection bulkConnection = Mockito.mock(BulkConnection.class);
    ArgumentCaptor<JobInfo> expectedJobInfo = ArgumentCaptor.forClass(JobInfo.class);
    AsyncApiException exception = Mockito.mock(AsyncApiException.class);
    connector.setBulkConnection(bulkConnection);

    JobInfo actualJobInfo = new JobInfo();
    String query = "SELECT Id FROM Contact";

    Mockito.when(exception.getExceptionCode()).thenReturn(AsyncExceptionCode.InvalidSessionId);
    Mockito.when(
            bulkConnection.createBatchFromStream(
                expectedJobInfo.capture(), Mockito.isA(InputStream.class)))
        .thenThrow(exception);
    connector.createBatchForQuery(actualJobInfo, query);
    assertEquals(expectedJobInfo.getValue(), actualJobInfo);
  }