@Test public void testBasicMethodAndConstructor() throws IOException { final Hack.HackedMethod1<Simple, Void, IOException, Unchecked, Unchecked, Integer> constructor = Hack.into(Simple.class).constructor().throwing(IOException.class).withParam(int.class); assertNotNull(constructor); final Simple simple = constructor.invoke(0).statically(); assertNotNull(simple); final Hack.HackedMethod0<Integer, Simple, Unchecked, Unchecked, Unchecked> foo = Hack.into(Simple.class).method("foo").returning(int.class).withoutParams(); assertNotNull(foo); assertEquals(7, (int) foo.invoke().on(simple)); final Hack.HackedMethod0<Integer, Simple, RuntimeException, Unchecked, Unchecked> foo_rt_ex = Hack.into(Simple.class).method("foo").returning(int.class).throwing(RuntimeException.class).withoutParams(); assertNotNull(foo_rt_ex); assertEquals(7, (int) foo_rt_ex.invoke().on(simple)); final Hack.HackedMethod0<Integer, Simple, IOException, Unchecked, Unchecked> foo_ex = Hack.into(Simple.class).method("foo").returning(int.class).throwing(IOException.class).withoutParams(); assertNotNull(foo_ex); assertEquals(7, (int) foo_ex.invoke().on(simple)); final Hack.HackedMethod3<Void, Void, IOException, Unchecked, Unchecked, Integer, String, Simple> bar = Hack.into(Simple.class).staticMethod("bar").throwing(IOException.class).withParams(int.class, String.class, Simple.class); assertNotNull(bar); bar.invoke(-1, "xyz", simple).statically(); assertFail(null, Hack.into(Simple.class).method("bar").throwing(UnsupportedOperationException.class, FileNotFoundException.class).withParams(int.class, String.class, Simple.class)); assertFail(NoSuchMethodException.class, Hack.into(Simple.class).method("notExist").withoutParams()); assertFail(NoSuchMethodException.class, Hack.into(Simple.class).method("foo").withParam(int.class)); assertFail(null, Hack.into(Simple.class).staticMethod("foo").withoutParams()); assertFail(null, Hack.into(Simple.class).method("foo").returning(Void.class).withoutParams()); }
public static HackedObject into(final Object source) { return new HackedMirrorObject(source); }
Hack { public static HackedObject into(final Object source) { return new HackedMirrorObject(source); } }
Hack { public static HackedObject into(final Object source) { return new HackedMirrorObject(source); } private  Hack(); }
Hack { public static HackedObject into(final Object source) { return new HackedMirrorObject(source); } private  Hack(); static HackedObject into(final Object source); static R mirrorStaticMethod(final String tag, final R fallback, final Object... args); static void verifyAllMirrorsIn(final Class<?> enclosing); static HackedClass<T> into(final @NonNull Class<T> clazz); static HackedClass<T> into(final String class_name); @SuppressWarnings("unchecked") static Hack.HackedClass<C> onlyIf(final boolean condition, final Hacking<Hack.HackedClass<C>> hacking); static ConditionalHack onlyIf(final boolean condition); static AssertionFailureHandler setAssertionFailureHandler(final @Nullable AssertionFailureHandler handler); }
Hack { public static HackedObject into(final Object source) { return new HackedMirrorObject(source); } private  Hack(); static HackedObject into(final Object source); static R mirrorStaticMethod(final String tag, final R fallback, final Object... args); static void verifyAllMirrorsIn(final Class<?> enclosing); static HackedClass<T> into(final @NonNull Class<T> clazz); static HackedClass<T> into(final String class_name); @SuppressWarnings("unchecked") static Hack.HackedClass<C> onlyIf(final boolean condition, final Hacking<Hack.HackedClass<C>> hacking); static ConditionalHack onlyIf(final boolean condition); static AssertionFailureHandler setAssertionFailureHandler(final @Nullable AssertionFailureHandler handler); static Class<?> ANY_TYPE; }