forked from Vidhee1411/Internship-Application
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataLoaderTest.java
109 lines (96 loc) · 4 KB
/
DataLoaderTest.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
import java.util.ArrayList;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import static org.junit.jupiter.api.Assertions.*;
public class DataLoaderTest {
private SearchableDatabase searchableDatabase = SearchableDatabase.getInstance();
private ArrayList<User> userList = searchableDatabase.getUsers();
private ArrayList<JobListing> jobList = searchableDatabase.getJobListings();
private ArrayList<CompanyProfile> profileList = searchableDatabase.getCompanyProfiles();
@BeforeEach
public void setup() {
userList.clear();
jobList.clear();
profileList.clear();
searchableDatabase.getUsers().add(new Student("bill", "Smith", "[email protected]", "password", "junior"));
searchableDatabase.getUsers().add(new Student("bob", "Smith", "[email protected]", "password", "junior"));
JobListing testlisting0 = new JobListing("python dev", "test data1", "test loation1", false, 0.0, "test company1");
JobListing testlisting1 = new JobListing("python dev", "test data1", "test loation1", false, 0.0, "test company1");
searchableDatabase.getJobListings().add(testlisting0);
searchableDatabase.getJobListings().add(testlisting1);
CompanyProfile testprofile0 = new CompanyProfile("test company name0", "test address0", "test description 0");
CompanyProfile testprofile1 = new CompanyProfile("test company name1", "test address1", "test description 1");
testprofile0.addListing(testlisting0);
testprofile1.addListing(testlisting1);
searchableDatabase.getCompanyProfiles().add(testprofile0);
searchableDatabase.getCompanyProfiles().add(testprofile1);
DataWriter.saveUsers();
DataWriter.saveJobListings();
DataWriter.saveCompanyProfiles();
}
@AfterEach
public void tearDown() {
userList.clear();
jobList.clear();
profileList.clear();
searchableDatabase.getUsers().clear();
searchableDatabase.getJobListings().clear();
searchableDatabase.getCompanyProfiles().clear();
DataWriter.saveUsers();
DataWriter.saveJobListings();
DataWriter.saveCompanyProfiles();
}
@Test
public void testGetTwoUsers(){
userList = DataLoader.loadData().getUsers();
assertEquals(2, userList.size());
}
@Test
public void testGetZeroUsers(){
searchableDatabase.getUsers().clear();
DataWriter.saveUsers();
searchableDatabase = DataLoader.loadData();
userList = searchableDatabase.getUsers();
assertEquals(0, userList.size());
}
@Test
public void testGetFirstUser(){
userList = DataLoader.loadData().getUsers();
assertEquals("bill", userList.get(0).getFirstName());
}
@Test
public void testGetTwoListings(){
jobList = DataLoader.loadData().getJobListings();
assertEquals(2, jobList.size());
}
@Test
public void testGetZeroListings(){
searchableDatabase.getCompanyProfiles().clear();
DataWriter.saveJobListings();
jobList = DataLoader.loadData().getJobListings();
assertEquals(0, jobList.size());
}
@Test
public void testGetFirstListing(){
jobList = DataLoader.loadData().getJobListings();
assertEquals("python dev", jobList.get(0).getTitle());
}
@Test
public void testGetTwoCompanyProfiles(){
profileList = DataLoader.loadData().getCompanyProfiles();
assertEquals(2, profileList.size());
}
@Test
public void testGetZeroCompanyProfiles(){
searchableDatabase.getCompanyProfiles().clear();
DataWriter.saveCompanyProfiles();
profileList = DataLoader.loadData().getCompanyProfiles();
assertEquals(0, profileList.size());
}
@Test
public void testGetFirstCompanyProfile(){
profileList = DataLoader.loadData().getCompanyProfiles();
assertEquals("test company name0", profileList.get(0).getCompanyName());
}
}