Skip to content

Commit

Permalink
Completed all tests for part2
Browse files Browse the repository at this point in the history
  • Loading branch information
WillMa17 committed Sep 12, 2024
1 parent b005848 commit 4698d68
Show file tree
Hide file tree
Showing 11 changed files with 1,262 additions and 9 deletions.
Binary file added IndividualProject/data.txt
Binary file not shown.
6 changes: 6 additions & 0 deletions IndividualProject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,33 @@ public String getCourseTimeSlot() {
return this.courseTimeSlot;
}

public int getEnrolledStudentCount() {
return this.enrolledStudentCount;
}


public String toString() {
return "\nInstructor: " + instructorName + "; Location: "
+ courseLocation + "; Time: " + courseTimeSlot;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}

if (obj == null || getClass() != obj.getClass()) {
return false;
}

Course course = (Course) obj;
return this.courseLocation.equals(course.getCourseLocation()) &&
this.courseTimeSlot.equals(course.getCourseTimeSlot()) &&
this.enrolledStudentCount == course.getEnrolledStudentCount() &&
this.instructorName.equals(course.getInstructorName()) &&
this.enrollmentCapacity == course.getEnrolledStudentCount();
}

public void reassignInstructor(String newInstructorName) {
this.instructorName = newInstructorName;
Expand All @@ -87,11 +108,11 @@ public void setEnrolledStudentCount(int count) {
this.enrolledStudentCount = count;
}


public boolean isCourseFull() {
return enrollmentCapacity > enrolledStudentCount;
}


@Serial
private static final long serialVersionUID = 123456L;
private final int enrollmentCapacity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ public String toString() {
return "result.toString()";
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}

if (obj == null || getClass() != obj.getClass()) {
return false;
}

Department dept = (Department) obj;
return this.toString().equals(dept.toString());
}

@Serial
private static final long serialVersionUID = 234567L;
private HashMap<String, Course> courses;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ public void onTermination() {
}
}


