Specification – dealing with map boundaries

Like in other cases, the helper classes already provide all the functionality that we need. So far, we used the location.forward method without arguments. To implement wrapping, there is the overloaded location.forward(Point max) method that will wrap the location when we reach the end of the grid. With the previous specification, we made sure that Planet is passed to the Ship class and that it contains Point max. Our job is to make sure that max is used when moving forward. The specification can be the following:

public void whenOverpassingEastBoundaryThenPositionIsReset() { location.setDirection(Direction.EAST); location.getPoint().setX(planet.getMax().getX()); ship.receiveCommands("f"); assertEquals(location.getX(), ...

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.