diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index 4d2d885..647c024 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -324,4 +324,71 @@ class AdministrationTest { } + @Test + void registerUser() { + Administration administration = new Administration(); + //Selects the userType + int userType = 1; + + //Checks if the user Input correct; in this case its pre-determined + boolean correctData = false; + while(!correctData) + { + //User Input + String userName = "Tobias"; + String userId = "S1010"; + + //Checks if the entered id is already being used + if(administration.findProfessorById(userId) != null || administration.findAdminById(userId) != null || administration.findStudentById(userId) != null) { + + } + else if(administration.findProfessorById(userId) == null || administration.findAdminById(userId) == null || administration.findStudentById(userId) == null) + { + //the entered id is not used + + + if(!administration.rightPrefix(userId, userType)) + { + //the prefix is wrong + + } + else if(!administration.isNumber(userId)) + { + //the substring does not contain only digits + System.out.println("Every character besides the first one need to be digits"); + + + } + else{ + //the id is not being used and has the right id-"syntax" + System.out.println("The Id has not been used already!"); + correctData = true; + } + + } + + switch (userType) + { + case 1: //Student + Student student = new Student(userName, userId, "Student"); + administration.addStudents(student); + break; + case 2: //Admin + Admin admin = new Admin(userName, userId, "Admin"); + administration.addAdmin(admin); + break; + case 3: //Professor + Professor professor = new Professor(userId, userName, "Professor"); + administration.addProfessor(professor); + default: //Error + break; + } + } + + //If All three are correct, the registerUser Function has been successful + assertEquals("Tobias", administration.findStudentById("S1010").getStudentName()); + assertEquals("S1010", administration.findStudentById("S1010").getStudentId()); + assertEquals("Student",administration.findStudentById("S1010").getStudentRole()); + + } }