Args { public String chomp() { if (args.length > index) { return args[index++]; } throw new ArrayIndexOutOfBoundsException("No args left to chomp. Please use canChomp()."); } Args(String[] args); String chomp(); boolean canChomp(); boolean canChomp(int numArgs); String peek(); boolean canPeek();  }
@Test public void cannotChompMoreThanExpectedNumberOfTimes() throws Exception { expectedException.expect(ArrayIndexOutOfBoundsException.class); expectedException.expectMessage("No args left to chomp. Please use canChomp()."); final Args args = new Args(new String[]{"1", "2", "3"}); args.chomp(); args.chomp(); args.chomp(); args.chomp(); }