Fakultas Ilmu Komputer UI

Commit 464d47d4 authored by Jerome Zebua's avatar Jerome Zebua
Browse files

Student CLI test

parent 815cfbc1
Pipeline #81866 failed with stage
in 1 minute and 35 seconds
......@@ -10,7 +10,9 @@ import softeng.g4.user.Admin;
import softeng.g4.user.Student;
import softeng.g4.user.TeachingAssistant;
import softeng.g4.user.UserList;
import java.io.*;
import org.junit.*;
import java.util.Scanner;
import static org.junit.jupiter.api.Assertions.*;
class StudentCLITest {
......@@ -21,6 +23,12 @@ class StudentCLITest {
private TeachingAssistant testTa;
private Student testStudent;
private final InputStream systemIn = System.in;
private final PrintStream systemOut = System.out;
private ByteArrayInputStream testIn;
private ByteArrayOutputStream testOut;
@BeforeEach
void setUpTearDown() {
userList = new UserList();
......@@ -38,8 +46,40 @@ class StudentCLITest {
"Test Student", Long.valueOf("123456789"), userList);
}
@Before
public void setUpOutput() {
testOut = new ByteArrayOutputStream();
System.setOut(new PrintStream(testOut));
}
private void provideInput(String data) {
testIn = new ByteArrayInputStream(data.getBytes());
System.setIn(testIn);
}
private String getOutput() {
return testOut.toString();
}
@After
public void restoreSystemInputOutput() {
System.setIn(systemIn);
System.setOut(systemOut);
}
@Test
void main() {
String data1 = "HELP";
provideInput(data1);
StudentCLI.main(new String[1]);
assertEquals(data1, "HELP");
String data2 = "APPOINTMENTS";
StudentCLI.main(new String[2]);
assertEquals(data2, "APPOINTMENT");
}
@Test
......
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