-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSearchableDatabaseTest.java
213 lines (177 loc) · 7.3 KB
/
SearchableDatabaseTest.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
public class SearchableDatabaseTest {
private SearchableDatabase searchableDatabase = SearchableDatabase.getInstance();
private JobListing testListing0 = new JobListing("python dev", "test data1", "test loation1", false, 0.0, "test company1");
private JobListing testListing1 = new JobListing("java dev", "test data1", "test loation1", true, 25.00, "test company1");
private Student testStudent0 = new Student("bill", "Smith", "[email protected]", "password", "junior");
private Student testStudent1 = new Student("bob", "Smith", "[email protected]", "password", "junior");
private CompanyProfile testProfile0 = new CompanyProfile("walmart", "test address0", "test description 0");
private CompanyProfile testProfile1 = new CompanyProfile("bestbuy", "test address1", "test description 1");
@BeforeEach
public void setup() {
searchableDatabase.getUsers().add(this.testStudent0);
searchableDatabase.getUsers().add(this.testStudent1);
testListing0.addRequiredSkill("java");
testListing1.addRequiredSkill("python");
testListing1.addRequiredSkill("java");
searchableDatabase.getJobListings().add(this.testListing0);
searchableDatabase.getJobListings().add(this.testListing1);
testProfile0.addListing(this.testListing0);
testProfile1.addListing(this.testListing1);
searchableDatabase.getCompanyProfiles().add(testProfile0);
searchableDatabase.getCompanyProfiles().add(testProfile1);
DataWriter.saveUsers();
DataWriter.saveJobListings();
DataWriter.saveCompanyProfiles();
}
@AfterEach
public void tearDown() {
searchableDatabase.getUsers().clear();
searchableDatabase.getJobListings().clear();
searchableDatabase.getCompanyProfiles().clear();
DataWriter.saveUsers();
DataWriter.saveJobListings();
DataWriter.saveCompanyProfiles();
}
@Test
public void testNewAddJoblisting(){
JobListing temp = new JobListing();
searchableDatabase.addJobListing(temp);
assertTrue(searchableDatabase.getJobListings().contains(temp));
}
@Test
public void testAddExistingJoblisting(){
assertFalse(searchableDatabase.addJobListing(testListing0));
}
@Test
public void testAddNullJoblisting(){
assertFalse(searchableDatabase.addJobListing(null));
}
@Test
public void testRemoveExistingJoblisting(){
searchableDatabase.removeJobListing(testListing0);
assertTrue(!searchableDatabase.getJobListings().contains(testListing0));
}
@Test
public void testRemoveNullJoblisting(){
assertFalse(searchableDatabase.removeJobListing(null));
}
@Test
public void testAddNewUser(){
Student temp = new Student("tempname", "templastname", "tempemail", "temppassword", "tempyearinschool");
searchableDatabase.addUser(temp);
assertTrue(searchableDatabase.getUsers().contains(temp));
}
@Test
public void testAddexistingUser(){
assertFalse(searchableDatabase.addUser(testStudent0));
}
@Test
public void testAddNullUser(){
assertFalse(searchableDatabase.addUser(null));
}
@Test
public void testRemoveExistingUser(){
searchableDatabase.removeUser(testStudent0);
assertFalse(searchableDatabase.getUsers().contains(testStudent0));
}
@Test
public void testRemoveNonExistentUser(){
Student temp = new Student("tempname", "templastname", "tempemail", "temppassword", "tempyearinschool");
assertFalse(searchableDatabase.removeUser(temp));
}
@Test
public void testRemoveNullUser(){
assertFalse(searchableDatabase.removeUser(null));
}
@Test
public void testAddNewCompanyProfile(){
CompanyProfile temp = new CompanyProfile("tempname", "tempaddress", "tempdescription");
searchableDatabase.addProfile(temp);
assertTrue(searchableDatabase.getCompanyProfiles().contains(temp));
}
@Test
public void testAddExistingCompanyProfile(){
assertFalse(searchableDatabase.addProfile(testProfile0));
}
@Test
public void testAddNullCompanyProfile(){
assertFalse(searchableDatabase.addProfile(null));
}
@Test
public void testRemoveExistingCompanyProfile(){
searchableDatabase.getCompanyProfiles().remove(testProfile0);
assertFalse(searchableDatabase.getCompanyProfiles().contains(testProfile0));
}
@Test
public void testRemoveNullCompanyProfile(){
assertFalse(searchableDatabase.removeProfile(null));
}
@Test
public void testSearchListingsbyTitle(){
assertEquals(1, searchableDatabase.searchListings(testListing0.getTitle()).size());
}
@Test
public void testSearchListingsbyTitleEmptyString(){
assertEquals(2, searchableDatabase.searchListings("").size());
}
@Test
public void testSearchListingsbyTitleHiddenListing(){
searchableDatabase.getJobListings().get(0).setVisibility(false);
assertEquals(0, searchableDatabase.searchListings("python dev").size());
}
@Test
public void testSearchCompanyProfilesOneResult(){
assertEquals(1, searchableDatabase.searchProfiles(testProfile0.getCompanyName()).size());
}
@Test
public void testSearchCompanyProfilesEmptyString(){
assertEquals(2, searchableDatabase.searchProfiles("").size());
}
@Test
public void testSearchlistingsbyPayOneResult(){
assertEquals(1, searchableDatabase.searchListingsbyPay(15.00).size());
}
@Test
public void testSearchlistingsbyPayNegative(){
assertEquals(2, searchableDatabase.searchListingsbyPay(-5.00).size());
}
@Test
public void testSearchlistingsbyPayHiddenListing(){
searchableDatabase.getJobListings().get(1).setVisibility(false);
assertEquals(0, searchableDatabase.searchListingsbyPay(5.00).size());
}
@Test
public void testSearchListingsbySkillOneResult(){
assertEquals(1, searchableDatabase.searchListingsBySkill("python").size());
}
@Test
public void testSearchListingsbySkillEmptyString(){
assertEquals(0, searchableDatabase.searchListingsBySkill("").size());
}
@Test
public void testSearchbySkillHiddenListing(){
searchableDatabase.getJobListings().get(1).setVisibility(false);
assertEquals(0, searchableDatabase.searchListingsBySkill("python").size());
}
@Test
public void testSortListingsAlphabetically(){
searchableDatabase.sortListingsAlphabetically();
assertEquals("java dev", searchableDatabase.getJobListings().get(0).getTitle());
}
@Test
public void testSortlistingsbypay(){
searchableDatabase.sortListingsbyPay();
assertEquals(25.0, searchableDatabase.getJobListings().get(0).getPayRate());
}
@Test
public void testSortCompanyProfilesAlphabetically(){
searchableDatabase.sortProfilesAlphabetically();
assertEquals("bestbuy", searchableDatabase.getCompanyProfiles().get(0).getCompanyName());
}
}