Utils { public static Object[] getMethodArgs(final Collection<Integer> indexes, final Object[] args, final String methodDesc) { Object[] selectedArgs = new Object[indexes.size()]; Iterator<Integer> iter = indexes.iterator(); for (int i = 0; i < indexes.size(); i++) { selectedArgs[i] = getMethodArg(iter.next(), args, methodDesc); } return selectedArgs; } private  Utils(); static Object getMethodArg(final int index, final Object[] args, final String methodDesc); static Object[] getMethodArgs(final Collection<Integer> indexes, final Object[] args, final String methodDesc); static Class<?>[] getMethodParameterTypes(final Collection<Integer> indexes, final Method method);  }
@Test public void getMethodArgs() throws Exception { final Object[] answer = new Object[] { "blue", "bubba" }; final Object[] args = new Object[] { null, "bubba", "blue" }; final Method method = AOPTargetClass1.class.getDeclaredMethod("doIt", String.class, String.class, String.class); try { Utils.getMethodArgs(Arrays.asList(1, -1), args, method.toString()); fail("Expected Exception"); } catch (InvalidParameterException ex) { assertTrue(ex.getMessage().indexOf("is invalid") != -1); System.out.println(ex.getMessage()); } try { Utils.getMethodArgs(Arrays.asList(2, 3), args, method.toString()); fail("Expected Exception"); } catch (InvalidParameterException ex) { assertTrue(ex.getMessage().indexOf("too big") != -1); System.out.println(ex.getMessage()); } try { Utils.getMethodArgs(Arrays.asList(4, 0), args, method.toString()); fail("Expected Exception"); } catch (InvalidParameterException ex) { assertTrue(ex.getMessage().indexOf("too big") != -1); System.out.println(ex.getMessage()); } try { Utils.getMethodArgs(Arrays.asList(1, 0), args, method.toString()); fail("Expected Exception"); } catch (InvalidParameterException ex) { assertTrue(ex.getMessage().indexOf("null") != -1); System.out.println(ex.getMessage()); } assertArrayEquals(answer, Utils.getMethodArgs(Arrays.asList(2, 1), args, method.toString())); }