use of com.google.api.services.people.v1.model.EmailAddress in project data-transfer-project by google.
the class GoogleContactToVCardConverterTest method testConversionToVCardEmail.
@Test
public void testConversionToVCardEmail() {
// 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";
EmailAddress primaryEmail = new EmailAddress().setValue(primaryString).setMetadata(PRIMARY_FIELD_METADATA);
EmailAddress secondaryEmail1 = new EmailAddress().setValue(secondaryString1).setMetadata(SECONDARY_FIELD_METADATA);
EmailAddress secondaryEmail2 = new EmailAddress().setValue(secondaryString2).setMetadata(SECONDARY_FIELD_METADATA);
Person person = DEFAULT_PERSON.setEmailAddresses(Arrays.asList(secondaryEmail1, primaryEmail, // Making sure order isn't a factor
secondaryEmail2));
// Run test - NB, this Person only has emails
VCard vCard = GoogleContactToVCardConverter.convert(person);
// Check results for correct values and preferences
List<Email> resultPrimaryEmailList = getPropertiesWithPreference(vCard, Email.class, VCARD_PRIMARY_PREF);
assertThat(getValuesFromTextProperties(resultPrimaryEmailList)).containsExactly(primaryString);
List<Email> resultSecondaryEmailList = getPropertiesWithPreference(vCard, Email.class, VCARD_PRIMARY_PREF + 1);
assertThat(getValuesFromTextProperties(resultSecondaryEmailList)).containsExactly(secondaryString1, secondaryString2);
}
use of com.google.api.services.people.v1.model.EmailAddress in project data-transfer-project by google.
the class GoogleContactsImporter method convertToGoogleEmail.
private static EmailAddress convertToGoogleEmail(Email vCardEmail) {
EmailAddress emailAddress = new EmailAddress();
emailAddress.setValue(vCardEmail.getValue());
if (vCardEmail.getPref() != null && vCardEmail.getPref() == VCARD_PRIMARY_PREF) {
emailAddress.setMetadata(PRIMARY_FIELD_METADATA);
} else {
emailAddress.setMetadata(SECONDARY_FIELD_METADATA);
}
return emailAddress;
}
use of com.google.api.services.people.v1.model.EmailAddress in project data-transfer-project by google.
the class VCardToGoogleContactConverter method convertToGoogleEmail.
private static EmailAddress convertToGoogleEmail(Email vCardEmail) {
EmailAddress emailAddress = new EmailAddress();
emailAddress.setValue(vCardEmail.getValue());
if (vCardEmail.getPref() != null && vCardEmail.getPref() == VCARD_PRIMARY_PREF) {
emailAddress.setMetadata(PRIMARY_FIELD_METADATA);
} else {
emailAddress.setMetadata(SECONDARY_FIELD_METADATA);
}
return emailAddress;
}
use of com.google.api.services.people.v1.model.EmailAddress in project data-transfer-project by google.
the class GoogleContactsExportConversionTest method testConversionToVCardEmail.
@Test
public void testConversionToVCardEmail() {
// 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";
EmailAddress primaryEmail = new EmailAddress().setValue(primaryString).setMetadata(PRIMARY_FIELD_METADATA);
EmailAddress secondaryEmail1 = new EmailAddress().setValue(secondaryString1).setMetadata(SECONDARY_FIELD_METADATA);
EmailAddress secondaryEmail2 = new EmailAddress().setValue(secondaryString2).setMetadata(SECONDARY_FIELD_METADATA);
Person person = DEFAULT_PERSON.setEmailAddresses(Arrays.asList(secondaryEmail1, primaryEmail, // Making sure order isn't a factor
secondaryEmail2));
// Run test - NB, this Person only has emails
VCard vCard = GoogleContactsExporter.convert(person);
// Check results for correct values and preferences
List<Email> resultPrimaryEmailList = getPropertiesWithPreference(vCard, Email.class, VCARD_PRIMARY_PREF);
assertThat(getValuesFromTextProperties(resultPrimaryEmailList)).containsExactly(primaryString);
List<Email> resultSecondaryEmailList = getPropertiesWithPreference(vCard, Email.class, VCARD_PRIMARY_PREF + 1);
assertThat(getValuesFromTextProperties(resultSecondaryEmailList)).containsExactly(secondaryString1, secondaryString2);
}
use of com.google.api.services.people.v1.model.EmailAddress in project data-transfer-project by google.
the class GoogleContactsImportConversionTest 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 = GoogleContactsImporter.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