use of org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.VCARD_PRIMARY_PREF in project data-transfer-project by google.
the class VCardToGoogleContactConverterTest method testConversionToGooglePhones.
@Test
public void testConversionToGooglePhones() {
// Set up test: vCard with 2 primary phone numbers and 1 secondary phone number
String primaryValue1 = "334-844-4244";
String primaryValue2 = "411";
String secondaryValue = "(555) 867-5309";
Telephone primaryTelephone1 = new Telephone(primaryValue1);
primaryTelephone1.setPref(VCARD_PRIMARY_PREF);
Telephone primaryTelephone2 = new Telephone(primaryValue2);
primaryTelephone2.setPref(VCARD_PRIMARY_PREF);
Telephone secondaryTelephone = new Telephone(secondaryValue);
secondaryTelephone.setPref(VCARD_PRIMARY_PREF + 1);
// Add numbers to vCard. Order shouldn't matter.
VCard vCard = defaultVCard;
vCard.addTelephoneNumber(secondaryTelephone);
vCard.addTelephoneNumber(primaryTelephone1);
vCard.addTelephoneNumber(primaryTelephone2);
// Run test
Person person = VCardToGoogleContactConverter.convert(vCard);
// Check results
// Correct number of phone numbers
assertThat(person.getPhoneNumbers().size()).isEqualTo(3);
// Check primary phone numbers
List<PhoneNumber> actualPrimaryNumbers = person.getPhoneNumbers().stream().filter(a -> a.getMetadata().getPrimary()).collect(Collectors.toList());
List<String> actualPrimaryNumberStrings = getValuesFromFields(actualPrimaryNumbers, PhoneNumber::getValue);
assertThat(actualPrimaryNumberStrings).containsExactly(primaryValue1, primaryValue2);
// Check secondary phone numbers
List<PhoneNumber> actualSecondaryNumbers = person.getPhoneNumbers().stream().filter(a -> !a.getMetadata().getPrimary()).collect(Collectors.toList());
List<String> actualSecondaryNumberStrings = getValuesFromFields(actualSecondaryNumbers, PhoneNumber::getValue);
assertThat(actualSecondaryNumberStrings).containsExactly(secondaryValue);
}
use of org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.VCARD_PRIMARY_PREF in project data-transfer-project by google.
the class VCardToGoogleContactConverterTest method testConversionToGoogleAddresses.
@Test
public void testConversionToGoogleAddresses() {
// Set up vCard with a primary address and a secondary address
String primaryStreet = "221B Baker St";
String primaryLocality = "London";
ezvcard.property.Address primaryAddress = new ezvcard.property.Address();
primaryAddress.setStreetAddress(primaryStreet);
primaryAddress.setLocality(primaryLocality);
primaryAddress.setPref(VCARD_PRIMARY_PREF);
String altStreet = "42 Wallaby Way";
String altLocality = "Sydney";
ezvcard.property.Address altAddress = new ezvcard.property.Address();
altAddress.setStreetAddress(altStreet);
altAddress.setLocality(altLocality);
altAddress.setPref(VCARD_PRIMARY_PREF + 1);
// Add addresses to vCard. Order shouldn't matter.
VCard vCard = defaultVCard;
vCard.addAddress(primaryAddress);
vCard.addAddress(altAddress);
// Run test
Person person = VCardToGoogleContactConverter.convert(vCard);
// Check results
// Check correct number of addresses
assertThat(person.getAddresses().size()).isEqualTo(2);
// Check primary address
List<Address> actualPrimaryAddresses = person.getAddresses().stream().filter(a -> a.getMetadata().getPrimary()).collect(Collectors.toList());
List<String> actualPrimaryAddressStreets = getValuesFromFields(actualPrimaryAddresses, Address::getStreetAddress);
assertThat(actualPrimaryAddressStreets).containsExactly(primaryStreet);
// Check secondary address
List<Address> actualSecondaryAddresses = person.getAddresses().stream().filter(a -> !a.getMetadata().getPrimary()).collect(Collectors.toList());
List<String> actualSecondaryAddressStreets = getValuesFromFields(actualSecondaryAddresses, Address::getStreetAddress);
assertThat(actualSecondaryAddressStreets).containsExactly(altStreet);
}
use of org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.VCARD_PRIMARY_PREF 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