You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.3 KiB

  1. package Application;
  2. import org.junit.jupiter.api.AfterEach;
  3. import org.junit.jupiter.api.BeforeEach;
  4. import org.junit.jupiter.api.Test;
  5. import java.io.ByteArrayInputStream;
  6. import java.io.ByteArrayOutputStream;
  7. import java.io.PrintStream;
  8. import static org.junit.jupiter.api.Assertions.*;
  9. class AppTest {
  10. private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
  11. private final ByteArrayInputStream inContent = new ByteArrayInputStream("1\n2\nq\n".getBytes());
  12. App app;
  13. Cli cli;
  14. @BeforeEach
  15. void setUp() {
  16. cli = new Cli(new PrintStream(outContent), inContent);
  17. cli.setClearConsoleActive(false);
  18. app = new App(cli);
  19. }
  20. @AfterEach
  21. void tearDown() {
  22. }
  23. //inContent has the 'q' at the end, to terminated the loop and set isRunning to false
  24. @Test
  25. void stop() {
  26. ByteArrayInputStream input = new ByteArrayInputStream("1\n2\nq\n".getBytes());
  27. cli = new Cli(new PrintStream(outContent), input);
  28. cli.setClearConsoleActive(false);
  29. app = new App(cli);
  30. app.start();
  31. assertFalse(app.isRunning());
  32. }
  33. @Test
  34. void selectMenuItem() {
  35. assertNull(app.getCurrentGame());
  36. app.selectMenuItem("1");
  37. assertNull(app.getCurrentGame());
  38. app.selectMenuItem("2");
  39. assertNotNull(app.getCurrentGame());
  40. }
  41. }