IO { public <T extends Enum> T ask(T defaultValue, String format, Object... args) { return ask(defaultValue, String.format(format, args)); } IO(PrintStream out, PrintStream err, Input in, SubprocessBuilder subprocess);  IO();  IO(PrintStream out, PrintStream err, Input in); T ask(T defaultValue, String format, Object... args); T ask(T defaultValue, String prompt); final StatusPrintStream out; final PrintStreamPlus err; final Input in; final SubprocessBuilder subprocess; }
@Test(groups = "fast") public void testYes() { for (String yes : Arrays.asList("y", "yes", "Y", "YES", "Yes", "yES", "\n", "")) { MockIO io = new MockIO(yes); YesNo response = io.ask(YesNo.YES, "Did the %s test pass", yes); Assert.assertEquals(io.getOut(), "Did the " + yes + " test pass [Y/n]? "); Assert.assertEquals(io.getErr(), ""); Assert.assertEquals(response, YesNo.YES, String.format("Input [%s]:", yes)); Assert.assertTrue(response.isYes()); Assert.assertFalse(response.isNo()); } }
@Test(groups = "fast") public void testNo() { for (String no : Arrays.asList("n", "no", "N", "NO", "No", "nO", "\n", "")) { MockIO io = new MockIO(no); YesNo response = io.ask(YesNo.NO, "Did the %s test pass", no); Assert.assertEquals(io.getOut(), "Did the " + no + " test pass [y/N]? "); Assert.assertEquals(io.getErr(), ""); Assert.assertEquals(response, YesNo.NO, String.format("Input [%s]:", no)); Assert.assertTrue(response.isNo()); Assert.assertFalse(response.isYes()); } }
@Test(groups = "fast") public void testReprompt() { MockIO io = new MockIO("foo bar\nbaz\nyes\n"); YesNo response = io.ask(YesNo.NO, "Did the test pass"); Assert.assertEquals( io.getOut(), "Did the test pass [y/N]? Did the test pass [y/N]? Did the test pass [y/N]? "); Assert.assertEquals(io.getErr(), ""); Assert.assertEquals(response, YesNo.YES); }
@Test(groups = "fast") public void testNotAnnotated() { MockIO io = new MockIO(); try { io.ask(NotAnnotated.FOO, "Did the test pass"); Assert.fail("Expected exception"); } catch (IllegalArgumentException e) { Assert.assertEquals( e.getMessage(), "No fields annotated with @PromptAnswer in class com.facebook.tools.io.TestIO$NotAnnotated"); } }
@Test(groups = "fast") public void testUppercaseAnswer() { MockIO io = new MockIO(); try { io.ask(UppercaseAnswer.FOO, "Did the test pass"); Assert.fail("Expected exception"); } catch (IllegalArgumentException e) { Assert.assertEquals( e.getMessage(), "Values must be all lower-case, but got Test for " + "com.facebook.tools.io.TestIO$UppercaseAnswer.FOO"); } }