-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAdministratorTest.java
155 lines (133 loc) · 4.59 KB
/
AdministratorTest.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import java.lang.NullPointerException;
import static org.junit.jupiter.api.Assertions.*;
public class AdministratorTest {
private Administrator admin;
private SearchableDatabase searchableDatabase;
@BeforeEach
public void setup() {
admin = new Administrator("Adam", "Inistrator", "[email protected]", "12345678", UUID.randomUUID());
searchableDatabase = SearchableDatabase.getInstance();
}
@AfterEach
public void tearDown() {
searchableDatabase.getUsers().clear();
searchableDatabase.getJobListings().clear();
searchableDatabase.getCompanyProfiles().clear();
}
@Test
public void testHideReviewEmptyConstructor() {
Review review = new Review();
admin.hideReview(review);
assertTrue(review.getVisibility());
}
@Test
public void testHideReviewFullConstructor() {
Review review = new Review("Test", "1", 4.9, "Blah blah");
try {
admin.hideReview(review);
} catch(NullPointerException e) {
assertNotNull(null);
}
assertFalse(review.getVisibility());
}
@Test
public void testHideReviewHiddenToVisible() {
Review review = new Review();
admin.hideReview(review);
admin.hideReview(review);
assertFalse(review.getVisibility());
}
@Test
public void testRemoveValidListing() {
JobListing toRemove = new JobListing();
toRemove.setUUID(UUID.randomUUID());
toRemove.editTitle("Job To Remove");
searchableDatabase.addJobListing(toRemove);
admin.removeListing(toRemove);
assertEquals(0, searchableDatabase.getJobListings().size());
}
@Test
public void testRemoveNullListing() {
try {
assertFalse(admin.removeListing(null));
} catch(NullPointerException e) {
assertNotNull(null);
}
}
@Test
public void testRemoveValidStudent() {
Student stud = new Student("Joe", "Clash", "[email protected]", "pleaseNotNow", "senior");
searchableDatabase.addUser(stud);
admin.removeAccount(stud);
assertEquals(0, searchableDatabase.getUsers().size());
}
@Test
public void testRemoveValidStudentTwice() {
Student stud = new Student("Joe", "Clash", "[email protected]", "pleaseNotNow", "senior");
searchableDatabase.addUser(stud);
admin.removeAccount(stud);
try {
admin.removeAccount(stud);
int i = 0;
assertEquals(1, i);
} catch (NullPointerException e){
assertNull(null);
}
}
@Test
public void testRemoveStudentNotInDatabase() {
Student stud = new Student("Joe", "Clash", "[email protected]", "pleaseNotNow", "senior");
try {
admin.removeAccount(stud);
int i = 0;
assertEquals(1, i);
} catch (NullPointerException e){
assertNull(null);
}
}
@Test
public void testRemoveNullStudent() {
Student stud = null;
searchableDatabase.addUser(stud);
admin.removeAccount(stud);
assertEquals(0, searchableDatabase.getUsers().size());
}
@Test
public void testRemoveValidEmployer() {
Employer emp = new Employer("Joe", "Washing", "[email protected]", "organized");
searchableDatabase.addUser(emp);
admin.removeAccount(emp);
assertEquals(0, searchableDatabase.getUsers().size());
}
@Test
public void testRemoveNullEmployer() {
Employer emp = null;
searchableDatabase.addUser(emp);
admin.removeAccount(emp);
assertEquals(0, searchableDatabase.getUsers().size());
}
@Test
public void testRegisterNormalAdmin() {
admin.registerAccount("Ad", "Mihn", "[email protected]", "bestADMIN");
assertEquals(1, searchableDatabase.getUsers().size());
}
@Test
public void testRegisterSameAdminTwice() {
admin.registerAccount("Ad", "Mihn", "[email protected]", "bestADMIN");
admin.registerAccount("Ad", "Mihn", "[email protected]", "bestADMIN");
assertEquals(1, searchableDatabase.getUsers().size());
}
@Test
public void testRegisterAdminWithNullValues() {
String firstName = null;
String lastName = null;
String email = null;
String password = null;
admin.registerAccount(firstName, lastName, email, password);
assertEquals(0, searchableDatabase.getUsers().size());
}
}