Search in sources :

Example 6 with EmailAddress

use of com.google.api.services.people.v1.model.EmailAddress in project data-transfer-project by google.

the class VCardToGoogleContactConverterTest method testConversionToGoogleEmails.

@Test
public void testConversionToGoogleEmails() {
    // Set up test: person with 1 primary email and 2 secondary emails
    String primaryString = "primary@email.com";
    String secondaryString1 = "secondary1@email.com";
    String secondaryString2 = "secondary2@email.com";
    Email primaryEmail = new Email(primaryString);
    primaryEmail.setPref(VCARD_PRIMARY_PREF);
    Email secondaryEmail1 = new Email(secondaryString1);
    secondaryEmail1.setPref(VCARD_PRIMARY_PREF + 1);
    Email secondaryEmail2 = new Email(secondaryString2);
    secondaryEmail2.setPref(VCARD_PRIMARY_PREF + 1);
    // Add emails to vCard.  Order shouldn't matter.
    VCard vCard = defaultVCard;
    vCard.addEmail(secondaryEmail1);
    vCard.addEmail(primaryEmail);
    vCard.addEmail(secondaryEmail2);
    // Run test
    Person person = VCardToGoogleContactConverter.convert(vCard);
    // Check results
    // Correct number of emails
    assertThat(person.getEmailAddresses().size()).isEqualTo(3);
    // Check primary email addresses
    List<EmailAddress> actualPrimaryEmails = person.getEmailAddresses().stream().filter(a -> a.getMetadata().getPrimary()).collect(Collectors.toList());
    List<String> actualPrimaryEmailsStrings = getValuesFromFields(actualPrimaryEmails, EmailAddress::getValue);
    assertThat(actualPrimaryEmailsStrings).containsExactly(primaryString);
    // Check secondary email addresses
    List<EmailAddress> actualSecondaryEmails = person.getEmailAddresses().stream().filter(a -> !a.getMetadata().getPrimary()).collect(Collectors.toList());
    List<String> actualSecondaryEmailsStrings = getValuesFromFields(actualSecondaryEmails, EmailAddress::getValue);
    assertThat(actualSecondaryEmailsStrings).containsExactly(secondaryString1, secondaryString2);
}
Also used : VCard(ezvcard.VCard) VCARD_PRIMARY_PREF(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.VCARD_PRIMARY_PREF) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) Telephone(ezvcard.property.Telephone) SOURCE_PARAM_NAME_TYPE(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.SOURCE_PARAM_NAME_TYPE) Test(org.junit.Test) PhoneNumber(com.google.api.services.people.v1.model.PhoneNumber) Truth.assertThat(com.google.common.truth.Truth.assertThat) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) StructuredName(ezvcard.property.StructuredName) Pair(com.google.gdata.util.common.base.Pair) Person(com.google.api.services.people.v1.model.Person) List(java.util.List) CONTACT_SOURCE_TYPE(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.CONTACT_SOURCE_TYPE) Nullable(com.google.gdata.util.common.base.Nullable) Address(com.google.api.services.people.v1.model.Address) Email(ezvcard.property.Email) Name(com.google.api.services.people.v1.model.Name) Collections(java.util.Collections) Before(org.junit.Before) Email(ezvcard.property.Email) VCard(ezvcard.VCard) Person(com.google.api.services.people.v1.model.Person) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) Test(org.junit.Test)

Aggregations

EmailAddress (com.google.api.services.people.v1.model.EmailAddress)6 Person (com.google.api.services.people.v1.model.Person)4 VCard (ezvcard.VCard)4 Email (ezvcard.property.Email)4 Test (org.junit.Test)4 Address (com.google.api.services.people.v1.model.Address)2 Name (com.google.api.services.people.v1.model.Name)2 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 Nullable (com.google.gdata.util.common.base.Nullable)2 Pair (com.google.gdata.util.common.base.Pair)2 StructuredName (ezvcard.property.StructuredName)2 Telephone (ezvcard.property.Telephone)2 Collections (java.util.Collections)2 List (java.util.List)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Before (org.junit.Before)2 CONTACT_SOURCE_TYPE (org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.CONTACT_SOURCE_TYPE)1 SOURCE_PARAM_NAME_TYPE (org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.SOURCE_PARAM_NAME_TYPE)1