InputAction extends AbstractTestAction { public String getVariable() { return variable; } InputAction(Builder builder); @Override void doExecute(TestContext context); String getMessage(); String getVariable(); String getValidAnswers(); static final String ANSWER_SEPARATOR; }
@Test public void testInput() throws IOException { reset(inputReader); when(inputReader.readLine()).thenReturn("yes"); InputAction input = new InputAction.Builder() .reader(inputReader) .message("Is that correct?") .build(); input.execute(context); Assert.assertEquals(context.getVariable("userinput"), "yes"); }
@Test public void testExistingInputVariable() { reset(inputReader); context.setVariable("userinput", "yes"); InputAction input = new InputAction.Builder() .reader(inputReader) .message("Is that correct?") .build(); input.execute(context); Assert.assertEquals(context.getVariable("userinput"), "yes"); }
@Test public void testValidAnswers() throws IOException { reset(inputReader); when(inputReader.readLine()).thenReturn("i dont know"); when(inputReader.readLine()).thenReturn("no"); InputAction input = new InputAction.Builder() .reader(inputReader) .message("Is that correct?") .answers("yes/no") .build(); input.execute(context); Assert.assertEquals(context.getVariable("userinput"), "no"); }