From 740beafb4be79e55edd4e0448ab589a088ce76db Mon Sep 17 00:00:00 2001 From: Tobias Herbert Date: Thu, 8 Feb 2024 16:25:35 +0100 Subject: [PATCH 1/4] refactoring: adjusting variables naming Convention to avoid confusion --- src/main/java/org/example/Admin.java | 44 +++++++++---------- src/main/java/org/example/Administration.java | 4 +- src/test/java/org/example/AdminTest.java | 6 +-- .../java/org/example/AdministrationTest.java | 6 +-- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/example/Admin.java b/src/main/java/org/example/Admin.java index f8ad460..309feed 100644 --- a/src/main/java/org/example/Admin.java +++ b/src/main/java/org/example/Admin.java @@ -8,9 +8,9 @@ import java.util.List; * Represents an administrative user in the system. */ public class Admin { - public String name; - public String id; - public String role; + public String adminName; + public String adminId; + public String adminRole; public Admin() { } @@ -22,29 +22,29 @@ public class Admin { * @param role the role of the admin in the system (should typically be "Admin") */ public Admin(String name, String id, String role) { - this.name = name; - this.id = id; - this.role = role; + this.adminName = name; + this.adminId = id; + this.adminRole = role; } - public String getName() { - return name; + public String getAdminName() { + return adminName; } - public void setName(String name) { - this.name = name; + public void setAdminName(String adminName) { + this.adminName = adminName; } - public String getId() { - return id; + public String getAdminId() { + return adminId; } - public void setId(String id) { - this.id = id; + public void setAdminId(String adminId) { + this.adminId = adminId; } - public String getRole() { - return role; + public String getAdminRole() { + return adminRole; } - public void setRole(String role) { - this.role = role; + public void setAdminRole(String adminRole) { + this.adminRole = adminRole; } /** @@ -53,9 +53,9 @@ public class Admin { */ public void printAdminInfo() { - System.out.println("Name: " + getName()); - System.out.println("ID: " + getId()); - System.out.println("Role: " + getRole()); + System.out.println("Name: " + getAdminName()); + System.out.println("ID: " + getAdminId()); + System.out.println("Role: " + getAdminRole()); } /** @@ -65,7 +65,7 @@ public class Admin { */ public void writeToFile(Admin admin, String filename) throws IOException{ try(BufferedWriter writer = new BufferedWriter(new FileWriter(filename))){ - String attributes = admin.getName() + "\n" + admin.getId() + "\n" + admin.getRole(); + String attributes = admin.getAdminName() + "\n" + admin.getAdminId() + "\n" + admin.getAdminRole(); writer.write(attributes); } diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index 03aa389..0041c76 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -153,7 +153,7 @@ public class Administration { { for(Admin admin : admins ) { - if(admin.getId().equals(adminID)){ + if(admin.getAdminId().equals(adminID)){ admins.remove(admin); return true; //Course found and removed } @@ -181,7 +181,7 @@ public class Administration { { for(Admin admin :admins) { - if(admin.getId().equals(adminId)) + if(admin.getAdminId().equals(adminId)) { return admin; } diff --git a/src/test/java/org/example/AdminTest.java b/src/test/java/org/example/AdminTest.java index 40104f9..890fed2 100644 --- a/src/test/java/org/example/AdminTest.java +++ b/src/test/java/org/example/AdminTest.java @@ -74,9 +74,9 @@ class AdminTest { assertEquals(1, testAdmins.size()); Admin admin = testAdmins.get(0); - assertEquals("Thomas", admin.getName()); - assertEquals("A1001", admin.getId()); - assertEquals("Admin", admin.getRole()); + assertEquals("Thomas", admin.getAdminName()); + assertEquals("A1001", admin.getAdminId()); + assertEquals("Admin", admin.getAdminRole()); } } \ No newline at end of file diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index 1dc593f..a98f761 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -139,8 +139,8 @@ class AdministrationTest { Admin result = administration.findAdminById("A2001"); assertNotNull(result, "Admin should be found after being added."); - assertEquals("A2001", result.getId(), "The ID of the found admin should match."); - assertEquals("Jane Doe", result.getName(), "The name of the found admin should match."); + assertEquals("A2001", result.getAdminId(), "The ID of the found admin should match."); + assertEquals("Jane Doe", result.getAdminName(), "The name of the found admin should match."); } @Test @@ -151,7 +151,7 @@ class AdministrationTest { Admin result = administration.findAdminById("A2002"); assertNotNull(result, "Admin should be found by ID."); - assertEquals("A2002", result.getId(), "The ID should match the one searched for."); + assertEquals("A2002", result.getAdminId(), "The ID should match the one searched for."); } @Test From 9ac92b1fcf02cdc0159c1551d2a19b834ec5dcde Mon Sep 17 00:00:00 2001 From: Tobias Herbert Date: Thu, 8 Feb 2024 16:28:43 +0100 Subject: [PATCH 2/4] refactoring: adjusting variables naming Convention to avoid confusion --- src/main/java/org/example/Administration.java | 4 +- src/main/java/org/example/Student.java | 44 +++++++++---------- .../java/org/example/AdministrationTest.java | 8 ++-- src/test/java/org/example/StudentTest.java | 6 +-- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index 0041c76..bbd7f83 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -196,7 +196,7 @@ public class Administration { */ public boolean deleteStudents(String studentID){ for(Student student : students){ - if(student.getId().equals(studentID)){ + if(student.getStudentId().equals(studentID)){ students.remove(student); return true; } @@ -223,7 +223,7 @@ public class Administration { { for(Student student :students) { - if(student.getId().equals(studentId)) + if(student.getStudentId().equals(studentId)) { return student; } diff --git a/src/main/java/org/example/Student.java b/src/main/java/org/example/Student.java index 5c4afe7..839a571 100644 --- a/src/main/java/org/example/Student.java +++ b/src/main/java/org/example/Student.java @@ -9,9 +9,9 @@ import java.util.List; */ public class Student { - String name; - String id; - String role; + String studentName; + String studentId; + String studentRole; public Student(){ @@ -25,33 +25,33 @@ public class Student { * @param role the role of the student in the system (should typically be "Student") */ - this.name = name; - this.id = id; - this.role = role; + this.studentName = name; + this.studentId = id; + this.studentRole = role; } - public String getName() { - return name; + public String getStudentName() { + return studentName; } - public String getId() { - return id; + public String getStudentId() { + return studentId; } - public String getRole() { - return role; + public String getStudentRole() { + return studentRole; } - public void setName(String name) { - this.name = name; + public void setStudentName(String studentName) { + this.studentName = studentName; } - public void setId(String id) { - this.id = id; + public void setStudentId(String studentId) { + this.studentId = studentId; } - public void setRole(String role) { - this.role = role; + public void setStudentRole(String studentRole) { + this.studentRole = studentRole; } /** @@ -61,15 +61,15 @@ public class Student { public void printStudentInfo() { - System.out.println("Name: " + getName()); - System.out.println("ID: " + getId()); - System.out.println("Role: " + getRole()); + System.out.println("Name: " + getStudentName()); + System.out.println("ID: " + getStudentId()); + System.out.println("Role: " + getStudentRole()); } public void writeToFile(Student student, String filename) throws IOException { try(BufferedWriter writer = new BufferedWriter(new FileWriter(filename))){ - String attributes = student.getName() + "\n" + student.getId() + "\n" + student.getRole(); + String attributes = student.getStudentName() + "\n" + student.getStudentId() + "\n" + student.getStudentRole(); writer.write(attributes); } diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index a98f761..047adaf 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -167,7 +167,7 @@ class AdministrationTest { // Now, the student should be found assertNotNull(administration.findStudentById("S1001")); - assertEquals("Alice", administration.findStudentById("S1001").getName()); + assertEquals("Alice", administration.findStudentById("S1001").getStudentName()); } @Test @@ -205,13 +205,13 @@ class AdministrationTest { assertNotNull(retrievedStudent); // Asserting that the retrieved student's name matches the expected name - assertEquals("Walter White", retrievedStudent.getName()); + assertEquals("Walter White", retrievedStudent.getStudentName()); // Asserting that the retrieved student's ID matches the expected ID - assertEquals("S123456", retrievedStudent.getId()); + assertEquals("S123456", retrievedStudent.getStudentId()); // Asserting that the retrieved student's role matches the expected role - assertEquals("Student", retrievedStudent.getRole()); + assertEquals("Student", retrievedStudent.getStudentRole()); } /** diff --git a/src/test/java/org/example/StudentTest.java b/src/test/java/org/example/StudentTest.java index 1e5f76f..1985b69 100644 --- a/src/test/java/org/example/StudentTest.java +++ b/src/test/java/org/example/StudentTest.java @@ -61,9 +61,9 @@ class StudentTest { assertEquals(1, testStudents.size()); Student admin = testStudents.get(0); - assertEquals("Sebastian Reichard", admin.getName()); - assertEquals("S1001", admin.getId()); - assertEquals("Student", admin.getRole()); + assertEquals("Sebastian Reichard", admin.getStudentName()); + assertEquals("S1001", admin.getStudentId()); + assertEquals("Student", admin.getStudentRole()); // Files.delete(Path.of(filename)); From 1585f1a487ab6eeb14a1cb79a6dd6f8669c663ac Mon Sep 17 00:00:00 2001 From: Tobias Herbert Date: Thu, 8 Feb 2024 16:36:04 +0100 Subject: [PATCH 3/4] refactoring: adjusting test functions to the naming conventions in class StudentTest --- src/test/java/org/example/StudentTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/example/StudentTest.java b/src/test/java/org/example/StudentTest.java index 1985b69..7ac62f4 100644 --- a/src/test/java/org/example/StudentTest.java +++ b/src/test/java/org/example/StudentTest.java @@ -30,7 +30,7 @@ class StudentTest { private static final Student sampleStudent = new Student("Sebastian Reichard", "S1001", "Student"); @org.junit.jupiter.api.Test - void writeToFile() throws IOException { + void testWriteToFile() throws IOException { Student student = sampleStudent; // String filename = "testStudentData.txt"; @@ -46,7 +46,7 @@ class StudentTest { } @Test - void readFromFile() throws IOException { + void testReadFromFile() throws IOException { try (PrintWriter writer = new PrintWriter(new FileWriter("testStudentData.txt"))){ writer.println("Sebastian Reichard"); From 1ce94ba809748c242a1542040abc7ca3cd64733c Mon Sep 17 00:00:00 2001 From: Tobias Herbert Date: Thu, 8 Feb 2024 16:37:28 +0100 Subject: [PATCH 4/4] refactoring: adjusting test functions to the naming conventions in class AdminTest --- src/test/java/org/example/AdminTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/example/AdminTest.java b/src/test/java/org/example/AdminTest.java index 890fed2..b6b50a2 100644 --- a/src/test/java/org/example/AdminTest.java +++ b/src/test/java/org/example/AdminTest.java @@ -30,7 +30,7 @@ class AdminTest { //Tests printAdminInfo Method @org.junit.jupiter.api.Test - void printAdminInfo() { + void testPrintAdminInfo() { Admin admin = new Admin("Aaron", "A1001", "Admin"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); @@ -47,7 +47,7 @@ class AdminTest { } //Tests writeToFile Method @Test - void writeToFile() throws IOException { + void testWriteToFile() throws IOException { Admin admin = new Admin("Simon", "A1001", "Admin") ; admin.writeToFile(admin, fileName()); @@ -59,7 +59,7 @@ class AdminTest { } //Tests readFromFile Method @Test - void readFromFile() throws IOException { + void testReadFromFile() throws IOException { try (PrintWriter writer = new PrintWriter(new FileWriter("testAdminData.txt"))){ writer.println("Thomas");