|
|
@ -0,0 +1,44 @@ |
|
|
|
package Game; |
|
|
|
|
|
|
|
import org.junit.Rule; |
|
|
|
import org.junit.contrib.java.lang.system.SystemOutRule; |
|
|
|
import org.junit.jupiter.api.AfterEach; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.io.PrintStream; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
|
|
|
|
class TictactoeTest { |
|
|
|
|
|
|
|
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); |
|
|
|
private final PrintStream originalOut = System.out; |
|
|
|
|
|
|
|
Tictactoe ttt; |
|
|
|
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
|
void setUp() { |
|
|
|
ttt = new Tictactoe(); |
|
|
|
System.setOut(new PrintStream(outContent)); |
|
|
|
} |
|
|
|
|
|
|
|
@AfterEach |
|
|
|
void tearDown() { |
|
|
|
System.setOut(originalOut); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testPrint() { |
|
|
|
ArrayList<String> testOB = new ArrayList<String>(); |
|
|
|
testOB.add("Hello"); |
|
|
|
testOB.add("World"); |
|
|
|
testOB.add("!!!"); |
|
|
|
ttt.setOutputBuffer(testOB); |
|
|
|
ttt.print(); |
|
|
|
assertEquals("Hello\nWorld\n!!!\n", outContent.toString().replaceAll("\r", "")); |
|
|
|
} |
|
|
|
} |