O'Reilly logo

Test-Driven Java Development - Second Edition by Viktor Farcic, Alex Garcia

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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(), ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required