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.
43 lines
1.1 KiB
43 lines
1.1 KiB
package Game;
|
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
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 {
|
|
|
|
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
|
private final PrintStream originalOut = System.out;
|
|
|
|
Game game;
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
System.setOut(new PrintStream(outContent));
|
|
game = mock(Game.class, Mockito.CALLS_REAL_METHODS);
|
|
}
|
|
|
|
@AfterEach
|
|
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", ""));
|
|
}
|
|
}
|