Fakultas Ilmu Komputer UI

Commit 7140cd27 authored by Bagus Prabowo's avatar Bagus Prabowo
Browse files

UserList Test

parent 0d10d3fe
admin,Admin
st,Student
ta,Teaching Assistant
a,Student
b,Teaching Assistant
ta,Teaching Assistant
\ No newline at end of file
......@@ -47,12 +47,12 @@ public class User {
}
}
public void listToString(List<Timetable> timetableList){
int i = 1;
for (Timetable timetable: timetableList) {
System.out.println(i + ". " + timetable.getTimetableName());
i++;
}
}
// public void listToString(List<Timetable> timetableList){
// int i = 1;
// for (Timetable timetable: timetableList) {
// System.out.println(i + ". " + timetable.getTimetableName());
// i++;
// }
// }
}
......@@ -3,30 +3,27 @@ package test;
import Softeng.Group3.SiJadwal.actor.User;
import Softeng.Group3.SiJadwal.model.Course;
import Softeng.Group3.SiJadwal.model.Timetable;
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.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TimetableTest {
private User owner;
private List<Course> courses;
private String timetableName;
private Timetable timetable;
@BeforeEach
void setup() {
owner = new User();
courses = new ArrayList<>();
timetableName = "Semester 5";
String timetableName = "Semester 5";
timetable = new Timetable(timetableName, courses, owner);
}
......
package test;
import Softeng.Group3.SiJadwal.actor.RoleType;
import Softeng.Group3.SiJadwal.repository.UserList;
import Softeng.Group3.SiJadwal.actor.User;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
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)
class UserListTest {
private static final UserList userList = new UserList();
private final PrintStream standardOut = System.out;
private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
@Test
void getUserList(){
userList.addUser("Test", RoleType.STUDENT);
List<User> TestList = userList.getUserList();
assertNotEquals(null, TestList);
}
@Test
void getUsernameTest(){
userList.addUser("Test", RoleType.STUDENT);
User TestGetUser = userList.getUser("Test");
assertEquals("Test", TestGetUser.getUsername());
}
@Test
void addUserTest(){
int initial = userList.getUserList().size();
userList.addUser("Test", RoleType.STUDENT);
int after = userList.getUserList().size();
assertEquals(initial + 1, after);
}
@Test
void updateRoleTest(){
userList.addUser("Test", RoleType.STUDENT);
userList.updateRole("Test", RoleType.TEACHING_ASSISTANT);
User TestRole = userList.getUser("Test");
System.out.println(TestRole.getRole());
assertEquals(RoleType.TEACHING_ASSISTANT, TestRole.getRole().getRoleName());
}
@Test
void ListToStringTest(){
System.setOut(new PrintStream(outputStreamCaptor));
userList.addUser("Test", RoleType.STUDENT);
userList.listToString(userList.getUserList());
assertEquals("1. Test", outputStreamCaptor.toString().trim());
System.setOut(standardOut);
}
}
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