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.

42 lines
1.1 KiB

  1. package Game;
  2. import org.junit.jupiter.api.AfterEach;
  3. import org.junit.jupiter.api.BeforeEach;
  4. import org.junit.jupiter.api.Test;
  5. import org.mockito.Mockito;
  6. import java.io.ByteArrayOutputStream;
  7. import java.io.PrintStream;
  8. import java.util.ArrayList;
  9. import static org.junit.jupiter.api.Assertions.*;
  10. import static org.mockito.Mockito.mock;
  11. class GameTest {
  12. private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
  13. private final PrintStream originalOut = System.out;
  14. Game game;
  15. @BeforeEach
  16. void setUp() {
  17. System.setOut(new PrintStream(outContent));
  18. game = mock(Game.class, Mockito.CALLS_REAL_METHODS);
  19. }
  20. @AfterEach
  21. void tearDown() {
  22. System.setOut(originalOut);
  23. }
  24. @Test
  25. public void print() {
  26. ArrayList<String> testOB = new ArrayList<>();
  27. testOB.add("Hello");
  28. testOB.add("World");
  29. testOB.add("!!!");
  30. game.setOutputBuffer(testOB);
  31. game.print();
  32. assertEquals("Hello\nWorld\n!!!\n", outContent.toString().replaceAll("\r", ""));
  33. }
  34. }