|
@ -0,0 +1,42 @@ |
|
|
|
|
|
package Application; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.AfterEach; |
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.*; |
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
|
|
import static org.mockito.Mockito.when; |
|
|
|
|
|
|
|
|
|
|
|
class AppTest { |
|
|
|
|
|
|
|
|
|
|
|
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); |
|
|
|
|
|
private final ByteArrayInputStream inContent = new ByteArrayInputStream("1\n2\nq\n".getBytes()); |
|
|
|
|
|
|
|
|
|
|
|
App app; |
|
|
|
|
|
Cli cli; |
|
|
|
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
|
|
|
void setUp() { |
|
|
|
|
|
cli = new Cli(new PrintStream(outContent), inContent); |
|
|
|
|
|
app = new App(cli); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@AfterEach |
|
|
|
|
|
void tearDown() { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//inContent has the 'q' at the end, to terminated the loop and set isRunning to false |
|
|
|
|
|
@Test |
|
|
|
|
|
void stop() { |
|
|
|
|
|
ByteArrayInputStream input = new ByteArrayInputStream("1\n2\nq\n".getBytes()); |
|
|
|
|
|
cli = new Cli(new PrintStream(outContent), input); |
|
|
|
|
|
app = new App(cli); |
|
|
|
|
|
app.start(); |
|
|
|
|
|
assertFalse(app.isRunning()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |