Browse Source

Added Gameinterface with TTT class and printTest

feature-game
Dion Aliu 3 years ago
parent
commit
9a6e8f1af4
  1. 8
      src/main/java/Game/Game.java
  2. 18
      src/main/java/Game/Tictactoe.java
  3. 44
      src/test/java/Game/TictactoeTest.java

8
src/main/java/Game/Game.java

@ -0,0 +1,8 @@
package Game;
public interface Game {
public abstract void print();
}

18
src/main/java/Game/Tictactoe.java

@ -0,0 +1,18 @@
package Game;
import java.util.ArrayList;
public class Tictactoe implements Game {
private ArrayList<String> outputBuffer = new ArrayList<String>();
@Override
public void print() {
for (int i = 0; i < outputBuffer.size(); i++) {
System.out.println(outputBuffer.get(i));
}
}
void setOutputBuffer(ArrayList<String> outputBuffer){
this.outputBuffer = outputBuffer;
}
}

44
src/test/java/Game/TictactoeTest.java

@ -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", ""));
}
}
Loading…
Cancel
Save