Add support for setting an optional last name in profiles.

This commit is contained in:
Alex Hart
2019-12-20 16:12:22 -04:00
committed by Greyson Parrelli
parent f2b9bf0b8c
commit 3907ec8b51
57 changed files with 1641 additions and 1847 deletions

View File

@@ -0,0 +1,164 @@
package org.thoughtcrime.securesms.profiles;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
public final class ProfileNameTest {
@Test
public void givenEmpty_thenIExpectSaneDefaults() {
// GIVEN
ProfileName profileName = ProfileName.EMPTY;
// THEN
assertNotNull("ProfileName should be non-null", profileName);
assertFalse("ProfileName should not be CJKV", profileName.isProfileNameCJKV());
assertEquals("ProfileName should have empty given name", "", profileName.getGivenName());
assertEquals("ProfileName should have empty family name", "", profileName.getFamilyName());
}
@Test
public void givenNullProfileName_whenIFromDataString_thenIExpectSaneDefaults() {
// GIVEN
ProfileName profileName = ProfileName.fromSerialized(null);
// THEN
assertSame(ProfileName.EMPTY, profileName);
}
@Test
public void givenProfileNameWithGivenNameOnly_whenIFromDataString_thenIExpectValidProfileName() {
// GIVEN
String profileName = "Given";
// WHEN
ProfileName name = ProfileName.fromSerialized(profileName);
// THEN
assertNotNull("ProfileName should be non-null", name);
assertFalse("ProfileName should not be CJKV", name.isProfileNameCJKV());
assertEquals("ProfileName should have expected given name", profileName, name.getGivenName());
assertEquals("ProfileName should have empty family name", "", name.getFamilyName());
}
@Test
public void givenProfileNameWithEnglishGivenNameAndEnglishFamilyName_whenIFromDataString_thenIExpectValidProfileName() {
// GIVEN
String profileName = "Given\0Family";
// WHEN
ProfileName name = ProfileName.fromSerialized(profileName);
// THEN
assertNotNull("ProfileName should be non-null", name);
assertFalse("ProfileName should not be CJKV", name.isProfileNameCJKV());
assertEquals("ProfileName should have expected given name", "Given", name.getGivenName());
assertEquals("ProfileName should have expected family name", "Family", name.getFamilyName());
}
@Test
public void givenProfileNameWithEnglishGivenNameAndCJKVFamilyName_whenIFromDataString_thenIExpectNonCJKVProfileName() {
// GIVEN
String profileName = "Given\0码";
// WHEN
ProfileName name = ProfileName.fromSerialized(profileName);
// THEN
assertNotNull("ProfileName should be non-null", name);
assertFalse("ProfileName should not be CJKV", name.isProfileNameCJKV());
assertEquals("ProfileName should have expected given name", "Given", name.getGivenName());
assertEquals("ProfileName should have expected family name", "", name.getFamilyName());
}
@Test
public void givenProfileNameWithCJKVGivenNameAndCJKVFamilyName_whenIFromDataString_thenIExpectNonCJKVProfileName() {
// GIVEN
String profileName = "\0码";
// WHEN
ProfileName name = ProfileName.fromSerialized(profileName);
// THEN
assertNotNull("ProfileName should be non-null", name);
assertTrue("ProfileName should be CJKV", name.isProfileNameCJKV());
assertEquals("ProfileName should have expected given name", "", name.getGivenName());
assertEquals("ProfileName should have expected family name", "", name.getFamilyName());
}
@Test
public void givenProfileNameWithCJKVGivenNameAndEnglishFamilyName_whenIFromDataString_thenIExpectNonCJKVProfileName() {
// GIVEN
String profileName = "\0Family";
// WHEN
ProfileName name = ProfileName.fromSerialized(profileName);
// THEN
assertNotNull("ProfileName should be non-null", name);
assertFalse("ProfileName should not be CJKV", name.isProfileNameCJKV());
assertEquals("ProfileName should have expected given name", "", name.getGivenName());
assertEquals("ProfileName should have expected family name", "Family", name.getFamilyName());
}
@Test
public void givenProfileNameWithEmptyInputs_whenIToDataString_thenIExpectAnEmptyString() {
// GIVEN
ProfileName name = ProfileName.fromParts("", "");
// WHEN
String data = name.serialize();
// THEN
assertEquals("Blank String should be returned (For back compat)", "", data);
}
@Test
public void givenProfileNameWithEmptyGivenName_whenIToDataString_thenIExpectAnEmptyString() {
// GIVEN
ProfileName name = ProfileName.fromParts("", "Family");
// WHEN
String data = name.serialize();
// THEN
assertEquals("Blank String should be returned (For back compat)", "", data);
}
@Test
public void givenProfileNameWithGivenName_whenIToDataString_thenIExpectValidProfileName() {
// GIVEN
ProfileName name = ProfileName.fromParts("Given", "");
// WHEN
String data = name.serialize();
// THEN
assertEquals(data, "Given\0");
}
@Test
public void givenProfileNameWithGivenNameAndFamilyName_whenIToDataString_thenIExpectValidProfileName() {
// GIVEN
ProfileName name = ProfileName.fromParts("Given", "Family");
// WHEN
String data = name.serialize();
// THEN
assertEquals(data, "Given\0Family");
}
@Test
public void fromParts_with_long_name_parts() {
ProfileName name = ProfileName.fromParts("GivenSomeVeryLongNameSomeVeryLongName", "FamilySomeVeryLongNameSomeVeryLongName");
assertEquals("GivenSomeVeryLongNameSomeV", name.getGivenName());
assertEquals("FamilySomeVeryLongNameSome", name.getFamilyName());
}
}