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 – combined commands

Now that we are able to process one command (whatever that the command is), it is time to add the option to send a string of commands. The specification can be the following:

public void whenReceiveCommandsThenAllAreExecuted() {
  Location expected = location.copy();
  expected.turnRight();
  expected.forward();
  expected.turnLeft();
  expected.backward();
  ship.receiveCommands("rflb");
  assertEquals(ship.getLocation(), expected);
}

This is a bit longer, but is still not an overly complicated specification. We're passing commands rflb (right, forwards, left, and backwards) and expecting that the Location changes accordingly. As before, we're not verifying the end result (seeing whether the if coordinates have changed), ...

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