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

Requirement – handling invalid input

Provided that our implementation is basically doing nothing, we are going to focus only on one thing—reading single operands. If the input is a single number (no operators) then it's a valid reverse notation and the value of the number is returned. Anything other than that is considered not a valid RPN for now.

This requirement is translated into these four tests:

public class ReversePolishNotationTest {  private ReversePolishNotation reversePolishNotation =    new ReversePolishNotation();  @Test(expected = NotReversePolishNotationError.class)  public void emptyInputThrowsError() {    reversePolishNotation.compute("");  }  @Test(expected = NotReversePolishNotationError.class) public void notANumberThrowsError() { ...

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