/** **************** Unit Test ***************** */ public long invokeMethod(Method m, long x, int i, int j) { try { Object[] args = new Object[] {x, i, j}; Object res = m.invoke(null, args); return (long) res; } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); return -1; } }
private void invalidValueHelper(Object obj, String methodName, int i) { try { Method m = obj.getClass().getMethod(methodName, int.class); m.invoke(obj, i); fail("Didn't cause an invalid value exception."); } catch (NoSuchMethodException | SecurityException e) { System.err.println("Error when getting the method. Uh oh!"); e.printStackTrace(); fail(); } catch (IllegalAccessException | IllegalArgumentException e) { System.err.println("Error when invoking the method. Uh oh!"); e.printStackTrace(); fail(); } catch (InvocationTargetException e) { assertEquals(JsonTypeException.class, e.getTargetException().getClass()); } }