@Test public void testCreation() { AmbiguousOptionException exception = new AmbiguousOptionException("foo", Arrays.asList(new Option().setLongName("foobar"), new Option().setLongName("foobaz"))); assertThat(exception.getOptions()).hasSize(2); assertThat(exception.getToken()).isEqualTo("foo"); assertThat(exception.getMessage()) .contains("Ambiguous argument in command line") .contains("'foo'") .contains("foobar").contains("foobaz"); }
@Test public void testAmbiguousPartialLongOption2() throws Exception { String[] args = new String[]{"-ver"}; TypedOption<Integer> v1 = new TypedOption<Integer>().setLongName("verbose") .setSingleValued(true) .setType(Integer.class); TypedOption<Boolean> v2 = new TypedOption<Boolean>().setLongName("version").setType(Boolean.class) .setSingleValued(false); cli.addOption(v1).addOption(v2); try { cli.parse(Arrays.asList(args)); fail("Exception expected"); } catch (AmbiguousOptionException e) { assertThat(e.getToken()).isEqualTo("-ver"); assertThat(e.getOptions()).hasSize(2); } }
@Test public void testAmbiguousPartialLongOption1() throws Exception { String[] args = new String[]{"--ver"}; TypedOption<Integer> v1 = new TypedOption<Integer>().setLongName("verbose") .setSingleValued(true) .setType(Integer.class); TypedOption<Boolean> v2 = new TypedOption<Boolean>().setLongName("version") .setType(Boolean.class) .setSingleValued(false); cli.addOption(v1).addOption(v2); try { cli.parse(Arrays.asList(args)); fail("Exception expected"); } catch (AmbiguousOptionException e) { assertThat(e.getToken()).isEqualTo("--ver"); assertThat(e.getOptions()).hasSize(2); } }
@Test public void testAmbiguousPartialLongOption3() throws Exception { String[] args = new String[]{"--ver=1"}; TypedOption<Integer> v1 = new TypedOption<Integer>().setLongName("verbose") .setSingleValued(true) .setType(Integer.class); TypedOption<Boolean> v2 = new TypedOption<Boolean>().setLongName("version").setType(Boolean.class) .setSingleValued(false); cli.addOption(v1).addOption(v2); try { cli.parse(Arrays.asList(args)); fail("Exception expected"); } catch (AmbiguousOptionException e) { assertThat(e.getToken()).isEqualTo("--ver"); assertThat(e.getOptions()).hasSize(2); } }
@Test public void testAmbiguousPartialLongOption4() throws Exception { String[] args = new String[]{"-ver=1"}; TypedOption<Integer> v1 = new TypedOption<Integer>().setLongName("verbose") .setSingleValued(true) .setType(Integer.class); TypedOption<Boolean> v2 = new TypedOption<Boolean>().setLongName("version").setType(Boolean.class) .setSingleValued(false); cli.addOption(v1).addOption(v2); try { cli.parse(Arrays.asList(args)); fail("Exception expected"); } catch (AmbiguousOptionException e) { assertThat(e.getToken()).isEqualTo("-ver"); assertThat(e.getOptions()).hasSize(2); } }
@Test public void testCreation() { AmbiguousOptionException exception = new AmbiguousOptionException("foo", Arrays.asList(new Option().setLongName("foobar"), new Option().setLongName("foobaz"))); assertThat(exception.getOptions()).hasSize(2); assertThat(exception.getToken()).isEqualTo("foo"); assertThat(exception.getMessage()) .contains("Ambiguous argument in command line") .contains("'foo'") .contains("foobar").contains("foobaz"); }
@Test public void testAmbiguousPartialLongOption1() throws Exception { String[] args = new String[]{"--ver"}; TypedOption<Integer> v1 = new TypedOption<Integer>().setLongName("verbose") .setSingleValued(true) .setType(Integer.class); TypedOption<Boolean> v2 = new TypedOption<Boolean>().setLongName("version") .setType(Boolean.class) .setSingleValued(false); cli.addOption(v1).addOption(v2); try { cli.parse(Arrays.asList(args)); fail("Exception expected"); } catch (AmbiguousOptionException e) { assertThat(e.getToken()).isEqualTo("--ver"); assertThat(e.getOptions()).hasSize(2); } }
@Test public void testAmbiguousPartialLongOption2() throws Exception { String[] args = new String[]{"-ver"}; TypedOption<Integer> v1 = new TypedOption<Integer>().setLongName("verbose") .setSingleValued(true) .setType(Integer.class); TypedOption<Boolean> v2 = new TypedOption<Boolean>().setLongName("version").setType(Boolean.class) .setSingleValued(false); cli.addOption(v1).addOption(v2); try { cli.parse(Arrays.asList(args)); fail("Exception expected"); } catch (AmbiguousOptionException e) { assertThat(e.getToken()).isEqualTo("-ver"); assertThat(e.getOptions()).hasSize(2); } }
@Test public void testAmbiguousPartialLongOption3() throws Exception { String[] args = new String[]{"--ver=1"}; TypedOption<Integer> v1 = new TypedOption<Integer>().setLongName("verbose") .setSingleValued(true) .setType(Integer.class); TypedOption<Boolean> v2 = new TypedOption<Boolean>().setLongName("version").setType(Boolean.class) .setSingleValued(false); cli.addOption(v1).addOption(v2); try { cli.parse(Arrays.asList(args)); fail("Exception expected"); } catch (AmbiguousOptionException e) { assertThat(e.getToken()).isEqualTo("--ver"); assertThat(e.getOptions()).hasSize(2); } }
@Test public void testAmbiguousPartialLongOption4() throws Exception { String[] args = new String[]{"-ver=1"}; TypedOption<Integer> v1 = new TypedOption<Integer>().setLongName("verbose") .setSingleValued(true) .setType(Integer.class); TypedOption<Boolean> v2 = new TypedOption<Boolean>().setLongName("version").setType(Boolean.class) .setSingleValued(false); cli.addOption(v1).addOption(v2); try { cli.parse(Arrays.asList(args)); fail("Exception expected"); } catch (AmbiguousOptionException e) { assertThat(e.getToken()).isEqualTo("-ver"); assertThat(e.getOptions()).hasSize(2); } }