Fakultas Ilmu Komputer UI

Commit bcc28da5 authored by Bagus Prabowo's avatar Bagus Prabowo
Browse files

CourseList Test

parent d77ba3c9
Pipeline #82000 passed with stages
in 6 minutes and 3 seconds
rpl,ade,1:01:01,1:01:02
adpro,daya,5:05:05,7:07:07
daa,there,4:04:04,13:01:01
random,abc,01:00:00,01:00:01
package repository;
import Softeng.Group3.SiJadwal.model.Course;
import Softeng.Group3.SiJadwal.repository.CourseList;
import Softeng.Group3.SiJadwal.model.Assignment;
import org.checkerframework.checker.units.qual.A;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.sql.Time;
import java.util.List;
import java.lang.System;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class CourseListTest {
private static final CourseList courseList = new CourseList();
private final PrintStream standardOut = System.out;
private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
private Course course;
@BeforeEach
void setup() {
course = new Course();
course.setCourseName("random");
course.setStartTime(Time.valueOf("1:00:00"));
course.setEndTime(Time.valueOf("1:00:01"));
course.setLecturer("dummy");
}
@Test
void getCourseListTest(){
courseList.addCourse(course.getCourseName(), course.getLecturer(), course.getStartTime(), course.getEndTime());
List<Course> test = courseList.getCourseList();
assertNotEquals(null, test);
}
@Test
void getCourseTest(){
courseList.addCourse(course.getCourseName(), course.getLecturer(), course.getStartTime(), course.getEndTime());
Course test = courseList.getCourse(course.getCourseName());
assertEquals("random", test.getCourseName());
}
@Test
void addCourseTest(){
int initial = courseList.getCourseList().size();
courseList.addCourse(course.getCourseName(), course.getLecturer(), course.getStartTime(), course.getEndTime());
int after = courseList.getCourseList().size();
assertEquals(initial + 1, after);
}
@Test
void deleteCourseTest(){
courseList.addCourse(course.getCourseName(), course.getLecturer(), course.getStartTime(), course.getEndTime());
int initial = courseList.getCourseList().size();
courseList.deleteCourse(course.getCourseName());
int after = courseList.getCourseList().size();
assertEquals(initial - 1, after);
}
@Test
void ListtoStringTest(){
courseList.addCourse(course.getCourseName(), course.getLecturer(), course.getStartTime(), course.getEndTime());
System.setOut(new PrintStream(outputStreamCaptor));
courseList.listToString(courseList.getCourseList());
assertEquals("1. random", outputStreamCaptor.toString().trim());
System.setOut(standardOut);
}
@Test
void updateCourseTest(){
courseList.addCourse(course.getCourseName(), course.getLecturer(), course.getStartTime(), course.getEndTime());
courseList.updateCourse(course.getCourseName(), "abc", course.getStartTime(), course.getEndTime());
Course newCourse = courseList.getCourse(course.getCourseName());
String lecturer = newCourse.getLecturer();
assertEquals("abc", lecturer);
}
}
\ 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