Browse Source

refactoring: extracting admin object in AdministrationTest file

remotes/origin/fdai7780
fdai7921 11 months ago
parent
commit
1a1504ac14
  1. 38
      src/test/java/org/example/AdministrationTest.java

38
src/test/java/org/example/AdministrationTest.java

@ -6,17 +6,17 @@ import static org.junit.jupiter.api.Assertions.*;
class AdministrationTest {
Administration admin = new Administration();
private static final Course sampleCourse = new Course("Math", "M101", 4);
// Test the findProfessorById Method
@Test
void findProfessorById() {
Administration administration = new Administration();
Professor prof1 = new Professor("P1001", "Aaron", "Professor");
administration.addProfessor(prof1);
admin.addProfessor(prof1);
Professor foundProf1 = administration.findProfessorById("P1001");
Professor foundProf1 = admin.findProfessorById("P1001");
assertEquals(prof1, foundProf1);
@ -26,7 +26,6 @@ class AdministrationTest {
@Test
void isNumber() {
Administration administration = new Administration();
String full01 = "S1002"; //Supposed student id
// String str1 = full01.substring(1); //String without the Letter
String full02 = "S100Z"; //Supposed student id
@ -35,9 +34,9 @@ class AdministrationTest {
// String str3 = full03.substring(1); //String without the Letter
//checks if the substrings contain only digits
boolean test01 = administration.isNumber(full01);
boolean test02 = administration.isNumber(full02);
boolean test03 = administration.isNumber(full03);
boolean test01 = admin.isNumber(full01);
boolean test02 = admin.isNumber(full02);
boolean test03 = admin.isNumber(full03);
assertEquals(true, test01); //only digits besides the first letter
assertEquals(false, test02); // false, because the Z at the end
@ -47,16 +46,15 @@ class AdministrationTest {
@Test
void rightPrefix() {
Administration administration = new Administration();
String full01 = "S1002"; //Supposed Student id
String full02 = "s100Z"; //Supposed Student id
String full03 = "X1004"; // Supposed Professor id
boolean test01 = administration.rightPrefix(full01, 1); //checks if the id is correct, "1" because we are expecting a student id
boolean test02 = administration.rightPrefix(full02, 1); //checks if the id is correct, "1" because we are expecting a student id
boolean test03 = administration.rightPrefix(full03, 3); //checks if the id is correct, "3" because we are expecting a professor id
boolean test01 = admin.rightPrefix(full01, 1); //checks if the id is correct, "1" because we are expecting a student id
boolean test02 = admin.rightPrefix(full02, 1); //checks if the id is correct, "1" because we are expecting a student id
boolean test03 = admin.rightPrefix(full03, 3); //checks if the id is correct, "3" because we are expecting a professor id
assertEquals(true, test01);
assertEquals(false, test02);
@ -65,12 +63,11 @@ class AdministrationTest {
@org.junit.jupiter.api.Test
void findStudentById(){
Administration administration = new Administration();
Student student = new Student("Mark", "S1001", "Student");
administration.addStudents(student);
admin.addStudents(student);
Student student2 = administration.findStudentById("S1001");
Student student2 = admin.findStudentById("S1001");
assertEquals(student, student2);
}
@ -80,7 +77,6 @@ class AdministrationTest {
*/
@Test
void addCourse() {
Administration admin = new Administration();
Course course = sampleCourse;
admin.addCourse(course);
assertEquals(course, admin.findCourseByID("M101"));
@ -92,16 +88,15 @@ class AdministrationTest {
*/
@Test
public void testDeleteCourse() {
Administration administration = new Administration();
// Adding a course
Course course = sampleCourse;
administration.addCourse(course);
admin.addCourse(course);
// Deleting the course
assertTrue(administration.deleteCourse("M101"));
assertTrue(admin.deleteCourse("M101"));
// Checking if the course is no longer found
assertNull(administration.findCourseByID("M101"));
assertNull(admin.findCourseByID("M101"));
}
/**
@ -110,13 +105,12 @@ class AdministrationTest {
*/
@Test
public void testFindCourseByID() {
Administration administration = new Administration();
// Adding a course
Course course = sampleCourse;
administration.addCourse(course);
admin.addCourse(course);
// Finding the added course
assertEquals(course, administration.findCourseByID("M101"));
assertEquals(course, admin.findCourseByID("M101"));
}
}
Loading…
Cancel
Save