implemented username() method that returns username depending on first and last name (#107)
This commit is contained in:
@@ -45,4 +45,12 @@ public class Name {
|
||||
return StringUtils.join(new String[] { fakeValuesService.fetchString("name.title.descriptor"),
|
||||
fakeValuesService.fetchString("name.title.level"), fakeValuesService.fetchString("name.title.job") }, " ");
|
||||
}
|
||||
|
||||
public String username() {
|
||||
return StringUtils.join(new String[]{
|
||||
firstName().replaceAll("'", "").toLowerCase(),
|
||||
".",
|
||||
lastName().replaceAll("'", "").toLowerCase()}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import static com.github.javafaker.matchers.MatchesRegularExpression.matchesRegularExpression;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.github.javafaker.matchers.MatchesRegularExpression.matchesRegularExpression;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class NameTest {
|
||||
|
||||
private Faker faker;
|
||||
@@ -54,4 +54,9 @@ public class NameTest {
|
||||
public void testTitle() {
|
||||
assertThat(faker.name().title(), matchesRegularExpression("(\\w+\\.?( )?){3}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUsername() {
|
||||
assertThat(faker.name().username(), matchesRegularExpression("^(\\w+)\\.(\\w+)$"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user