Fakultas Ilmu Komputer UI

Commit a5844345 authored by saddamonpc's avatar saddamonpc
Browse files

Refactor Student.java and Add more tests for TeachingAssistant.java

parent fc7f0dd1
Pipeline #81531 failed with stage
in 1 minute and 14 seconds
......@@ -14,17 +14,22 @@ public class Appointment implements Serializable {
private String startTime;
private String endTime;
private String description;
public String getStatus() {
return status;
}
private String status;
public Appointment(String date, Student student, TeachingAssistant ta, String startTime, String endTime, String decription, String status) {
public Appointment(String date, Student student, TeachingAssistant ta, String startTime, String endTime, String description) {
this.id = generateId();
this.date = date;
this.student = student;
this.ta = ta;
this.startTime = startTime;
this.endTime = endTime;
this.description = decription;
this.status = status;
this.description = description;
this.status = "Pending";
}
public String getId (){
......
......@@ -13,13 +13,6 @@ public class Calendar implements Serializable {
private ArrayList<Schedule> friday = new ArrayList<Schedule>();
private ArrayList<Schedule> saturday = new ArrayList<Schedule>();
private ArrayList<Schedule> sunday = new ArrayList<Schedule>();
// private ArrayList<Appointment> A_monday = new ArrayList<>();
// private ArrayList<Appointment> A_tuesday = new ArrayList<>();
// private ArrayList<Appointment> A_wednesday = new ArrayList<>();
// private ArrayList<Appointment> A_thursday = new ArrayList<>();
// private ArrayList<Appointment> A_friday = new ArrayList<>();
// private ArrayList<Appointment> A_saturday = new ArrayList<>();
// private ArrayList<Appointment> A_sunday = new ArrayList<>();
public void showCalendar() {
System.out.println("Monday:");
......@@ -50,7 +43,7 @@ public class Calendar implements Serializable {
for (Schedule schedule : sunday) {
System.out.println(schedule.toString());
}
System.out.println("");
System.out.println();
}
// Add schedule to calendar
......@@ -84,9 +77,8 @@ public class Calendar implements Serializable {
sunday.add(schedule);
break;
// TODO: Need to change default case
default:
monday.add(schedule);
System.out.println("Wrong day!");
break;
}
}
......@@ -119,41 +111,4 @@ public class Calendar implements Serializable {
return sunday;
}
// Add Appointment to calendar
// public void addAppointment(String day, Appointment appointment) {
// switch (day) {
// case "monday":
// A_monday.add(appointment);
// break;
//
// case "tuesday":
// A_tuesday.add(appointment);
// break;
//
// case "wednesday":
// A_wednesday.add(appointment);
// break;
//
// case "thursday":
// A_thursday.add(appointment);
// break;
//
// case "friday":
// A_friday.add(appointment);
// break;
//
// case "saturday":
// A_saturday.add(appointment);
// break;
//
// case "sunday":
// A_sunday.add(appointment);
// break;
//
// // TODO: Need to change default case
// default:
// A_monday.add(appointment);
// break;
// }
// }
}
......@@ -39,8 +39,7 @@ public class StudentCLI extends CLI {
String endTime = sc.nextLine();
System.out.println("(Optional) Add description for your appointment: ");
String description = sc.nextLine();
String status = "Pending";
currentStudent.setAppointment(day, ta, startTime, endTime, description, status, userList);
currentStudent.setAppointment(day, ta, startTime, endTime, description, userList);
System.out.println("Successfully added a new appointment!");
break;
......
......@@ -26,25 +26,17 @@ public class Student extends UserStudent {
}
// TODO: Adds appointment with the corresponding TeachingAssistant
public void setAppointment(String date, String TAusername, String startTime, String endTime, String description, String status, UserList userList) {
public void setAppointment(String date, String TAusername, String startTime, String endTime, String description, UserList userList) {
TeachingAssistant ta = userList.searchTA(TAusername);
if(ta.getUsername().equals("falseTA")){
System.out.println("TA not found");
} else{
Appointment newAppointment = new Appointment(date, this, ta, startTime, endTime, description, status);
} else {
Appointment newAppointment = new Appointment(date, this, ta, startTime, endTime, description);
//this.calendar.addAppointment(day, newAppointment);
this.appointmentlist.add(newAppointment);
ta.appointmentlist.add(newAppointment);
}
}
public void addAppointment() {
}
// Not a necessary method to implement. Just a bonus if there's enough time.
public void addReminder() {}
// TODO: After adding appointment, the student will have an option to add a description or not.
public void addDescription() {}
// See this Student's calendar
// temporary calendar
......
......@@ -37,11 +37,6 @@ public class TeachingAssistant extends UserStudent {
this.calendar.addSchedule(day, newSchedule);
}
// public void setAppointment(String day, String name, String ta, String startTime, String endTime, String description, String status) {
// Appointment newAppointment = new Appointment(name, ta, startTime, endTime, description, status);
// this.calendar.addAppointment(day, newAppointment);
// }
// See this TA's calendar
public void seeCalendar() {
this.calendar.showCalendar();
......@@ -89,9 +84,6 @@ public class TeachingAssistant extends UserStudent {
}
}
// Not a necessary method to implement. Just a bonus if there's enough time.
public void addReminder() {}
public String toString() {
return username + " - " + fullname;
}
......
package softeng.g4.user;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import softeng.g4.course.CourseList;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import static org.junit.jupiter.api.Assertions.*;
class TeachingAssistantTest {
private UserList userList = new UserList();
private CourseList courseList = new CourseList();
private TeachingAssistant testTa =
new TeachingAssistant("testTa", "Test Teacher", Long.parseLong("123456789"), userList);
private UserList userList;
private CourseList courseList;
private Admin testAdmin;
private TeachingAssistant testTa;
private Student testStudent;
@Test
void seeCourseList() {
@BeforeEach
void setUpTearDown() {
userList = new UserList();
courseList = new CourseList();
testAdmin = new Admin("falseAdmin", "False Admin", userList);
testTa = new TeachingAssistant("testTa",
"Test Teacher", Long.parseLong("123456789"), userList);
testStudent = new Student("testStudent",
"Test Student", Long.valueOf("123456789"), userList);
}
@Test
void setSchedule() {
testTa.setSchedule("monday", "Busy", "07:00", "21:00");
testTa.setSchedule("tuesday", "Busy", "07:00", "21:00");
testTa.setSchedule("wednesday", "Busy", "07:00", "21:00");
testTa.setSchedule("thursday", "Busy", "07:00", "21:00");
testTa.setSchedule("friday", "Busy", "07:00", "21:00");
testTa.setSchedule("saturday", "Busy", "07:00", "21:00");
testTa.setSchedule("sunday", "Busy", "07:00", "21:00");
assertEquals(testTa.getCalendar().getMonday().size(), 1);
assertEquals(testTa.getCalendar().getTuesday().size(), 1);
assertEquals(testTa.getCalendar().getWednesday().size(), 1);
assertEquals(testTa.getCalendar().getThursday().size(), 1);
assertEquals(testTa.getCalendar().getFriday().size(), 1);
assertEquals(testTa.getCalendar().getSaturday().size(), 1);
assertEquals(testTa.getCalendar().getSunday().size(), 1);
}
@Test
void seeCalendar() {
}
void seeCalendar() throws Exception {
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
// After this all System.out.println() statements will come to outContent stream.
@Test
void acceptAppointment() {
}
testTa.setSchedule("monday", "Busy", "07:00", "21:00");
@Test
void rejectAppointment() {
testTa.seeCalendar();
String expectedOutput =
"Monday:\r\nBusy 07:00 - 21:00\r\n" +
"Tuesday:\r\nWednesday:\r\nThursday:\r\nFriday:\r\nSaturday:\r\nSunday:\r\n\r\n";
assertEquals(expectedOutput, outContent.toString());
}
@Test
void addReminder() {
}
@Test
void testToString() {
void acceptAppointment() {
testStudent.setAppointment(
"31/12", "testTa", "08:00", "09:40", "testDesc", userList);
testTa.acceptAppointment(testTa.appointmentlist.get(0).getId(), userList);
assertEquals(testTa.appointmentlist.get(0).getStatus(), "Accepted");
assertEquals(testStudent.appointmentlist.get(0).getStatus(),"Accepted");
}
@Test
void getRole() {
void rejectAppointment() {
testStudent.setAppointment(
"31/12", "testTa", "08:00", "09:40", "testDesc", userList);
testTa.rejectAppointment(testTa.appointmentlist.get(0).getId(), userList);
assertEquals(testTa.appointmentlist.get(0).getStatus(), "Rejected");
assertEquals(testStudent.appointmentlist.get(0).getStatus(),"Rejected");
}
@Test
void getUsername() {
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment