@Test public void whenSelectActionAddInputTwoNumbersAndRepeatThenResultTwoNumbers() { try (ByteArrayOutputStream output = new ByteArrayOutputStream(); ByteArrayInputStream input = new ByteArrayInputStream("1\r\n15\r\n5\r\ny\r\nn\r\n0".getBytes())) { System.setOut(new PrintStream(output)); System.setIn(input); new InteractCalc().initDialog(); assertThat(output.toString().contains("is 25.0"), is(true)); } catch (IOException ioe) { ioe.printStackTrace(); } }
public void initDialog() { Calculator calc = new Calculator(); ActionManager manager = new ActionManager(); while (!isExit) { manager.showMenu(); int userAction = askUserAction(manager.getActionsLength()); isExit = userAction == 0; if (!isExit) { Action action = manager.select(userAction - 1); double numberOne = askUserNumber("first"); double numberTwo = askUserNumber("second"); action.execute(calc, numberOne, numberTwo); printResult(calc, action); while (sc.hasNextLine() && sc.nextLine().equals("y")) { action.execute(calc, calc.getResult(), numberTwo); printResult(calc, action); } } } }
InteractCalc { public void initDialog() { Calculator calc = new Calculator(); ActionManager manager = new ActionManager(); while (!isExit) { manager.showMenu(); int userAction = askUserAction(manager.getActionsLength()); isExit = userAction == 0; if (!isExit) { Action action = manager.select(userAction - 1); double numberOne = askUserNumber("first"); double numberTwo = askUserNumber("second"); action.execute(calc, numberOne, numberTwo); printResult(calc, action); while (sc.hasNextLine() && sc.nextLine().equals("y")) { action.execute(calc, calc.getResult(), numberTwo); printResult(calc, action); } } } } }
InteractCalc { public void initDialog() { Calculator calc = new Calculator(); ActionManager manager = new ActionManager(); while (!isExit) { manager.showMenu(); int userAction = askUserAction(manager.getActionsLength()); isExit = userAction == 0; if (!isExit) { Action action = manager.select(userAction - 1); double numberOne = askUserNumber("first"); double numberTwo = askUserNumber("second"); action.execute(calc, numberOne, numberTwo); printResult(calc, action); while (sc.hasNextLine() && sc.nextLine().equals("y")) { action.execute(calc, calc.getResult(), numberTwo); printResult(calc, action); } } } }  }
InteractCalc { public void initDialog() { Calculator calc = new Calculator(); ActionManager manager = new ActionManager(); while (!isExit) { manager.showMenu(); int userAction = askUserAction(manager.getActionsLength()); isExit = userAction == 0; if (!isExit) { Action action = manager.select(userAction - 1); double numberOne = askUserNumber("first"); double numberTwo = askUserNumber("second"); action.execute(calc, numberOne, numberTwo); printResult(calc, action); while (sc.hasNextLine() && sc.nextLine().equals("y")) { action.execute(calc, calc.getResult(), numberTwo); printResult(calc, action); } } } }  void initDialog(); }
InteractCalc { public void initDialog() { Calculator calc = new Calculator(); ActionManager manager = new ActionManager(); while (!isExit) { manager.showMenu(); int userAction = askUserAction(manager.getActionsLength()); isExit = userAction == 0; if (!isExit) { Action action = manager.select(userAction - 1); double numberOne = askUserNumber("first"); double numberTwo = askUserNumber("second"); action.execute(calc, numberOne, numberTwo); printResult(calc, action); while (sc.hasNextLine() && sc.nextLine().equals("y")) { action.execute(calc, calc.getResult(), numberTwo); printResult(calc, action); } } } }  void initDialog();  }