Specification – planet information

The first thing we can do is pass the Planet object with the maximum X and Y axis coordinates to the Ship constructor. Fortunately, Planet is one more of the helper classes that have already been made (and tested). All we need to do is instantiate it and pass it to the Ship constructor:

public void whenInstantiatedThenPlanetIsStored() {
  Point max = new Point(50, 50);
  Planet planet = new Planet(max);
  ship = new Ship(location, planet);
  assertEquals(ship.getPlanet(), planet);
}

We're defining the size of the planet as 50 x 50 and passing that to the Planet class. In turn, that class is afterwards passed to the Ship constructor. You might have noticed that the constructor needs an extra argument. In the current ...

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.