OptionProcessor { public OptionBuilder newOption(E longOption) { return new OptionBuilder(longOption); }  static OptionProcessor<T> create(); OptionBuilder newOption(E longOption); List<String> process(List<String> args); boolean has(E longOption); void set(E longOption); void unset(E longOption); void set(E longOption, String argument); String get(E longOption); int getInteger(E longOption); double getDouble(E longOption); float getFloat(E longOption); @Override String toString();  }
@Test(expected = IllegalArgumentException.class) public void testRegisterTwiceDiffCaseLongDiffShort() { op.newOption(alpha).shortOption('a').done(); op.newOption("Alpha").shortOption('A').done(); }
@Test(expected = IllegalArgumentException.class) public void testRegisterTwiceShort() { op.newOption(alpha).shortOption('a').done(); op.newOption(bravo).shortOption('a').done(); }
@SuppressWarnings("rawtypes") @Test(expected = IllegalStateException.class) public void testRegisterPostmod1() { OptionBuilder b = op.newOption(alpha).shortOption('a'); b.done(); b.shortOption('a'); }
@SuppressWarnings("rawtypes") @Test(expected = IllegalStateException.class) public void testRegisterPostmod2() { OptionBuilder b = op.newOption(alpha).shortOption('a'); b.done(); b.noArg(); }
@SuppressWarnings("rawtypes") @Test(expected = IllegalStateException.class) public void testRegisterPostmod3() { OptionBuilder b = op.newOption(alpha).shortOption('a'); b.done(); b.optionalArg(); }
@SuppressWarnings("rawtypes") @Test(expected = IllegalStateException.class) public void testRegisterPostmod4() { OptionBuilder b = op.newOption(alpha).shortOption('a'); b.done(); b.requiredArg(); }
@SuppressWarnings("rawtypes") @Test(expected = IllegalStateException.class) public void testRegisterTwice() { OptionBuilder b = op.newOption(alpha).shortOption('a'); b.done(); b.done(); }
@Test(expected = IllegalArgumentException.class) public void testRegisterTwiceLongDifferentType() { op.newOption(bravo).noArg().done(); op.newOption(bravo).optionalArg().done(); }
@Test(expected = IllegalArgumentException.class) public void testRegisterDash() { op.newOption("-").done(); }
@Test(expected = IllegalArgumentException.class) public void testRegisterEmptyLong() { op.newOption("").done(); }
@Test public void testRegisterIllegalCharacters() { for (char i = Character.MIN_VALUE; i < Character.MAX_VALUE; ++i) { if (!Character.isLetter(i)) { try { op.newOption(String.valueOf(i)).done(); throw new AssertionError( "Should have rejected long option " + i); } catch (IllegalArgumentException e) { } try { op.newOption(alpha).shortOption(Character.valueOf(i)) .done(); throw new AssertionError( "Should have rejected short option " + i); } catch (IllegalArgumentException e) { } } } }
@Test(expected = IllegalArgumentException.class) public void testRegisterIllegalOptionNumber1() throws SoarException { op.newOption("640").done(); }
@Test(expected = IllegalArgumentException.class) public void testRegisterIllegalOptionNumber2() throws SoarException { op.newOption("1eet").done(); }
@Test public void testMultipleOptions() throws SoarException { op.newOption(alpha).done(); op.newOption(bravo).done(); List<String> empty = new ArrayList<String>(); List<String> arg = Lists.newArrayList("arg"); verify(Lists.newArrayList("command", "--alpha", "--bravo"), empty, alpha, bravo); verify(Lists.newArrayList("command", "arg", "--alpha", "--bravo"), arg, alpha, bravo); verify(Lists.newArrayList("command", "--alpha", "arg", "--bravo"), arg, alpha, bravo); verify(Lists.newArrayList("command", "--alpha", "--bravo", "arg"), arg, alpha, bravo); verify(Lists.newArrayList("command", "-a", "--bravo"), empty, alpha, bravo); verify(Lists.newArrayList("command", "arg", "-a", "--bravo"), arg, alpha, bravo); verify(Lists.newArrayList("command", "-a", "arg", "--bravo"), arg, alpha, bravo); verify(Lists.newArrayList("command", "-a", "--bravo", "arg"), arg, alpha, bravo); verify(Lists.newArrayList("command", "--alpha", "-b"), empty, alpha, bravo); verify(Lists.newArrayList("command", "arg", "--alpha", "-b"), arg, alpha, bravo); verify(Lists.newArrayList("command", "--alpha", "arg", "-b"), arg, alpha, bravo); verify(Lists.newArrayList("command", "--alpha", "-b", "arg"), arg, alpha, bravo); verify(Lists.newArrayList("command", "-a", "-b"), empty, alpha, bravo); verify(Lists.newArrayList("command", "arg", "-a", "-b"), arg, alpha, bravo); verify(Lists.newArrayList("command", "-a", "arg", "-b"), arg, alpha, bravo); verify(Lists.newArrayList("command", "-a", "-b", "arg"), arg, alpha, bravo); verify(Lists.newArrayList("command", "-b", "-a"), empty, alpha, bravo); verify(Lists.newArrayList("command", "arg", "-b", "-a"), arg, alpha, bravo); verify(Lists.newArrayList("command", "-b", "arg", "-a"), arg, alpha, bravo); verify(Lists.newArrayList("command", "-b", "-a", "arg"), arg, alpha, bravo); verify(Lists.newArrayList("command", "--bravo", "-a"), empty, alpha, bravo); verify(Lists.newArrayList("command", "arg", "--bravo", "-a"), arg, alpha, bravo); verify(Lists.newArrayList("command", "--bravo", "arg", "-a"), arg, alpha, bravo); verify(Lists.newArrayList("command", "--bravo", "-a", "arg"), arg, alpha, bravo); verify(Lists.newArrayList("command", "-b", "--alpha"), empty, alpha, bravo); verify(Lists.newArrayList("command", "arg", "-b", "--alpha"), arg, alpha, bravo); verify(Lists.newArrayList("command", "-b", "arg", "--alpha"), arg, alpha, bravo); verify(Lists.newArrayList("command", "-b", "--alpha", "arg"), arg, alpha, bravo); verify(Lists.newArrayList("command", "--bravo", "--alpha"), empty, alpha, bravo); verify(Lists.newArrayList("command", "arg", "--bravo", "--alpha"), arg, alpha, bravo); verify(Lists.newArrayList("command", "--bravo", "arg", "--alpha"), arg, alpha, bravo); verify(Lists.newArrayList("command", "--bravo", "--alpha", "arg"), arg, alpha, bravo); verify(Lists.newArrayList("command", "-ab"), empty, alpha, bravo); verify(Lists.newArrayList("command", "arg", "-ab"), arg, alpha, bravo); verify(Lists.newArrayList("command", "-ab", "arg"), arg, alpha, bravo); verify(Lists.newArrayList("command", "-ba"), empty, alpha, bravo); verify(Lists.newArrayList("command", "arg", "-ba"), arg, alpha, bravo); verify(Lists.newArrayList("command", "-ba", "arg"), arg, alpha, bravo); }
@Test public void testNonOptArgOrder() throws SoarException { op.newOption(alpha).newOption(bravo).newOption(charlie).done(); verifyabc(Lists.newArrayList("command", "--alpha", "--bravo", "--charlie", "1", "2", "3")); verifyabc(Lists.newArrayList("command", "--alpha", "--bravo", "1", "--charlie", "2", "3")); verifyabc(Lists.newArrayList("command", "--alpha", "1", "--bravo", "--charlie", "2", "3")); verifyabc(Lists.newArrayList("command", "--alpha", "1", "--bravo", "2", "--charlie", "3")); verifyabc(Lists.newArrayList("command", "1", "--alpha", "--bravo", "2", "--charlie", "3")); verifyabc(Lists.newArrayList("command", "1", "--alpha", "2", "--bravo", "--charlie", "3")); verifyabc(Lists.newArrayList("command", "1", "--alpha", "2", "--bravo", "3", "--charlie")); verifyabc(Lists.newArrayList("command", "1", "2", "3", "--alpha", "--bravo", "--charlie")); }
@Test(expected = NullPointerException.class) public void testRegisterNullLong() { op.newOption(null).done(); }
@Test(expected = IllegalArgumentException.class) public void testRegisterTwiceLong() { op.newOption(alpha).done(); op.newOption(alpha).done(); }
@Test(expected = IllegalArgumentException.class) public void testRegisterTwiceLongDiffShort() { op.newOption(alpha).shortOption('a').done(); op.newOption(alpha).shortOption('A').done(); }