### Question:
ReversePolishNotation { int compute(String expression) { Stack<Integer> stack = new Stack<>(); for (String elem : expression.trim().split(" ")) { if ("+".equals(elem)) applyOperation(stack, ADD); else if ("-".equals(elem)) applyOperation(stack, SUBTRACT); else if ("*".equals(elem)) applyOperation(stack, MULTIPLY); else if ("/".equals(elem)) applyOperation(stack, DIVIDE); else { stack.push(parseInt(elem)); } } if (stack.size() == 1) return stack.pop(); else throw new NotReversePolishNotationError(); }    }### Answer:
@Test(expected = NotReversePolishNotationError.class) public void emptyInputThrowsError() { reversePolishNotation.compute(""); }
@Test(expected = NotReversePolishNotationError.class) public void notANumberThrowsError() { reversePolishNotation.compute("a"); }
@Test public void oneDigitReturnsNumber() { assertThat(reversePolishNotation.compute("0")).isEqualTo(0); }
@Test public void moreThanOneDigitReturnsNumber() { assertThat(reversePolishNotation.compute("120")).isEqualTo(120); }
@Test public void addOperationReturnsCorrectValue() { assertThat(reversePolishNotation.compute("1 2 +")).isEqualTo(3); }
@Test public void subtractOperationReturnsCorrectValue() { assertThat(reversePolishNotation.compute("2 1 -")).isEqualTo(1); }
@Test public void multiplyOperationReturnsCorrectValue() { assertThat(reversePolishNotation.compute("2 1 *")).isEqualTo(2); }
@Test public void divideOperationReturnsCorrectValue() { assertThat(reversePolishNotation.compute("2 2 /")).isEqualTo(1); }
@Test public void multipleAddOperationsReturnCorrectValue() { assertThat(reversePolishNotation.compute("1 2 5 + +")).isEqualTo(8); }
@Test public void multipleDifferentOperationsReturnCorrectValue() { assertThat(reversePolishNotation.compute("5 12 + 3 -")).isEqualTo(14); }
@Test public void aComplexTest() { assertThat(reversePolishNotation.compute("5 1 2 + 4 * + 3 -")).isEqualTo(14); }