Skip to content

Commit 50cf7c1

Browse files
committed
Completed IndividualProjectApplicationUnitTest
1 parent f841a2e commit 50cf7c1

File tree

4 files changed

+165
-3
lines changed

4 files changed

+165
-3
lines changed

IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public Department(String deptCode, HashMap<String, Course> courses, String depar
3434
* @return The number of majors.
3535
*/
3636
public int getNumberOfMajors() {
37-
return -this.numberOfMajors;
37+
return this.numberOfMajors;
3838
}
3939

4040
/**
@@ -43,7 +43,7 @@ public int getNumberOfMajors() {
4343
* @return The name of the department chair.
4444
*/
4545
public String getDepartmentChair() {
46-
return "this.departmentChair";
46+
return this.departmentChair;
4747
}
4848

4949
/**
@@ -107,7 +107,7 @@ public String toString() {
107107
result.append(deptCode).append(" ").append(key).append(": ").append(value.toString())
108108
.append("\n");
109109
}
110-
return "result.toString()";
110+
return result.toString();
111111
}
112112

113113
@Serial
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package dev.coms4156.project.individualproject;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.util.HashMap;
6+
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.api.Test;
9+
import org.springframework.boot.test.context.SpringBootTest;
10+
import org.springframework.test.context.ContextConfiguration;
11+
12+
13+
/**
14+
* This class is built to test the Department class, which we have created to represent
15+
* a department of the courses
16+
*/
17+
@SpringBootTest
18+
@ContextConfiguration
19+
public class DepartmentUnitTests {
20+
@BeforeEach
21+
public void setupDepartmentForTesting() {
22+
testCourses = new HashMap<String, Course>();
23+
testCourses.put("4156", new Course("Griffin Newbold", "417 IAB", "11:40-12:55", 250));
24+
testDepartment = new Department("COMS", testCourses, "Griffin Newbold", 2700);
25+
}
26+
27+
@Test
28+
public void toStringTest() {
29+
String expectedResult = "COMS 4156: \nInstructor: Griffin Newbold; Location: 417 IAB; Time: 11:40-12:55\n";
30+
assertEquals(expectedResult, testDepartment.toString());
31+
}
32+
33+
@Test
34+
public void getDepartmentChairTest() {
35+
assertEquals("Griffin Newbold", testDepartment.getDepartmentChair());
36+
}
37+
38+
@Test
39+
public void getCourseSelectionTest() {
40+
assertEquals(testCourses, testDepartment.getCourseSelection());
41+
}
42+
43+
@Test
44+
public void addPersonToMajorTest() {
45+
testDepartment.addPersonToMajor();
46+
assertEquals(2701, testDepartment.getNumberOfMajors());
47+
}
48+
49+
@Test
50+
public void dropPersonFromMajorTest() {
51+
testDepartment.dropPersonFromMajor();
52+
assertEquals(2699, testDepartment.getNumberOfMajors());
53+
}
54+
55+
@Test
56+
public void addCourseTest() {
57+
Course newCourse = new Course("Griffin BBB", "417 BBB", "1:00-2:15", 250);
58+
testDepartment.addCourse("4157", newCourse);
59+
assertEquals(newCourse, testDepartment.getCourseSelection().get("4157"));
60+
}
61+
62+
@Test
63+
public void createCourseTest() {
64+
Course newCourse = new Course("Griffin BBB", "417 BBB", "1:00-2:15", 250);
65+
testDepartment.createCourse("4157", "Griffin BBB", "417 BBB", "1:00-2:15", 250);
66+
assertEquals(newCourse.toString(), testDepartment.getCourseSelection().get("4157").toString());
67+
}
68+
69+
70+
@Test
71+
public void getNumberOfMajorsTest() {
72+
assertEquals(2700, testDepartment.getNumberOfMajors());
73+
}
74+
75+
private Department testDepartment;
76+
private HashMap<String, Course> testCourses;
77+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package dev.coms4156.project.individualproject;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.util.HashMap;
6+
7+
import org.junit.jupiter.api.BeforeAll;
8+
import org.junit.jupiter.api.Test;
9+
import org.springframework.boot.test.context.SpringBootTest;
10+
import org.springframework.test.context.ContextConfiguration;
11+
12+
/**
13+
* This class is built to test the IndividualProjectApplication class, which we have created to represent
14+
* the application that manages the courses and departments.
15+
*/
16+
@SpringBootTest
17+
@ContextConfiguration
18+
public class IndividualProjectApplicationUnitTest {
19+
20+
@BeforeAll
21+
public static void setupCourseForTesting() {
22+
// Firstly we set up the dataset for the test
23+
application = new IndividualProjectApplication();
24+
String[] args = {"setup"};
25+
application.run(args);
26+
}
27+
28+
@Test
29+
public void runTest() {
30+
myFileDatabase = IndividualProjectApplication.myFileDatabase;
31+
assertEquals(7, myFileDatabase.getDepartmentMapping().size());
32+
}
33+
34+
@Test
35+
public void overrideDatabaseTest() {
36+
testMyFileDatabase = new MyFileDatabase(0, "data.txt");
37+
38+
Course testCourse = new Course("Griffin Newbold", "417 IAB", "11:40-12:55", 250);
39+
HashMap<String, Course> testCourses = new HashMap<String, Course>();
40+
testCourses.put("4156", testCourse);
41+
42+
Department testDepartment = new Department("COMS", testCourses, "Griffin Newbold", 2700);
43+
HashMap<String, Department> testDepartmentMapping = new HashMap<String, Department>();
44+
testDepartmentMapping.put("COMS", testDepartment);
45+
46+
overideMyFileDatabase = new MyFileDatabase(1, "override_data.txt");
47+
overideMyFileDatabase.setMapping(testDepartmentMapping);
48+
IndividualProjectApplication.overrideDatabase(overideMyFileDatabase);
49+
50+
myFileDatabase = IndividualProjectApplication.myFileDatabase;
51+
assertEquals(1, myFileDatabase.getDepartmentMapping().size());
52+
53+
// set the database back to the original value
54+
IndividualProjectApplication.overrideDatabase(testMyFileDatabase);
55+
}
56+
57+
@Test
58+
public void onTerminationTest() {
59+
application.onTermination();
60+
testMyFileDatabase = new MyFileDatabase(0, "data.txt");
61+
assertEquals(7, IndividualProjectApplication.myFileDatabase.getDepartmentMapping().size());
62+
}
63+
64+
private MyFileDatabase testMyFileDatabase;
65+
private MyFileDatabase overideMyFileDatabase;
66+
private MyFileDatabase myFileDatabase;
67+
private static IndividualProjectApplication application;
68+
}

bugs.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Here I will list all the bugs that I found in the project and how I solve it.
22

3+
# In Course class:
34
1. `return enrollmentCapacity > enrolledStudentCount;`
45
- Address: In isCourseFull() method in Course class.
56
- Solution: Change the > to <.
@@ -14,3 +15,19 @@ Here I will list all the bugs that I found in the project and how I solve it.
1415
- Address: In getInstructorName() method in Course class.
1516
- Solution: Change courseLocation to instructorName.
1617
- Reason: The method should return the instructorName, not the courseLocation.
18+
19+
# In Department class:
20+
1. `return -this.numberOfMajors;`
21+
- Address: In getNumberOfMajors() method in Department class.
22+
- Solution: Remove the - sign.
23+
- Reason: The method should return the number of majors, not the negative number of majors.
24+
25+
2. `return "result.toString()";`
26+
- Address: In toString() method in Department class.
27+
- Solution: change it to return result.toString();
28+
- Reason: The method should return the result of the toString() method, not the string "result.toString()".
29+
30+
3. `return "this.departmentChair";`
31+
- Address: In getDepartmentChair() method in Department class.
32+
- Solution: Change it to return this.departmentChair;
33+
- Reason: The method should return the departmentChair, not the string "this.departmentChair".

0 commit comments

Comments
 (0)