-
-
Notifications
You must be signed in to change notification settings - Fork 6k
/
ProfileNameTest.java
179 lines (140 loc) · 5.9 KB
/
ProfileNameTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
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_whenIFromSerialized_thenIExpectExactlyEmpty() {
// 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);
assertEquals("Family", name.getFamilyName());
}
@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());
}
@Test
public void givenProfileNameWithGivenNameAndFamilyNameWithSpaces_whenIToDataString_thenIExpectTrimmedProfileName() {
// GIVEN
ProfileName name = ProfileName.fromParts(" Given ", " Family");
// WHEN
String data = name.serialize();
// THEN
assertEquals(data, "Given\0Family");
assertEquals(name.getGivenName(), "Given");
assertEquals(name.getFamilyName(), "Family");
}
}