-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathEmployeeValidatorTest.java
79 lines (67 loc) · 2.32 KB
/
EmployeeValidatorTest.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
package com.tuturself.java8validator;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import com.tuturself.java8validator.exception.EmployeeException;
import com.tuturself.java8validator.model.Employee;
import com.tuturself.java8validator.validators.EmployeeValidator;
/**
* @author Dragon Warrior
*
*/
public abstract class EmployeeValidatorTest {
public abstract EmployeeValidator getInstance();
@Test
public void employee_isComplete_validationSucceed() {
try {
getInstance().validate(new Employee("ABCD", "XYZS", "[email protected]", 37));
} catch (EmployeeException e) {
fail("Should have been valid and therefore not thrown an exception");
}
}
@Test
public void employee_withoutFirstName_validationFail() {
try {
getInstance().validate(new Employee(null, "XYZS", "[email protected]", 37));
fail("Should have had EmployeeException containing 'valid firstname'");
} catch (EmployeeException e) {
assertTrue(e.getMessage().contains("valid firstname"));
}
}
@Test
public void employee_shortFirstName_validationFail() {
try {
getInstance().validate(new Employee("A", "XYZS", "[email protected]", 37));
fail("Should have had EmployeeException containing 'valid firstname'");
} catch (EmployeeException e) {
assertTrue(e.getMessage().contains("valid firstname"));
}
}
@Test
public void employee_wrongEmail_validationFail() {
try {
getInstance().validate(new Employee("ABCD", "XYZS", "1", 37));
fail("Should have had EmployeeException containing 'valid email'");
} catch (EmployeeException e) {
assertTrue(e.getMessage().contains("valid email"));
}
}
@Test
public void employee_underAge_validationFail() {
try {
getInstance().validate(new Employee("ABCD", "XYZS", "jon", 16));
fail("Should have had EmployeeException containing 'valid age'");
} catch (EmployeeException e) {
assertTrue(e.getMessage().contains("valid age"));
}
}
@Test
public void employee_overAge_validationFail() {
try {
getInstance().validate(new Employee("ABCD", "XYZS", "jon", 65));
fail("Should have had EmployeeException containing 'valid age'");
} catch (EmployeeException e) {
assertTrue(e.getMessage().contains("valid age"));
}
}
}