Browse Source

tictactoe: refactored test code to use one game instance object for all test cases

tictactoe
Malte Schellhardt 3 years ago
committed by Lorenz Hohmann
parent
commit
46b1605e31
  1. 20
      src/test/java/de/tims/tictactoe/GameLogicTest.java

20
src/test/java/de/tims/tictactoe/GameLogicTest.java

@ -3,33 +3,31 @@ package de.tims.tictactoe;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(Lifecycle.PER_CLASS)
class GameLogicTest {
private int size = 3;
private GameLogic game = new GameLogic(size);
private final int SIZE = 3;
private GameLogic game;
@BeforeAll
static void setUpBeforeClass() throws Exception {
}
@BeforeEach
void setUp() throws Exception {
void setUpBeforeClass() throws Exception {
this.game = new GameLogic(SIZE);
}
@Test
void createGameLogicTest() {
GameLogic expectedResult = this.game;
GameLogic realResult = new GameLogic(size);
GameLogic realResult = new GameLogic(SIZE);
assertEquals(expectedResult.getClass(), realResult.getClass());
}
@ -79,7 +77,7 @@ class GameLogicTest {
{'-', '-', '-'},
{'-', '-', '-'}}),
Arguments.of("set field [1][0] for player 2", 1, 0, 'o', new char[][]
{{'-', '-', '-'},
{{'x', '-', '-'},
{'o', '-', '-'},
{'-', '-', '-'}})
);

Loading…
Cancel
Save