-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstNameTests.java
More file actions
105 lines (92 loc) · 2.37 KB
/
Copy pathFirstNameTests.java
File metadata and controls
105 lines (92 loc) · 2.37 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
97
98
99
100
101
102
103
104
105
package tests;
import junit.framework.TestCase;
import models.Professor;
import models.UserFactory;
import models.UserType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class FirstNameTests extends TestCase {
private Professor prof;
public FirstNameTests(String name) {
super(name);
}
@Before
public void setUp() {
try {
this.prof = (Professor) UserFactory.createUser(UserType.PROFESSOR);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
@Test
public void testFirstNameCorrect() {
try {
this.prof.setFirstName("Petre");
assertEquals("Petre", this.prof.getFirstName());
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
@Test
public void testFirstNameWrong1() {
try {
this.prof.setFirstName(null);
assertNull(this.prof.getFirstName());
} catch (Exception ex) {
System.out.println(ex.getMessage());
assertNull(this.prof.getFirstName());
}
}
@Test(expected = AssertionError.class)
public void testFirstNameWrong2() {
try {
this.prof.setFirstName("Pe");
} catch (Exception ex) {
System.out.println(ex.getMessage());
assertEquals("Pe", this.prof.getFirstName());
}
}
@Test(expected = AssertionError.class)
public void testFirstNameWrong3() {
try {
this.prof.setFirstName("Petrepetrepetrepetrepetrepetrepetre");
} catch (Exception ex) {
System.out.println(ex.getMessage());
assertEquals("Petrepetrepetrepetrepetrepetrepetre",
this.prof.getFirstName());
}
}
@Test(expected = AssertionError.class)
public void testFirstNameWrong4() {
try {
this.prof.setFirstName("Petre123");
} catch (Exception ex) {
System.out.println(ex.getMessage());
assertEquals("Petre123", this.prof.getFirstName());
}
}
@Test(expected = AssertionError.class)
public void testFirstNameWrong5() {
try {
this.prof = (Professor) UserFactory.createUser(UserType.PROFESSOR);
this.prof.setFirstName("petre");
} catch (Exception ex) {
System.out.println(ex.getMessage());
assertEquals("petre", this.prof.getFirstName());
}
}
@Test(expected = AssertionError.class)
public void testFirstNameWrong6() {
try {
this.prof.setFirstName("Pet re");
} catch (Exception ex) {
System.out.println(ex.getMessage());
assertEquals("Pet re", this.prof.getFirstName());
}
}
@After
public void tearDown() throws Exception {
this.prof = null;
}
}