ReflectiveProc extends PN { public static ReflectiveProc invoke(Class clazz, String name, Class... paramTypes) { Method m = Signatures.bestMethod(clazz, name, paramTypes); if (m == null) { throw notFound(clazz, name, paramTypes); } return new ReflectiveProc(null, m); } ReflectiveProc(Object instance, Method method);  ReflectiveProc(Constructor constructor); static Class[] anyParameters(int count); static ReflectiveProc newInstance(Class<?> clazz, Class... paramTypes); static PN newInstanceWith(Class<?> clazz, Object... args); static ReflectiveProc invoke(Class clazz, String name, Class... paramTypes); static ReflectiveProc invoke(Object object, String name, Class... paramTypes); static PN invokeWith(Class clazz, String name, Object... args); static PN invokeWith(Object object, String name, Object... args); static final Class[] ANY_PARAMETERS; static final Class[] NO_PARAMETERS; }
@Test public void test_callClass() { Proc proc = Procs.invoke(ReflectiveProcTest.class, "count", int.class); assertThat(proc.call(7).hasResult(), is(true)); assertThat(counter, is(7)); }
@Test public void test_findWithBoxedType() { Proc proc = Procs.invoke(ReflectiveProcTest.class, "count", Integer.class); assertThat(proc.call(7).hasResult(), is(true)); assertThat(counter, is(7)); }
@Test public void test_callClass_AnyParam() { Proc proc = Procs.invoke(ReflectiveProcTest.class, "count", ReflectiveProc.ANY_PARAMETERS); assertThat(proc.call(9).hasResult(), is(true)); assertThat(counter, is(9)); }
@Test public void test_callInstance() { Proc proc = Procs.invoke(new Inc(3), "inc", ReflectiveProc.NO_PARAMETERS); assertThat(proc.hasResult(), is(true)); assertThat(counter, is(3)); }
@Test public void test_callInstance_AnyParam() { Proc proc = Procs.invoke(new Inc(4), "inc", ReflectiveProc.ANY_PARAMETERS); assertThat(proc.hasResult(), is(true)); assertThat(counter, is(4)); }
@Test public void test_implicitClass_invoke() { Proc proc = Procs.invoke("count"); assertThat(proc.call(11).hasResult(), is(true)); assertThat(counter, is(11)); }
@Test public void test_unboundInstance_invoke() { Proc proc = Procs.invoke(Inc.class, "inc"); assertThat(proc.call(new Inc(3)).hasResult(), is(true)); assertThat(counter, is(3)); assertThat(proc.call(new Inc(4)).hasResult(), is(true)); assertThat(counter, is(7)); }
@Test public void test_varArgs_1() throws Exception { Proc sum = Procs.invoke(new VarArgs(), "sum").call(1, 2, 3); assertThat(sum.getException(), is(nullValue())); assertThat(sum.getResult(), is((Object) 6)); }
@Test public void test_varArgs_2() throws Exception { Proc sum = Procs.invoke(new VarArgs(), "sum").call(1); assertThat(sum.getException(), is(nullValue())); assertThat(sum.getResult(), is((Object) 1)); }
@Test public void test_varArgs_3() throws Exception { Proc sum = Procs.invoke(new VarArgs(), "sum").call(); assertThat(sum.getException(), is(nullValue())); assertThat(sum.getResult(), is((Object) 0)); }