|
@ -2,42 +2,17 @@ package Game; |
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.AfterEach; |
|
|
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.mockito.Mockito; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
|
|
import java.io.PrintStream; |
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
|
|
|
|
|
|
|
|
class GameTest { |
|
|
class GameTest { |
|
|
|
|
|
|
|
|
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); |
|
|
|
|
|
private final PrintStream originalOut = System.out; |
|
|
|
|
|
|
|
|
|
|
|
Game game; |
|
|
|
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
@BeforeEach |
|
|
void setUp() { |
|
|
void setUp() { |
|
|
System.setOut(new PrintStream(outContent)); |
|
|
|
|
|
game = mock(Game.class, Mockito.CALLS_REAL_METHODS); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@AfterEach |
|
|
@AfterEach |
|
|
void tearDown() { |
|
|
void tearDown() { |
|
|
System.setOut(originalOut); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void print() { |
|
|
|
|
|
ArrayList<String> testOB = new ArrayList<>(); |
|
|
|
|
|
testOB.add("Hello"); |
|
|
|
|
|
testOB.add("World"); |
|
|
|
|
|
testOB.add("!!!"); |
|
|
|
|
|
game.setOutputBuffer(testOB); |
|
|
|
|
|
game.print(); |
|
|
|
|
|
assertEquals("Hello\nWorld\n!!!\n", outContent.toString().replaceAll("\r", "")); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |