Remove whitespaces from usernames (#296) (#297)

* Remove whitespaces from usernames (#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...
This commit is contained in:
Jose
2018-08-07 01:01:08 +01:00
committed by Ricky Yim
parent 84efab1290
commit d7409c8375
2 changed files with 16 additions and 1 deletions
+4 -1
View File
@@ -120,10 +120,13 @@ public class Name {
* @see Name#lastName()
*/
public String username() {
return StringUtils.join(new String[]{
String username = StringUtils.join(new String[]{
firstName().replaceAll("'", "").toLowerCase(),
".",
lastName().replaceAll("'", "").toLowerCase()}
);
return StringUtils.deleteWhitespace(username);
}
}
@@ -4,6 +4,9 @@ import org.junit.Test;
import static com.github.javafaker.matchers.MatchesRegularExpression.matchesRegularExpression;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
public class NameTest extends AbstractFakerTest{
@@ -51,4 +54,13 @@ public class NameTest extends AbstractFakerTest{
public void testUsername() {
assertThat(faker.name().username(), matchesRegularExpression("^(\\w+)\\.(\\w+)$"));
}
@Test
public void testUsernameWithSpaces() {
final Name name = spy(new Name(faker));
doReturn("Compound Name").when(name).firstName();
doReturn(name).when(faker).name();
assertThat(faker.name().username(), matchesRegularExpression("^(\\w+)\\.(\\w+)$"));
}
}