Fakultas Ilmu Komputer UI

Commit b80a35a3 authored by hazlazuardi's avatar hazlazuardi
Browse files

Added Assignment class and its unit test

parent f84fa060
Pipeline #81315 failed with stages
in 12 seconds
admin,Admin
st,Student
ta,Teaching Assistant
A,Student
B,Student
C,Student
......@@ -20,7 +20,6 @@ public class Student extends Role {
private TimetableList timetableList = new TimetableList();
// User currentUser = Main.currentUser;
@Override
public void exclusiveActions() {
System.out.println("6. Create a timetable");
......
package Softeng.Group3.SiJadwal.model;
import Softeng.Group3.SiJadwal.actor.Role;
import Softeng.Group3.SiJadwal.actor.RoleType;
import Softeng.Group3.SiJadwal.actor.User;
import java.util.HashSet;
import java.util.Set;
public class Assignment {
private String assignmentName;
private Course assignmentCourse;
private Boolean validated;
private Set<User> validatedBy = new HashSet<>();
private User createdBy;
public String getAssignmentName() {
return assignmentName;
}
public Assignment() {
}
public void setAssignmentName(String assignmentName) {
this.assignmentName = assignmentName;
}
public Course getAssignmentCourse() {
return assignmentCourse;
}
public void setAssignmentCourse(Course assignmentCourse) {
this.assignmentCourse = assignmentCourse;
}
public Boolean getValidated() {
return validationChecker();
}
public void setValidated(Boolean customValidated) {
this.validated = customValidated;
}
public Set<User> getValidatedBy() {
return validatedBy;
}
public void addValidatedBy(User user) {
this.validatedBy.add(user);
}
public void removeValidatedBy(User user) {
this.validatedBy.remove(user);
}
public void clearValidatedBy() {
this.validatedBy.clear();
}
public User getCreatedBy() {
return createdBy;
}
public void setCreatedBy(User createdBy) {
this.createdBy = createdBy;
}
private Boolean validationChecker() {
Set<User> bucket = new HashSet<>();
for (User u: this.validatedBy) {
if (u.getRole().getRoleName().equals(RoleType.STUDENT)) {
bucket.add(u);
}
if (u.getRole().getRoleName().equals(RoleType.TEACHING_ASSISTANT)) {
setValidated(true);
return true;
}
}
if (bucket.size() >= 3 ) {
setValidated(true);
return true;
}
return false;
}
}
package test;
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.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import java.sql.Time;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.*;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class AssignmentTest {
private final static UserList userList = new UserList();
@Test
void testIfThereAreThreeStudentInValidatedBy() {
User a = new User();
Role r = new Student();
r.setRoleName(RoleType.STUDENT);
Assignment assignment = new Assignment();
a.setUsername("A");
a.setRole(r.getRoleName());
userList.addUser(a.getUsername(), a.getRole().getRoleName());
User b = new User("B", r);
userList.addUser(b.getUsername(), b.getRole().getRoleName());
User c = new User("C", r);
userList.addUser(c.getUsername(), c.getRole().getRoleName());
Set<User> vdum = assignment.getValidatedBy();
assertEquals(0, vdum.size());
assignment.addValidatedBy(a);
assignment.addValidatedBy(b);
assignment.addValidatedBy(c);
assertEquals(3, vdum.size());
assertEquals(true, assignment.getValidated());
}
@Test
void testIfThereIsATeachingAssistantInValidatedBy() {
Role rt = new TeachingAssistant();
User t = new User("TA", rt);
rt.setRoleName(RoleType.TEACHING_ASSISTANT);
Assignment assignmentT = new Assignment();
assertEquals(0, assignmentT.getValidatedBy().size());
assignmentT.addValidatedBy(t);
assertEquals(1, assignmentT.getValidatedBy().size());
assertEquals(true, assignmentT.getValidated());
assignmentT.clearValidatedBy();
assertEquals(0, assignmentT.getValidatedBy().size());
}
@Test
void getAssignmentName() {
Assignment assignment = new Assignment();
assertNull(assignment.getAssignmentName());
}
@Test
void setAssignmentName() {
Assignment assignment = new Assignment();
assignment.setAssignmentName("Practical 10");
assertEquals("Practical 10", assignment.getAssignmentName());
}
@Test
void getAssignmentCourse() {
Assignment assignment = new Assignment();
assertNull(assignment.getAssignmentCourse());
}
@Test
void setAssignmentCourse() {
Assignment assignment = new Assignment();
Course rpl = new Course("RPL", "Ade", new Time(500), new Time(1000));
assignment.setAssignmentCourse(rpl);
assertEquals(rpl, assignment.getAssignmentCourse());
}
@Test
void getValidated() {
Assignment assignment = new Assignment();
assertEquals(false, assignment.getValidated());
}
@Test
void setValidated() {
Assignment assignment = new Assignment();
assignment.setValidated(true);
assertNotNull(assignment.getValidated());
}
@Test
void addValidatedBy() {
Assignment assignment = new Assignment();
User toAdd = new User();
assignment.addValidatedBy(toAdd);
assertEquals(1, assignment.getValidatedBy().size());
assertEquals(true, assignment.getValidatedBy().contains(toAdd));
}
@Test
void getValidatedBy() {
Assignment assignment = new Assignment();
assertEquals(0, assignment.getValidatedBy().size());
}
@Test
void removeValidatedBy() {
Assignment assignment = new Assignment();
User toRemove = new User();
assignment.addValidatedBy(toRemove);
assertEquals(1, assignment.getValidatedBy().size());
assignment.removeValidatedBy(toRemove);
assertEquals(false, assignment.getValidatedBy().contains(toRemove));
}
@Test
void clearValidatedBy() {
Assignment assignment = new Assignment();
assignment.addValidatedBy(new User());
assertEquals(1, assignment.getValidatedBy().size());
assignment.clearValidatedBy();
assertEquals(0, assignment.getValidatedBy().size());
}
@Test
void getCreatedBy() {
}
@Test
void setCreatedBy() {
}
}
Supports Markdown
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