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);
}
Aggregations