private String createNewContact()
      throws HubSpotConnectorException, HubSpotConnectorNoAccessTokenException,
          HubSpotConnectorAccessTokenExpiredException {
    final ContactProperties cp = new ContactProperties();
    final long date = new Date().getTime();
    final String email = String.format("*****@*****.**", date);

    cp.setEmail(email);
    cp.setFirstname("theFirstName");
    cp.setLastname("theLastName");
    cp.setNumemployees(ContactPropertiesNumberOfEmployees._25_50);
    cp.setLifecyclestage(ContactPropertiesLifecycleStage.LEAD);
    cp.setCity("beautifulCity");

    final Contact c = connector.createContact(USER_ID, cp);
    c.toString();

    return email;
  }
  @Test
  public void addAndRemoveContactFromLists()
      throws HubSpotConnectorException, HubSpotConnectorNoAccessTokenException,
          HubSpotConnectorAccessTokenExpiredException {
    // Create a new contact
    final String email = createNewContact();

    // Retrieve the contact by email and check that all the properties setted are stablished
    final Contact c = connector.getContactByEmail(USER_ID, email);
    Assert.assertNotNull(c);

    // Retrieve all the email lists and use one that is not dynamic
    final HubSpotListLists hsll = connector.getContactsLists(USER_ID, null, null);
    Assert.assertNotNull(hsll);

    for (final HubSpotList hbl : hsll.getLists()) {
      // It must be a non dynamic list
      if (!hbl.getDynamic()) {
        final String listId = hbl.getListId();

        final HubSpotListAddContactToListResponse hslactlr =
            connector.addExistingContactInAList(USER_ID, listId, c.getVid());

        Assert.assertNotNull(hslactlr);
        Assert.assertNotNull(hslactlr.getUpdated());
        Assert.assertEquals(1, hslactlr.getUpdated().size());
        Assert.assertEquals(Integer.valueOf(c.getVid()), hslactlr.getUpdated().get(0));

        break;
      }
    }

    // Delete the contact by his ID and check the response
    final ContactDeleted cd = connector.deleteContact(USER_ID, c.getVid());

    Assert.assertNotNull(cd);
    Assert.assertTrue(cd.getDeleted());
    Assert.assertEquals(cd.getVid(), c.getVid());
  }
  /*
   * Test the cut point in iteration for the new iterator. When calling stopIteration the next hasNext should return false regarding what the API says
   */
  @Test
  public void testStopIteration()
      throws HubSpotConnectorException, HubSpotConnectorNoAccessTokenException,
          HubSpotConnectorAccessTokenExpiredException {
    Iterator<Contact> i = connector.getRecentContactsPaginated(USER_ID, "1").iterator();

    int contacts = 0;

    for (int x = 0; x < 2; x++) {
      if (i.hasNext()) {
        i.next();
        contacts++;
      }
    }

    // In order that this test works we need at least two Contacts
    if (contacts < 2) {
      for (int x = contacts; x > 0; x--) {
        createNewContact();
      }
    }

    final Collection<Contact> c = connector.getRecentContactsPaginated(USER_ID, "10");
    i = c.iterator();

    i = Mockito.spy(i); // Mock the iterator

    Contact co;
    while (i.hasNext()) {
      co = i.next();
      System.out.println(co.getVid());
      final PaginatedIterable<?, ?> pi = (PaginatedIterable<?, ?>) c;
      // pi.stopIteration();
    }

    // If the cut point was correct, it must be called only one time
    Mockito.verify(i, Mockito.times(1)).next();
  }
  /*
   * 1. create a new Contact (OP: createContact) 2. retrieve contact by email (OP: getContactByEmail) 3. update the contact (OP: updateContact) 4. retrieve contact by id (OP:
   * getContactById) 5. delete contact by id (OP:
   */
  @Test
  public void createRetrieveDeleteContact()
      throws HubSpotConnectorException, HubSpotConnectorNoAccessTokenException,
          HubSpotConnectorAccessTokenExpiredException {

    // 1. Create a new contact
    ContactProperties cp;

    final String email = createNewContact();

    // 2. Retrieve the contact by email and check that all the properties setted are stablished
    Contact c = connector.getContactByEmail(USER_ID, email);
    Assert.assertNotNull(c);

    cp = c.getContactProperties();
    Assert.assertNotNull(cp);
    Assert.assertFalse(StringUtils.isEmpty(c.getVid()));
    Assert.assertEquals(cp.getFirstname(), "theFirstName");
    Assert.assertEquals(cp.getLastname(), "theLastName");
    Assert.assertEquals(cp.getNumemployees(), ContactPropertiesNumberOfEmployees._25_50);
    Assert.assertEquals(cp.getLifecyclestage(), ContactPropertiesLifecycleStage.LEAD);
    Assert.assertEquals(cp.getCity(), "beautifulCity");

    // 3. Update the lastname of the contact
    cp = new ContactProperties();
    cp.setLastname("lastNameModified");

    connector.updateContact(USER_ID, c.getVid(), cp);

    // 4. Retrieve again the same contact but this time by ID, and check that the lastname holds the
    // modified value
    c = connector.getContactById(USER_ID, c.getVid());

    Assert.assertNotNull(c);

    cp = c.getContactProperties();

    Assert.assertNotNull(cp);
    Assert.assertEquals(cp.getLastname(), "lastNameModified");

    // 5. Delete the contact by his ID and check the response
    final ContactDeleted cd = connector.deleteContact(USER_ID, c.getVid());

    Assert.assertNotNull(cd);
    Assert.assertTrue(cd.getDeleted());
    Assert.assertEquals(cd.getVid(), c.getVid());
  }