Skip to content

Commit d7409c8

Browse files
jrodaloRicky Yim
authored andcommitted
Remove whitespaces from usernames (DiUS#296) (DiUS#297)
* Remove whitespaces from usernames (DiUS#296) Some languages include compound names (spanish and portugese for example) and that breaks usernames validation * Remove noise from my previous commit Accidentally cleaned the entire file...
1 parent 84efab1 commit d7409c8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/main/java/com/github/javafaker/Name.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,13 @@ public String title() {
120120
* @see Name#lastName()
121121
*/
122122
public String username() {
123-
return StringUtils.join(new String[]{
123+
124+
String username = StringUtils.join(new String[]{
124125
firstName().replaceAll("'", "").toLowerCase(),
125126
".",
126127
lastName().replaceAll("'", "").toLowerCase()}
127128
);
129+
130+
return StringUtils.deleteWhitespace(username);
128131
}
129132
}

src/test/java/com/github/javafaker/NameTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import static com.github.javafaker.matchers.MatchesRegularExpression.matchesRegularExpression;
66
import static org.junit.Assert.assertThat;
7+
import static org.mockito.Mockito.doReturn;
8+
import static org.mockito.Mockito.spy;
9+
710

811
public class NameTest extends AbstractFakerTest{
912

@@ -51,4 +54,13 @@ public void testTitle() {
5154
public void testUsername() {
5255
assertThat(faker.name().username(), matchesRegularExpression("^(\\w+)\\.(\\w+)$"));
5356
}
57+
58+
@Test
59+
public void testUsernameWithSpaces() {
60+
final Name name = spy(new Name(faker));
61+
doReturn("Compound Name").when(name).firstName();
62+
doReturn(name).when(faker).name();
63+
assertThat(faker.name().username(), matchesRegularExpression("^(\\w+)\\.(\\w+)$"));
64+
}
65+
5466
}

0 commit comments

Comments
 (0)