Game.java
+ Implementented method PlaceMethod completely + Implemented method CheckForTie * Changed checkForWin into else Language.java + Added outputSeparator() + Added outputGameStartedText() + Added outputMoveText() GameTest.java Added Tests to catch System out printlns
This commit is contained in:
+63
-22
@@ -1,36 +1,77 @@
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Assert;
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* Klasse GameTest
|
||||
*
|
||||
* Diese Klasse beinhaltet und führt alle Testfälle für die Klasse GameTest aus
|
||||
*
|
||||
*/
|
||||
class GameTest {
|
||||
|
||||
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
||||
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
|
||||
private final PrintStream originalOut = System.out;
|
||||
private final PrintStream originalErr = System.err;
|
||||
|
||||
@Before
|
||||
public void setUpStreams() {
|
||||
System.setOut(new PrintStream(outContent));
|
||||
System.setErr(new PrintStream(errContent));
|
||||
private final PrintStream standardOut = System.out;
|
||||
private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
|
||||
|
||||
private Game game = new Game();
|
||||
|
||||
@BeforeEach
|
||||
public void beforeEach() {
|
||||
game = new Game();
|
||||
System.setOut(new PrintStream(outputStreamCaptor));
|
||||
}
|
||||
|
||||
@After
|
||||
public void restoreStreams() {
|
||||
System.setOut(originalOut);
|
||||
System.setErr(originalErr);
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
System.setOut(standardOut);
|
||||
}
|
||||
|
||||
|
||||
// Konstruktive Testfälle
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void placeOneField() {
|
||||
game.placeField(1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void checkTest() {
|
||||
System.out.println("hello");
|
||||
assertEquals("hello", outContent.toString());
|
||||
public void testGameShouldbeTie() {
|
||||
game.placeField(1);
|
||||
game.placeField(2);
|
||||
game.placeField(3);
|
||||
game.placeField(5);
|
||||
game.placeField(4);
|
||||
game.placeField(6);
|
||||
game.placeField(8);
|
||||
game.placeField(7);
|
||||
game.placeField(9);
|
||||
}
|
||||
|
||||
|
||||
// Destruktive Testfälle
|
||||
|
||||
@Test
|
||||
public void placeNotExistingField() {
|
||||
|
||||
System.out.println("Hello Baeldung Readers!!");
|
||||
System.out.println("Hello Baeldung Readers!!");
|
||||
System.out.println("Hello Baeldung Readers!!");
|
||||
System.out.println("Hello Baeldung Readers!!");
|
||||
|
||||
Assert.assertEquals("Hello Baeldung Readers!!\n" +
|
||||
"Hello Baeldung Readers!!\n" +
|
||||
"Hello Baeldung Readers!!\n" +
|
||||
"Hello Baeldung Readers!!", outputStreamCaptor.toString()
|
||||
.trim());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user