//Database Instance
public static MyFileDatabase myFileDatabase;
private static boolean saveData = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ public ResponseEntity<?> changeCourseLocation(@RequestParam(value = "deptCode")

private ResponseEntity<?> handleException(Exception e) {
System.out.println(e.toString());
return new ResponseEntity<>("An Error has occurred", HttpStatus.OK);
return new ResponseEntity<>("An Error has occurred", HttpStatus.INTERNAL_SERVER_ERROR);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,115 @@
package dev.coms4156.project.individualproject;

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.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;


/**
* This class contains unit tests for the course class.
* This class contains unit tests for the Course class.
*/
@SpringBootTest
@ContextConfiguration
public class CourseUnitTests {

@BeforeAll
public static void setupCourseForTesting() {
@BeforeEach
public void setupCourseForTesting() {
testCourse = new Course("Griffin Newbold", "417 IAB", "11:40-12:55", 250);
}

@Test
public void getEnrolledStudentCountTest(){
assertEquals(0, testCourse.getEnrolledStudentCount());
}

@Test
public void enrollStudentTest() {
testCourse.enrollStudent();
assertEquals(1, testCourse.getEnrolledStudentCount());
}

@Test
public void enrollFailTest() {
testCourse = new Course("Griffin Newbold", "417 IAB", "11:40-12:55", 0);
testCourse.enrollStudent();
assertEquals(0, testCourse.getEnrolledStudentCount());
}

@Test
public void setEnrolledStudentCountTest() {
testCourse.setEnrolledStudentCount(10);
assertEquals(10, testCourse.getEnrolledStudentCount());
}

@Test
public void setEnrolledStudentCountFailTest() {
testCourse.setEnrolledStudentCount(251);
assertEquals(0, testCourse.getEnrolledStudentCount());
}

@Test
public void toStringTest() {
String expectedResult = "\nInstructor: Griffin Newbold; Location: 417 IAB; Time: 11:40-12:55";
assertEquals(expectedResult, testCourse.toString());
}

@Test
public void getCourseLocationTest() {
String expectedResult = "417 IAB";
assertEquals(expectedResult, testCourse.getCourseLocation());
}

@Test
public void getCourseTimeSlotTest() {
String expectedResult = "11:40-12:55";
assertEquals(expectedResult, testCourse.getCourseTimeSlot());
}

@Test
public void getInstructorNameTest() {
String expectedResult = "Griffin Newbold";
assertEquals(expectedResult, testCourse.getInstructorName());
}

@Test
public void reassignInstructorTest() {
testCourse.reassignInstructor("Suwei Ma");
assertEquals("Suwei Ma", testCourse.getInstructorName());
}

@Test
public void reassignLocationTest() {
testCourse.reassignLocation("418 IAB");
assertEquals("418 IAB", testCourse.getCourseLocation());
}

@Test
public void reassignTimeTest() {
testCourse.reassignTime("11:50-1:05");
assertEquals("11:50-1.05", testCourse.getCourseTimeSlot());
}

@Test
public void isCourseFullTest() {
testCourse.setEnrolledStudentCount(250);
assertTrue(testCourse.isCourseFull());
}

@Test
public void CourseNotFullTest() {
testCourse.setEnrolledStudentCount(0);
assertFalse(testCourse.isCourseFull());
}

@Test
public void equalsTest() {
Course testCourse_new = new Course("Griffin Newbold", "417 IAB", "11:40-12:55", 250);
testCourse_new.setEnrolledStudentCount(1);
assertEquals(testCourse, testCourse_new);
}
/** The test course instance used for testing. */
public static Course testCourse;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package dev.coms4156.project.individualproject;

import java.util.HashMap;
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.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;


/**
* This class contains unit tests for the Department class.
*/
@SpringBootTest
@ContextConfiguration
public class DepartmentUnitTests {

@BeforeEach
public void setupDepartmentForTesting() {
Course coms4118 = new Course("Jason Nieh", "417 IAB", "4:10-5:25", 50);
HashMap<String, Course> courses = new HashMap<>();
courses.put("4118", coms4118);
testDepartment = new Department("COMS", courses, "Department Chair", 2);
}

@Test
public void getNumberOfMajorsTest() {
assertEquals(2, testDepartment.getNumberOfMajors());
}

@Test
public void getDepartmentChairTest() {
assertEquals("Department Chair", testDepartment.getDepartmentChair());
}

@Test
public void getCourseSelectionTest() {
Course coms4118 = new Course("Jason Nieh", "417 IAB", "4:10-5:25", 50);
HashMap<String, Course> courses = new HashMap<>();
courses.put("4118", coms4118);
assertEquals(courses, testDepartment.getCourseSelection());
}

@Test
public void addPersonToMajorTest() {
testDepartment.addPersonToMajor();
assertEquals(3, testDepartment.getNumberOfMajors());
}

@Test
public void dropPersonFromMajorTest() {
testDepartment.dropPersonFromMajor();
assertEquals(1, testDepartment.getNumberOfMajors());
}

@Test
public void createCourseTest() {
testDepartment.createCourse("4156", "Gail Kaizer", "Remote", "10:10-11:25", 50);
HashMap<String, Course> courses = testDepartment.getCourseSelection();
Course testCourse = new Course("Gail Kaizer", "Remote", "10:10-11:25", 50);
assertEquals(courses.get("COMS4156"), testCourse);
}

@Test
public void toStringTest() {
Course coms4118 = new Course("Jason Nieh", "417 IAB", "4:10-5:25", 50);
String str = "4118 :" + coms4118.toString() + "\n";
assertEquals(str, testDepartment.toString());
}

@Test
public void equalsTest(){
Course coms4118 = new Course("Jason Nieh", "417 IAB", "4:10-5:25", 50);
HashMap<String, Course> courses = new HashMap<>();
courses.put("4118", coms4118);
Department testEquals = new Department("COMS", courses, "Department Chair", 2);
assertEquals(testDepartment, testEquals);
}

/** The test department instance used for testing. */
public static Department testDepartment;
}

Loading

0 comments on commit 4698d68

Please sign in to comment.