-
Notifications
You must be signed in to change notification settings - Fork 863
Expand file tree
/
Copy pathNameTest.java
More file actions
96 lines (77 loc) · 2.91 KB
/
NameTest.java
File metadata and controls
96 lines (77 loc) · 2.91 KB
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
package com.github.javafaker;
import com.github.javafaker.repeating.Repeat;
import org.junit.Test;
import static com.github.javafaker.matchers.MatchesRegularExpression.matchesRegularExpression;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
public class NameTest extends AbstractFakerTest{
@Test
public void testName() {
assertThat(faker.name().name(), matchesRegularExpression("([\\w']+\\.?( )?){2,3}"));
}
@Test
public void testNameWithMiddle() {
assertThat(faker.name().nameWithMiddle(), matchesRegularExpression("([\\w']+\\.?( )?){3,4}"));
}
@Test @Repeat(times = 10)
public void testNameWithMiddleDoesNotHaveRepeatedName() {
String nameWithMiddle = faker.name().nameWithMiddle();
String[] splitNames = nameWithMiddle.split(" ");
String firstName = splitNames[0];
String middleName = splitNames[1];
assertThat(firstName, not(equalTo(middleName)));
}
@Test
public void testFullName() {
assertThat(faker.name().fullName(), matchesRegularExpression("([\\w']+\\.?( )?){2,4}"));
}
@Test
public void testFirstName() {
assertThat(faker.name().firstName(), matchesRegularExpression("\\w+"));
}
@Test
public void testLastName() {
assertThat(faker.name().lastName(), matchesRegularExpression("[A-Za-z']+"));
}
@Test
public void testPrefix() {
assertThat(faker.name().prefix(), matchesRegularExpression("\\w+\\.?"));
}
@Test
public void testSuffix() {
assertThat(faker.name().suffix(), matchesRegularExpression("\\w+\\.?"));
}
@Test
public void testTitle() {
assertThat(faker.name().title(), matchesRegularExpression("(\\w+\\.?( )?){3}"));
}
@Test
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+)$"));
}
@Test
public void testLocalPart() {
assertThat(faker.name().localPart(), matchesRegularExpression("^([\\w']+)\\.([\\w']+)$"));
}
@Test
public void testLocalPartWithSpaces() {
final Name name = spy(new Name(faker));
doReturn("Compound Name").when(name).firstName();
doReturn(name).when(faker).name();
assertThat(faker.name().localPart(), matchesRegularExpression("^([\\w']+)\\.([\\w']+)$"));
}
@Test
public void testBloodGroup() {
assertThat(faker.name().bloodGroup(), matchesRegularExpression("(A|B|AB|O)[+-]"));
}
}