Software concepts are often easiest to explain through code, and this one is no exception. We have seen and worked with the Tic-Tac-Toe application (see Chapter 3, Red-Green-Refactor – From Failure Through Success until Perfection). The following code performs position validation:
public class TicTacToe { public void validatePosition(int x, int y) { if (x < 1 || x > 3) { throw new RuntimeException("X is outside board"); } if (y < 1 || y > 3) { throw new RuntimeException("Y is outside board"); } } }
The specification that corresponds with this code is as follows:
public class TicTacToeSpec { @Rule public ExpectedException exception = ExpectedException.none(); private TicTacToe ticTacToe; @Before public final void before() ...