-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsernameTests.java
More file actions
88 lines (76 loc) · 1.93 KB
/
Copy pathUsernameTests.java
File metadata and controls
88 lines (76 loc) · 1.93 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
package tests;
import junit.framework.TestCase;
import models.Student;
import models.UserFactory;
import models.UserType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class UsernameTests extends TestCase {
private Student stud;
public UsernameTests(String name) {
super(name);
}
@Before
public void setUp() {
try {
this.stud = (Student) UserFactory.createUser(UserType.STUDENT);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
@Test
public void testUsernameCorrect() {
this.stud.setUsername("ionut.petre");
assertEquals("ionut.petre", this.stud.getUsername());
}
@Test
public void testUsernameWrong1() {
try {
this.stud.setUsername(null);
} catch (Exception ex) {
System.out.println(ex.toString());
assertEquals(null, this.stud.getUsername());
}
}
@Test(expected = AssertionError.class)
public void testUsernameWrong2() {
try {
this.stud.setUsername("Ionut.petre");
} catch (Exception ex) {
System.out.println(ex.toString());
assertEquals("Ionut.petre", this.stud.getUsername());
}
}
@Test(expected = AssertionError.class)
public void testUsernameWrong3() {
try {
this.stud.setUsername("ionut_petre");
} catch (Exception ex) {
System.out.println(ex.toString());
assertEquals("ionut_petre", this.stud.getUsername());
}
}
@Test(expected = AssertionError.class)
public void testUsernameWrong4() {
try {
this.stud.setUsername("ion");
} catch (Exception ex) {
System.out.println(ex.toString());
assertEquals("ion", this.stud.getUsername());
}
}
@Test(expected = AssertionError.class)
public void testUsernameWrong5() {
try {
this.stud.setUsername("ionut.petreeeeeeeeeeeeeeeeeeeee");
} catch (Exception ex) {
System.out.println(ex.toString());
assertEquals("ionut.petreeeeeeeeeeeeeeeeeeeee", this.stud.getUsername());
}
}
@After
public void tearDown() throws Exception {
this.stud = null;
}
}