77 lines
1.7 KiB
Java
77 lines
1.7 KiB
Java
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 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));
|
|
}
|
|
|
|
@AfterEach
|
|
public void tearDown() {
|
|
System.setOut(standardOut);
|
|
}
|
|
|
|
|
|
// Konstruktive Testfälle
|
|
|
|
/**
|
|
*
|
|
*/
|
|
@Test
|
|
public void placeOneField() {
|
|
game.placeField(1);
|
|
|
|
}
|
|
|
|
|
|
@Test
|
|
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());
|
|
}
|
|
|
|
} |