@Test public void testFieldBindingDoesNotSetAccessible() throws Exception { Field f = ModelMethodBindingBean.class.getDeclaredField("x"); FieldBinding binding = new FieldBinding(new ModelMethodBindingBean(), f); try { binding.get(); fail("Expected exception"); } catch (PicocliException ok) { assertThat("not accessible", ok.getCause() instanceof IllegalAccessException); } }
@Test public void testMethodMustBeAccessible() throws Exception { Method setX = ModelMethodBindingBean.class.getDeclaredMethod("setX", int.class); MethodBinding binding = new MethodBinding(new ModelMethodBindingBean(), setX, CommandSpec.create()); try { binding.set(1); fail("Expected exception"); } catch (PicocliException ok) { assertThat("not accessible", ok.getCause() instanceof IllegalAccessException); } }
@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()); } }
@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()); } }
@Test public void testArgSpecGetterWrapNonPicocliException() { final Exception expected = new Exception("boom"); IGetter getter = new IGetter() { public <T> T get() throws Exception { throw expected; } }; PositionalParamSpec positional = PositionalParamSpec.builder().getter(getter).build(); try { positional.getValue(); } catch (CommandLine.PicocliException ex) { assertSame(expected, ex.getCause()); } }
@Test public void testMethodMustBeAccessible() throws Exception { Method setX = ModelMethodBindingBean.class.getDeclaredMethod("setX", int.class); MethodBinding binding = new MethodBinding(new ModelMethodBindingBean(), setX, CommandSpec.create()); try { binding.set(1); fail("Expected exception"); } catch (PicocliException ok) { assertThat("not accessible", ok.getCause() instanceof IllegalAccessException); } }
@Test public void testFieldBindingDoesNotSetAccessible() throws Exception { Field f = ModelMethodBindingBean.class.getDeclaredField("x"); FieldBinding binding = new FieldBinding(new ModelMethodBindingBean(), f); try { binding.get(); fail("Expected exception"); } catch (PicocliException ok) { assertThat("not accessible", ok.getCause() instanceof IllegalAccessException); } }
@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()); } }
@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()); } }
@Test public void testArgSpecGetterWrapNonPicocliException() { final Exception expected = new Exception("boom"); IGetter getter = new IGetter() { public <T> T get() throws Exception { throw expected; } }; PositionalParamSpec positional = PositionalParamSpec.builder().getter(getter).build(); try { positional.getValue(); } catch (CommandLine.PicocliException ex) { assertSame(expected, ex.getCause()); } }