Fakultas Ilmu Komputer UI

Commit 963409cb authored by hazlazuardi's avatar hazlazuardi
Browse files

model package 100% coverage

parent 6f17a345
Pipeline #81968 passed with stages
in 4 minutes and 9 seconds
it1,st,rpl,2020-01-01,true,st,ta
ga3,st,rpl,2021-06-07,true,st,ta
......@@ -358,6 +358,7 @@ public class Student extends Role {
System.out.println("Picked: " + picked3.getAssignmentName());
picked3.getAssignmentCourse().deleteAssignment(picked3);
assignmentList.deleteAssignment(picked3);
CSVAssignment.deleteAssignment(picked3.getAssignmentName());
......
......@@ -21,15 +21,7 @@ public class Assignment {
}
public Assignment() {
}
public Assignment(String assignmentName, Course assignmentCourse, LocalDate dueDate, Boolean validated, Set<User> validatedBy,User createdBy) {
this.assignmentName = assignmentName;
this.assignmentCourse = assignmentCourse;
this.dueDate = dueDate;
this.validated = validated;
this.validatedBy = validatedBy;
this.createdBy = createdBy;
this.setValidated(getValidated());
}
public void setAssignmentName(String assignmentName) {
......@@ -100,8 +92,8 @@ public class Assignment {
@Override
public String toString() {
return "Name: " + assignmentName + ", Due Date: " + dueDate + ", Created by: " +
createdBy +", Validation: " + validated + ", Validated by: " + validatedBy;
return "Name: " + assignmentName + "\nDue Date: " + dueDate + "\nCreated by: " +
createdBy +"\nValid: " + validated + "\nValidated by: " + validatedBy;
}
}
......@@ -9,18 +9,21 @@ public class Course {
private String lecturer;
private Time startTime;
private Time endTime;
private List<Assignment> assignments;
private List<Assignment> assignments = new ArrayList<>();;
// public Course(){};
public Course(){ assignments = new ArrayList<>();}
public Course(){
this.assignments = getAssignments();
}
public Course(String courseName, String lecturer, Time startTime, Time endTime) {
this.courseName = courseName;
this.lecturer = lecturer;
this.startTime = startTime;
this.endTime = endTime;
this.assignments = getAssignments();
}
public Course(String courseName, String lecturer, Time startTime, Time endTime, List<Assignment> assignments) {
......@@ -77,12 +80,11 @@ public class Course {
for (Assignment a: assignments) {
if (a.getAssignmentName().equalsIgnoreCase(assignmentName)) {
return a;
}
}
}}
return null;
}
@Override
public String toString() {
return "\nCourse: " + courseName + ", Start Time: " + startTime + ", End Time: " + endTime + "\nAssignments: " + assignments;
return "\nCourse: " + courseName + "\nStart Time: " + startTime + "\nEnd Time: " + endTime + "\nAssignments: \n\s" + assignments;
}
}
......@@ -4,11 +4,13 @@ import Softeng.Group3.SiJadwal.actor.*;
import Softeng.Group3.SiJadwal.model.Assignment;
import Softeng.Group3.SiJadwal.model.Course;
import Softeng.Group3.SiJadwal.repository.UserList;
import org.checkerframework.checker.units.qual.A;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import java.sql.Time;
import java.time.LocalDate;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.*;
......@@ -137,12 +139,45 @@ public class AssignmentTest {
assertEquals(0, assignment.getValidatedBy().size());
}
@Test
void getDueDate() {
Assignment assignment = new Assignment();
assertNull(assignment.getDueDate());
}
@Test
void setDueDate() {
Assignment assignment = new Assignment();
assignment.setDueDate(LocalDate.parse("2021-06-07"));
assertEquals("2021-06-07", assignment.getDueDate().toString());
}
@Test
void testToString() {
Assignment assignment = new Assignment();
Course dummyRpl = new Course();
User dummyUser = new User();
dummyUser.setUsername("Haz");
assignment.setAssignmentName("ga33");
assignment.setAssignmentCourse(dummyRpl);
assignment.setCreatedBy(dummyUser);
assignment.setDueDate(LocalDate.parse("2021-06-07"));
assertEquals("Name: " + "ga33" + "\nDue Date: " + "2021-06-07" + "\nCreated by: " +
"Haz" +"\nValid: " + "false" + "\nValidated by: " + "[]", assignment.toString());
}
@Test
void getCreatedBy() {
Assignment assignment = new Assignment();
assertNull(assignment.getCreatedBy());
}
@Test
void setCreatedBy() {
Assignment assignment = new Assignment();
User dummyHaz = new User();
assignment.setCreatedBy(dummyHaz);
assertEquals(dummyHaz, assignment.getCreatedBy());
}
}
package model;
import Softeng.Group3.SiJadwal.actor.User;
import Softeng.Group3.SiJadwal.model.Assignment;
import Softeng.Group3.SiJadwal.model.Course;
import Softeng.Group3.SiJadwal.model.Timetable;
import org.checkerframework.checker.units.qual.A;
import org.checkerframework.checker.units.qual.C;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import java.sql.Time;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
......@@ -24,6 +28,7 @@ class CourseTest {
private Time startTime;
private Time endTime;
private Course testCourse;
private List<Assignment> assignments;
@BeforeEach
void setup() {
......@@ -31,7 +36,8 @@ class CourseTest {
lecturer = "Ade";
startTime = Time.valueOf("08:00:00");
endTime = Time.valueOf("09:40:00");
testCourse = new Course(courseName, lecturer, startTime, endTime);
assignments = new ArrayList<>();
testCourse = new Course(courseName, lecturer, startTime, endTime, assignments);
}
@Test
......@@ -79,5 +85,47 @@ class CourseTest {
testCourse.setEndTime(endTime2);
assertEquals(endTime2, testCourse.getEndTime());
}
@Test
void getAssignments() {
Course course = new Course("dummy", "dummyLecturer", Time.valueOf("08:00:00"), Time.valueOf("09:45:00"));
List<Assignment> assignments = new ArrayList<>();
assertEquals(assignments, course.getAssignments());
}
@Test
void addAssignment() {
Course newCourse = new Course();
Assignment dumAss = new Assignment();
newCourse.addAssignment(dumAss);
assertEquals(1, newCourse.getAssignments().size());
}
@Test
void getAssignment() {
Assignment dumass = new Assignment();
dumass.setAssignmentName("dumass");
testCourse.addAssignment(dumass);
assertEquals(dumass, testCourse.getAssignment("dumass"));
}
@Test
void testGetAssignmentAndNull() {
assertNull(testCourse.getAssignment("dumass"));
}
@Test
void deleteAssignment() {
Assignment toDelete = new Assignment();
testCourse.addAssignment(toDelete);
assertEquals(1, testCourse.getAssignments().size());
testCourse.deleteAssignment(toDelete);
assertEquals(0, testCourse.getAssignments().size());
}
@Test
void testToString() {
assertEquals("\nCourse: " + "RPL" + "\nStart Time: " + "08:00:00" + "\nEnd Time: " + "09:40:00" + "\nAssignments: \n\s" + "[]", testCourse.toString());
}
}
......@@ -3,6 +3,7 @@ package model;
import Softeng.Group3.SiJadwal.actor.User;
import Softeng.Group3.SiJadwal.model.Course;
import Softeng.Group3.SiJadwal.model.Timetable;
import org.checkerframework.checker.units.qual.C;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
......@@ -65,4 +66,13 @@ class TimetableTest {
timetable.addCourse(newCourse);
assertEquals(1, timetable.getCourses().size());
}
@Test
void deleteCourse() {
Course dumCourse = new Course();
timetable.addCourse(dumCourse);
assertEquals(1, timetable.getCourses().size());
timetable.deleteCourse(dumCourse);
assertEquals(0, timetable.getCourses().size());
}
}
\ 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