@Test public void getMethodArg() throws Exception { final String answer = "bubba"; final Object[] args = new Object[] { null, answer, "blue" }; final Method method = AOPTargetClass1.class.getDeclaredMethod("doIt", String.class, String.class, String.class); try { Utils.getMethodArg(-1, args, method.toString()); fail("Expected Exception"); } catch (InvalidParameterException ex) { assertTrue(ex.getMessage().indexOf("is invalid") != -1); System.out.println(ex.getMessage()); } try { Utils.getMethodArg(3, args, method.toString()); fail("Expected Exception"); } catch (InvalidParameterException ex) { assertTrue(ex.getMessage().indexOf("too big") != -1); System.out.println(ex.getMessage()); } try { Utils.getMethodArg(4, args, method.toString()); fail("Expected Exception"); } catch (InvalidParameterException ex) { assertTrue(ex.getMessage().indexOf("too big") != -1); System.out.println(ex.getMessage()); } try { Utils.getMethodArg(0, args, method.toString()); fail("Expected Exception"); } catch (InvalidParameterException ex) { assertTrue(ex.getMessage().indexOf("null") != -1); System.out.println(ex.getMessage()); } assertEquals(answer, Utils.getMethodArg(1, args, method.toString())); }
public static Object getMethodArg(final int index, final Object[] args, final String methodDesc) { if (index < 0) { throw new InvalidParameterException(String.format("An index of %s is invalid", index)); } if (args.length <= index) { throw new InvalidParameterException(String.format("An index of %s is too big for the number of arguments in [%s]", index, methodDesc)); } final Object indexObject = args[index]; if (indexObject == null) { throw new InvalidParameterException(String.format("The argument passed into [%s] at index %s is null.", methodDesc, index)); } return indexObject; }
Utils { public static Object getMethodArg(final int index, final Object[] args, final String methodDesc) { if (index < 0) { throw new InvalidParameterException(String.format("An index of %s is invalid", index)); } if (args.length <= index) { throw new InvalidParameterException(String.format("An index of %s is too big for the number of arguments in [%s]", index, methodDesc)); } final Object indexObject = args[index]; if (indexObject == null) { throw new InvalidParameterException(String.format("The argument passed into [%s] at index %s is null.", methodDesc, index)); } return indexObject; } }
Utils { public static Object getMethodArg(final int index, final Object[] args, final String methodDesc) { if (index < 0) { throw new InvalidParameterException(String.format("An index of %s is invalid", index)); } if (args.length <= index) { throw new InvalidParameterException(String.format("An index of %s is too big for the number of arguments in [%s]", index, methodDesc)); } final Object indexObject = args[index]; if (indexObject == null) { throw new InvalidParameterException(String.format("The argument passed into [%s] at index %s is null.", methodDesc, index)); } return indexObject; } private  Utils(); }
Utils { public static Object getMethodArg(final int index, final Object[] args, final String methodDesc) { if (index < 0) { throw new InvalidParameterException(String.format("An index of %s is invalid", index)); } if (args.length <= index) { throw new InvalidParameterException(String.format("An index of %s is too big for the number of arguments in [%s]", index, methodDesc)); } final Object indexObject = args[index]; if (indexObject == null) { throw new InvalidParameterException(String.format("The argument passed into [%s] at index %s is null.", methodDesc, index)); } return indexObject; } 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); }
Utils { public static Object getMethodArg(final int index, final Object[] args, final String methodDesc) { if (index < 0) { throw new InvalidParameterException(String.format("An index of %s is invalid", index)); } if (args.length <= index) { throw new InvalidParameterException(String.format("An index of %s is too big for the number of arguments in [%s]", index, methodDesc)); } final Object indexObject = args[index]; if (indexObject == null) { throw new InvalidParameterException(String.format("The argument passed into [%s] at index %s is null.", methodDesc, index)); } return indexObject; } 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);  }