|
@ -4,7 +4,9 @@ import org.junit.jupiter.api.AfterEach; |
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
import java.io.ByteArrayOutputStream; |
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
|
|
import java.io.InputStream; |
|
|
import java.io.PrintStream; |
|
|
import java.io.PrintStream; |
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
@ -13,23 +15,34 @@ class CliTest { |
|
|
|
|
|
|
|
|
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); |
|
|
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); |
|
|
private final PrintStream originalOut = System.out; |
|
|
private final PrintStream originalOut = System.out; |
|
|
|
|
|
private final ByteArrayInputStream inContent = new ByteArrayInputStream("Test".getBytes()); |
|
|
|
|
|
private final InputStream originalIn = System.in; |
|
|
|
|
|
|
|
|
Cli cli; |
|
|
Cli cli; |
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
@BeforeEach |
|
|
void setUp() { |
|
|
void setUp() { |
|
|
System.setOut(new PrintStream(outContent)); |
|
|
System.setOut(new PrintStream(outContent)); |
|
|
cli = new Cli(System.out); |
|
|
|
|
|
|
|
|
System.setIn(inContent); |
|
|
|
|
|
cli = new Cli(System.out, System.in); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@AfterEach |
|
|
@AfterEach |
|
|
void tearDown() { |
|
|
void tearDown() { |
|
|
System.setOut(originalOut); |
|
|
System.setOut(originalOut); |
|
|
|
|
|
System.setIn(originalIn); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Only tests correct stream integration, other methods are provided |
|
|
@Test |
|
|
@Test |
|
|
void getPrintStream() { |
|
|
void getPrintStream() { |
|
|
cli.getPrintStream().println("Hello World!"); |
|
|
cli.getPrintStream().println("Hello World!"); |
|
|
assertEquals("Hello World!\n", outContent.toString().replaceAll("\r", "")); |
|
|
assertEquals("Hello World!\n", outContent.toString().replaceAll("\r", "")); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Only tests correct stream integration, other methods are provided |
|
|
|
|
|
@Test |
|
|
|
|
|
void getScanner() { |
|
|
|
|
|
assertEquals(cli.getScanner().next(), "Test"); |
|
|
|
|
|
} |
|
|
} |
|
|
} |