Content of file TicTacToeEvaluatorStrategyTest.java
package de.fhdw.gaming.ipspiel23.tictactoe.core.domain.impl;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import de.fhdw.gaming.core.domain.GameException;
import de.fhdw.gaming.ipspiel23.tictactoe.core.domain.TicTacToeBoard;
import de.fhdw.gaming.ipspiel23.tictactoe.core.domain.TicTacToeField;
import de.fhdw.gaming.ipspiel23.tictactoe.core.domain.TicTacToeFieldState;
import de.fhdw.gaming.ipspiel23.tictactoe.core.domain.TicTacToePlayer;
import de.fhdw.gaming.ipspiel23.tictactoe.core.domain.TicTacToePosition;
import de.fhdw.gaming.ipspiel23.tictactoe.core.domain.TicTacToeState;
import de.fhdw.gaming.ipspiel23.tictactoe.core.evaluation.MixedEvaluationStrategy;
/**
* Tests {@link MixedEvaluationStrategy}.
*/
public class TicTacToeEvaluatorStrategyTest {
/**
* Tests {@link MixedEvaluationStrategy#evaluateState(TicTacToeState)}.
*/
@Test
void testEvaluateState() throws GameException {
final TicTacToePlayer player1 = new TicTacToePlayerImpl("player1", true);
final TicTacToePlayer player2 = new TicTacToePlayerImpl("player2", false);
final TicTacToeBoard board = new TicTacToeBoardImpl(3);
final TicTacToeField field1 = board.getFieldAt(TicTacToePosition.of(0, 0));
final TicTacToeField field2 = board.getFieldAt(TicTacToePosition.of(0, 1));
final TicTacToeField field3 = board.getFieldAt(TicTacToePosition.of(0, 2));
field1.changeState(TicTacToeFieldState.CROSS);
field2.changeState(TicTacToeFieldState.CROSS);
field3.changeState(TicTacToeFieldState.CROSS);
final TicTacToeState state = new TicTacToeStateImpl(board, player1, player2, true);
final MixedEvaluationStrategy mixedStrat = new MixedEvaluationStrategy();
final Optional<Integer> result = mixedStrat.evaluateState(state);
assertTrue(result.isPresent());
assertTrue(result.get() > 0);
}
/**
* Tests {@link MixedEvaluationStrategy#evaluateState(TicTacToeState)}.
*/
@Test
void testEvaluateState2() throws GameException {
final TicTacToePlayer player1 = new TicTacToePlayerImpl("player1", true);
final TicTacToePlayer player2 = new TicTacToePlayerImpl("player2", false);
final TicTacToeBoard board = new TicTacToeBoardImpl(3);
final TicTacToeField field1 = board.getFieldAt(TicTacToePosition.of(0, 0));
final TicTacToeField field2 = board.getFieldAt(TicTacToePosition.of(0, 1));
final TicTacToeField field3 = board.getFieldAt(TicTacToePosition.of(0, 2));
field1.changeState(TicTacToeFieldState.CROSS);
field2.changeState(TicTacToeFieldState.CROSS);
field3.changeState(TicTacToeFieldState.CROSS);
final TicTacToeState state = new TicTacToeStateImpl(board, player1, player2, false);
final MixedEvaluationStrategy mixedStrat = new MixedEvaluationStrategy();
final Optional<Integer> result = mixedStrat.evaluateState(state);
assertTrue(result.isPresent());
assertFalse(result.get() > 0);
}
}
JUnit 5 tests should be package-private.
Reports JUnit 5 test classes and methods that are not package-private.
Contrary to JUnit 4 tests, which required public visibility to be run by the engine,
JUnit 5 tests can also be run if they're package-private. Marking them as such
is a good practice to limit their visibility.
Test methods are identified as those which use `@Test`, `@RepeatedTest`,
`@TestFactory`, `@TestTemplate` or `@ParameterizedTest`.
class MyTest { // not public, that's fine
@Test
public void testBad() { } // should not have a public modifier
@Test
protected void testAlsoBad() { } // should not have a protected modifier
@Test
private void testNoRun() { } // should not have a private modifier
@Test
void testGood() { } // package private as expected
}