@Test public void invalidChar() throws Exception { try { calculator.enter('A'); throw new AssertionFailureNotDetectedError(); } catch (IllegalArgumentException e) { assertEquals(e.getMessage(), "Character 'A' is not supported"); } }
public void enter(char c) { switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': state.processDigit(c); break; case '.': state.processDot(); break; case '+': case '-': case '/': case '*': state.processOperator(c); break; case '=': state.processEquals(); break; case 'C': state = new EnteringFirstOperandState('0'); break; default: throw new IllegalArgumentException("Character '" + c + "' is not supported"); } }
Calculator { public void enter(char c) { switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': state.processDigit(c); break; case '.': state.processDot(); break; case '+': case '-': case '/': case '*': state.processOperator(c); break; case '=': state.processEquals(); break; case 'C': state = new EnteringFirstOperandState('0'); break; default: throw new IllegalArgumentException("Character '" + c + "' is not supported"); } } }
Calculator { public void enter(char c) { switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': state.processDigit(c); break; case '.': state.processDot(); break; case '+': case '-': case '/': case '*': state.processOperator(c); break; case '=': state.processEquals(); break; case 'C': state = new EnteringFirstOperandState('0'); break; default: throw new IllegalArgumentException("Character '" + c + "' is not supported"); } } Calculator(); }
Calculator { public void enter(char c) { switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': state.processDigit(c); break; case '.': state.processDot(); break; case '+': case '-': case '/': case '*': state.processOperator(c); break; case '=': state.processEquals(); break; case 'C': state = new EnteringFirstOperandState('0'); break; default: throw new IllegalArgumentException("Character '" + c + "' is not supported"); } } Calculator(); void enter(char c); String getCurrentValue(); }
Calculator { public void enter(char c) { switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': state.processDigit(c); break; case '.': state.processDot(); break; case '+': case '-': case '/': case '*': state.processOperator(c); break; case '=': state.processEquals(); break; case 'C': state = new EnteringFirstOperandState('0'); break; default: throw new IllegalArgumentException("Character '" + c + "' is not supported"); } } Calculator(); void enter(char c); String getCurrentValue(); static final DecimalFormat FORMAT; }