Java Code Examples for picocli.CommandLine.Model.PositionalParamSpec#setValue()

The following examples show how to use picocli.CommandLine.Model.PositionalParamSpec#setValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelArgSpecTest.java    From picocli with Apache License 2.0 5 votes vote down vote up
@Test
public void testArgSpecSetterRethrowsPicocliException() {
    final CommandLine.PicocliException expected = new CommandLine.PicocliException("boom");
    ISetter setter = new ISetter() {
        public <T> T set(T value) throws Exception { throw expected; }
    };
    PositionalParamSpec positional = PositionalParamSpec.builder().setter(setter).build();
    try {
        positional.setValue("abc");
    } catch (CommandLine.PicocliException ex) {
        assertSame(expected, ex);
    }
}
 
Example 2
Source File: ModelArgSpecTest.java    From picocli with Apache License 2.0 5 votes vote down vote up
@Test
public void testArgSpecSetValueCallsSetter() {
    final Object[] newVal = new Object[1];
    ISetter setter = new ISetter() {
        public <T> T set(T value) { newVal[0] = value; return null; }
    };
    PositionalParamSpec positional = PositionalParamSpec.builder().setter(setter).build();
    positional.setValue("abc");
    assertEquals("abc", newVal[0]);
}
 
Example 3
Source File: ModelArgSpecTest.java    From picocli with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test
public void testArgSpecSetValueWithCommandLineCallsSetter() {
    final Object[] newVal = new Object[1];
    ISetter setter = new ISetter() {
        public <T> T set(T value) { newVal[0] = value; return null; }
    };
    PositionalParamSpec positional = PositionalParamSpec.builder().setter(setter).build();
    positional.setValue("abc", new CommandLine(CommandSpec.create()));
    assertEquals("abc", newVal[0]);
}
 
Example 4
Source File: ModelArgSpecTest.java    From picocli with Apache License 2.0 5 votes vote down vote up
@Test
public void testArgSpecSetterWrapNonPicocliException() {
    final Exception expected = new Exception("boom");
    ISetter setter = new ISetter() {
        public <T> T set(T value) throws Exception { throw expected; }
    };
    PositionalParamSpec positional = PositionalParamSpec.builder().setter(setter).build();
    try {
        positional.setValue("abc");
    } catch (CommandLine.PicocliException ex) {
        assertSame(expected, ex.getCause());
    }
}
 
Example 5
Source File: ModelArgSpecTest.java    From picocli with Apache License 2.0 5 votes vote down vote up
@Test
public void testArgSpecSetter2WrapNonPicocliException() {
    final Exception expected = new Exception("boom");
    ISetter setter = new ISetter() {
        public <T> T set(T value) throws Exception { throw expected; }
    };
    PositionalParamSpec positional = PositionalParamSpec.builder().setter(setter).build();
    try {
        positional.setValue("abc");
    } catch (CommandLine.PicocliException ex) {
        assertSame(expected, ex.getCause());
    }
}