AbstractStep implements Step { protected String waitForAnswer() { try { ConsoleReader consoleReader = getConsoleReader(); String answer = consoleReader.readLine(); Optional<String> defaultAnswer = getDefaultAnswer(); return answer.isEmpty() && defaultAnswer.isPresent() ? defaultAnswer.get() : answer; } catch (Exception e) { logger.error(String.format("Error while getting input: %s", e.getMessage())); return ""; } }    }
@Test public void testWaitForAnswer() throws Exception { mockAbstractStep.setConsoleReader(mockConsoleReader("test-answer\n")); String answer = mockAbstractStep.waitForAnswer(); assertThat(answer, equalTo("test-answer")); }