import org.apache.commons.lang3.StringUtils;
import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
import org.mxchange.jcoreutils.comparable.ComparableUtils;
+import org.mxchange.jcoreutils.dates.DateUtils;
import org.mxchange.jcoreutils.number.SafeNumberUtils;
import org.mxchange.jcountry.model.data.Country;
import org.mxchange.jcountry.model.data.CountryData;
* Default constructor
*/
public UserContact () {
- // Default is not user's own contact
- this.contactOwnContact = Boolean.FALSE;
}
/**
* @param contactFirstName First name
* @param contactFamilyName Family name
* @param contactCountry Country instance
+ * @param isOwnContact Whether this is own contact
*/
- public UserContact (final PersonalTitle contactPersonalTitle, final String contactFirstName, final String contactFamilyName, final Country contactCountry) {
+ public UserContact (final PersonalTitle contactPersonalTitle, final String contactFirstName, final String contactFamilyName, final Country contactCountry, final Boolean isOwnContact) {
// Invoke default constructor
this();
} else if (contactCountry.getCountryId() < 1) {
// Throw IAE
throw new IllegalArgumentException(MessageFormat.format("contactCountry.countryId={0} is not valid", contactCountry.getCountryId())); //NOI18N
+ } else if (null == isOwnContact) {
+ // Throw NPE
+ throw new NullPointerException("isOwnContact is null"); // NOI18N
}
// Set all
this.contactFirstName = contactFirstName;
this.contactFamilyName = contactFamilyName;
this.contactCountry = contactCountry;
+ this.contactOwnContact = isOwnContact;
+ }
+
+ /**
+ * Constructor with all fields, except created/updated and primary key
+ * <p>
+ * @param personalTitle Personal title (Mr./Mrs.)
+ * @param firstName First name
+ * @param familyName Family name
+ * @param country Country (e.g. current)
+ * @param street Street name
+ * @param houseNumber House number
+ * @param houseNumberExtension Extension to house number (e.g. a in 12a)
+ * @param zipCode ZIP code
+ * @param city City
+ * @param emailAddress email address
+ * @param academicTitle Academic title
+ * @param birthday Birthday
+ * @param comment Comment
+ * @param isOwnContact Whether this is own contact
+ * <p>
+ * @todo Find a way to stop 0000-00-00 as birthdays to be entered
+ */
+ public UserContact (final PersonalTitle personalTitle, final String firstName, final String familyName, final Country country, final String street, final Short houseNumber, final String houseNumberExtension, final Integer zipCode, final String city, final String emailAddress, final String academicTitle, final Date birthday, final String comment, final Boolean isOwnContact) {
+ // Call other constructor first
+ this(personalTitle, firstName, familyName, country, isOwnContact);
+
+ // Validate parameter
+ if (street != null && street.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("street is empty"); // NOI18N
+ } else if (houseNumber != null && houseNumber < 0) {
+ // No zero house numbers exist
+ throw new IllegalArgumentException(MessageFormat.format("houseNumber={0} is not valid", houseNumber)); // NOI18N
+ } else if (houseNumberExtension != null && houseNumberExtension.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("houseNumberExtension is empty"); // NOI18N
+ } else if (zipCode != null && zipCode < 0) {
+ // No zero house numbers exist
+ throw new IllegalArgumentException(MessageFormat.format("zipCode={0} is not valid", zipCode)); // NOI18N
+ } else if (city != null && city.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("city is empty"); // NOI18N
+ } else if (emailAddress != null && emailAddress.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("emailAddress is empty"); // NOI18N
+ } else if (academicTitle != null && academicTitle.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("academicTitle is empty"); // NOI18N
+ } else if (comment != null && comment.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("comment is empty"); // NOI18N
+ }
+
+ // Set all fields
+ this.contactStreet = street;
+ this.contactHouseNumber = houseNumber;
+ this.contactHouseNumberExtension = houseNumberExtension;
+ this.contactZipCode = zipCode;
+ this.contactCity = city;
+ this.contactEmailAddress = emailAddress;
+ this.contactTitle = academicTitle;
+ this.contactBirthday = birthday;
+ this.contactComment = comment;
}
@Override
this.getContactPersonalTitle().compareTo(contact.getContactPersonalTitle()),
// ... academical title
StringUtils.compareIgnoreCase(this.getContactTitle(), contact.getContactTitle()),
- // .. family name is next ...
+ // .. family name ...
StringUtils.compareIgnoreCase(this.getContactFamilyName(), contact.getContactFamilyName()),
- // .. first name is second ...
+ // .. next is first...
StringUtils.compareIgnoreCase(this.getContactFirstName(), contact.getContactFirstName()),
// ... next is email address
- StringUtils.compareIgnoreCase(this.getContactEmailAddress(), contact.getContactEmailAddress()),};
+ StringUtils.compareIgnoreCase(this.getContactEmailAddress(), contact.getContactEmailAddress()),
+ // ... next birthday - year
+ DateUtils.compareYearMonthDay(this.getContactBirthday(), contact.getContactBirthday()),
+ // ... next "is own" flag
+ Boolean.compare(this.isOwnContact(), contact.isOwnContact()),
+ // ... next comment
+ StringUtils.compare(this.getContactComment(), contact.getContactComment())
+ };
// Check all values
final int comparison = ComparableUtils.checkAll(comparators);
--- /dev/null
+/*
+ * Copyright (C) 2022 Roland Häder<roland@mxchange.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontacts.model.utils;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Objects;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jcontacts.model.contact.UserContact;
+import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
+import org.mxchange.jcountry.model.data.Country;
+import org.mxchange.jcountry.model.data.CountryData;
+import org.testng.Assert;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ * Test cases for ContactUtils class
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class ContactUtilsTest {
+
+ private static final Country CONTACT_COUNTRY1 = new CountryData(
+ "+", //NOI18N
+ "DE", //NOI18N
+ "0", //NOI18N
+ "COUNTRY_GERMANY", //NOI18N
+ Boolean.FALSE,
+ Short.valueOf("49") //NOI18N
+ );
+
+ private static final Country CONTACT_COUNTRY2 = new CountryData(
+ "+", //NOI18N
+ "US", //NOI18N
+ "0", //NOI18N
+ "COUNTRY_USA", //NOI18N
+ Boolean.FALSE,
+ Short.valueOf("1") //NOI18N
+ );
+
+ private static final String CONTACT_FIRST_NAME1 = "Bob"; //NOI18N
+
+ private static final String CONTACT_FIRST_NAME2 = "Alice"; //NOI18N
+
+ private static final Short CONTACT_HOUSE_NUMBER1 = 123;
+
+ private static final Short CONTACT_HOUSE_NUMBER2 = 456;
+
+ private static final String CONTACT_LAST_NAME1 = "Johnson"; //NOI18N
+
+ private static final String CONTACT_LAST_NAME2 = "Andrews";
+
+ private static final String CONTACT_STREET_NAME1 = "Park Street"; //NOI18N
+
+ private static final String CONTACT_STREET_NAME2 = "Sunshine Strip"; //NOI18N
+
+ static {
+ // Fake ids
+ CONTACT_COUNTRY1.setCountryId(1l);
+ CONTACT_COUNTRY2.setCountryId(2l);
+ }
+
+ /**
+ * Default constructor
+ */
+ public ContactUtilsTest () {
+ }
+
+ @DataProvider (name = "different-contact-provider")
+ public Object[][] createDifferentContacts () {
+ // Different date objects
+ final Date date = new Date();
+ final Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ calendar.add(Calendar.MONTH, 1);
+
+ return new Object[][]{
+ // Different personal title
+ {new UserContact(
+ PersonalTitle.MRS,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ Boolean.FALSE
+ )
+ // Different first name
+ }, {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME2,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ Boolean.FALSE
+ )
+ // Different family name
+ }, {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MRS,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME2,
+ CONTACT_COUNTRY1,
+ Boolean.FALSE
+ )
+ // Different country
+ }, {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY2,
+ Boolean.FALSE
+ )
+ // Different "is own" flag
+ }, {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ Boolean.TRUE
+ )
+ // All optional fields (except fax, land-line and mobile number) versus required fields only filled out
+ }, {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ Boolean.FALSE
+ )
+ // Different street
+ }, {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME2, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ )
+ // Different house number
+ }, {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER2,
+ "a", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ )
+ // Different house number extension (both set)
+ }, {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "b", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ )
+ // Different house number extension (left null)
+ }, {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ null, //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "b", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ )
+ // Different house number extension (right null)
+ }, {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ null, //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ )
+ // Different ZIP code
+ }, {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 67890,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ )
+ // Different city
+ }, {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 12345,
+ "New York", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ )
+ // Different email address
+ }, {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@company.com", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ )
+ // Different accdemical title
+ }, {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "PHD", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ )
+ // Different birthday
+ }, {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ calendar.getTime(),
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ )
+ // Different comment
+ }, {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr.", //NOI18N
+ date,
+ "A tester user", //NOI18N
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ CONTACT_STREET_NAME1, //NOI18N
+ CONTACT_HOUSE_NUMBER1,
+ "a", //NOI18N
+ 12345,
+ "Chicago", //NOI18N
+ "bob@example.org", //NOI18N
+ "Dr,", //NOI18N
+ date,
+ "A testing user", //NOI18N
+ Boolean.FALSE
+ )
+ }};
+ }
+
+ @DataProvider (name = "left-null-contact-provider")
+ public Object[][] createLeftNullContacts () {
+ return new Object[][]{
+ {null, new UserContact()},
+ {null, new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ Boolean.FALSE
+ )
+ }};
+ }
+
+ @DataProvider (name = "right-null-contact-provider")
+ public Object[][] createRightNullContacts () {
+ return new Object[][]{
+ {new UserContact(), null},
+ {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ Boolean.FALSE
+ ), null
+ }};
+ }
+
+ @DataProvider (name = "same-contact-provider")
+ public Object[][] createSameContacts () {
+ return new Object[][]{
+ {new UserContact(), new UserContact()},
+ {new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ Boolean.FALSE
+ ), new UserContact(
+ PersonalTitle.MR,
+ CONTACT_FIRST_NAME1,
+ CONTACT_LAST_NAME1,
+ CONTACT_COUNTRY1,
+ Boolean.FALSE
+ )
+ }};
+ }
+
+ @Test (description = "Tests if comparing different contacts returns expected value", dataProvider = "different-contact-provider")
+ public void testCompareDifferentContact (final Contact contact1, final Contact contact2) {
+ // Should be never zero
+ Assert.assertTrue(ContactUtils.compare(contact1, contact2) != 0);
+ }
+
+ @Test (description = "Tests if comparing left-null contact returns expected value", dataProvider = "left-null-contact-provider")
+ public void testCompareLeftNullContact (final Contact contact1, final Contact contact2) {
+ // Should be -1
+ Assert.assertEquals(ContactUtils.compare(contact1, contact2), -1);
+ }
+
+ @Test (description = "Tests if comparing right-null contact returns expected value", dataProvider = "right-null-contact-provider")
+ public void testCompareRightNullContact (final Contact contact1, final Contact contact2) {
+ // Should be -1
+ Assert.assertEquals(ContactUtils.compare(contact1, contact2), 1);
+ }
+
+ @Test (description = "Tests if comparing same contacts returns expected value", dataProvider = "same-contact-provider")
+ public void testCompareSameContact (final Contact contact1, final Contact contact2) {
+ // Should be 0
+ Assert.assertEquals(ContactUtils.compare(contact1, contact2), 0);
+ }
+
+ @Test (description = "Tests for an exception being expected when targetContact is null", dataProvider = "different-contact-provider")
+ public void testCopyContactDataDifferentContact (final Contact contact1, final Contact contact2) {
+ // Should cause an NPE
+ ContactUtils.copyContactData(contact1, contact2);
+
+ // Both instances must be equal now
+ Assert.assertTrue(Objects.equals(contact2, contact1));
+ }
+
+ @Test (description = "Tests for an exception being expected when sourceContact is null", dataProvider = "left-null-contact-provider", expectedExceptions = NullPointerException.class)
+ public void testCopyContactDataLeftNull (final Contact contact1, final Contact contact2) {
+ // Should cause an NPE
+ ContactUtils.copyContactData(contact1, contact2);
+
+ // NEVER REACHED!
+ Assert.fail("If sourceContact is null, a NPE should always be thrown"); //NOI18N
+ }
+
+ @Test (description = "Tests for an exception being expected when targetContact is null", dataProvider = "right-null-contact-provider", expectedExceptions = NullPointerException.class)
+ public void testCopyContactDataRightNull (final Contact contact1, final Contact contact2) {
+ // Should cause an NPE
+ ContactUtils.copyContactData(contact1, contact2);
+
+ // NEVER REACHED!
+ Assert.fail("If targetContact is null, a NPE should always be thrown"); //NOI18N
+ }
+
+ @Test (description = "Tests for an exception being expected when targetContact is null", dataProvider = "same-contact-provider", expectedExceptions = IllegalArgumentException.class)
+ public void testCopyContactDataSameContact (final Contact contact1, final Contact contact2) {
+ // Should cause an NPE
+ ContactUtils.copyContactData(contact1, contact2);
+
+ // NEVER REACHED!
+ Assert.fail("If sourceContact and targetContact are the same IAE should always be thrown"); //NOI18N
+ }
+
+ @Test (description = "Tests for false when both contacts are different", dataProvider = "different-contact-provider")
+ public void testIsSameContactDataDifferentContact (final Contact contact1, final Contact contact2) {
+ // Should return false
+ Assert.assertFalse(ContactUtils.isSameContact(contact1, contact2));
+ }
+
+ @Test (description = "Tests for an exception being expected when first Contact is null", dataProvider = "left-null-contact-provider", expectedExceptions = NullPointerException.class)
+ public void testIsSameContactDataLeftNull (final Contact contact1, final Contact contact2) {
+ // Should cause an NPE
+ final boolean isSame = ContactUtils.isSameContact(contact1, contact2);
+
+ // NEVER REACHED!
+ Assert.fail("If first Contact is null, a NPE should always be thrown: isSame=" + isSame); //NOI18N
+ }
+
+ @Test (description = "Tests for an exception being expected when second Contact is null", dataProvider = "right-null-contact-provider", expectedExceptions = NullPointerException.class)
+ public void testIsSameContactDataRightNull (final Contact contact1, final Contact contact2) {
+ // Should cause an NPE
+ final boolean isSame = ContactUtils.isSameContact(contact1, contact2);
+
+ // NEVER REACHED!
+ Assert.fail("If secondContact is null, a NPE should always be thrown: isSame=" + isSame); //NOI18N
+ }
+
+ @Test (description = "Tests for true when both contacts are the same", dataProvider = "same-contact-provider")
+ public void testIsSameContactDataSameContact (final Contact contact1, final Contact contact2) {
+ // Should return true
+ Assert.assertTrue(ContactUtils.isSameContact(contact1, contact2));
+ }
+
+}