Implementation

The implementation of this specification is almost the same as the previous one. All we have to do is throw an exception if y does not fall within the defined range:

public void play(int x, int y) {
  if (x < 1 || x > 3) {
    throw new RuntimeException("X is outside board");
  } else if (y < 1 || y > 3) {
    throw new RuntimeException("Y is outside board");
  }
}

In order for the last test to pass, we had to add the else clause that checks whether Y is inside the board.

Let's do the last test for this requirement.

Get Test-Driven Java Development - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.