AbstractStep implements Step { protected void printMessageWithDefaultAnswer() { Optional<String> defaultAnswer = getDefaultAnswer(); String message = getMessage(); if (defaultAnswer.isPresent()) { String defaultAnswerValue = defaultAnswer.get(); if (message != null && containsPlaceholder(message, Placeholder.DEFAULT_ANSWER)) { message = replacePlaceholders(message, new HashMap<Placeholder, String>() { { put(Placeholder.DEFAULT_ANSWER, defaultAnswerValue); } }); } else { message = String.format("%s [%s]", message, defaultAnswerValue); } } logger.ok(message); }    }
@Test public void testPrintMessageWithDefaultAnswer() { mockAbstractStep.setMessage("test-message"); mockAbstractStep.setDefaultAnswer(DEFAULT_ANSWER); mockAbstractStep.printMessageWithDefaultAnswer(); assertThat(logger.getOkMessages(), contains("test-message [default-answer]")); }
@Test public void testPrintMessageContainingPlaceholderWithDefaultAnswer() { mockAbstractStep.setMessage("test $defaultAnswer message"); mockAbstractStep.setDefaultAnswer(DEFAULT_ANSWER); mockAbstractStep.printMessageWithDefaultAnswer(); assertThat(logger.getOkMessages(), contains("test default-answer message")); }
@Test public void testPrintMessageWithNoDefaultAnswer() { mockAbstractStep.setMessage("test-message"); mockAbstractStep.printMessageWithDefaultAnswer(); assertThat(logger.getOkMessages(), contains("test-message")); }