AnalyzingMethodRefPredicate implements Predicate<MethodRef> { @Override public boolean test(MethodRef t) { Boolean suspendable = suspendables.get(t); if (suspendable == null) { throw new IllegalArgumentException("Method " + t.getName() + t.getDesc() + " not found"); } return suspendable; } AnalyzingMethodRefPredicate(byte[] buffer, Predicate<MethodRef> predicate); @Override boolean test(MethodRef t);  }
@Test public void testApplyParentPredicate() throws Exception { class C { void m() { m2(); } void m2() { } } Predicate<MethodRef> predicate = new AnalyzingMethodRefPredicate(getBytes(C.class), t -> !t.getName().equals("m")); assertFalse(predicate.test(getMethodRef(C.class.getDeclaredMethod("m")))); }
@Test public void testApplyMethodWithoutCalls() throws Exception { class C { void m() { } } Predicate<MethodRef> predicate = new AnalyzingMethodRefPredicate(getBytes(C.class), TRUE_PREDICATE); assertFalse(predicate.test(getMethodRef(C.class.getDeclaredMethod("m")))); }
@Test public void testApplyMethodWithCall() throws Exception { class C { void m() { m2(); } void m2() { } } Predicate<MethodRef> predicate = new AnalyzingMethodRefPredicate(getBytes(C.class), TRUE_PREDICATE); assertTrue(predicate.test(getMethodRef(C.class.getDeclaredMethod("m")))); }
@Test public void testApplyMethodWithCallFinalClass() throws Exception { final class C { void m() { m2(); } void m2() { } } Predicate<MethodRef> predicate = new AnalyzingMethodRefPredicate(getBytes(C.class), TRUE_PREDICATE); assertFalse(predicate.test(getMethodRef(C.class.getDeclaredMethod("m")))); }
@Test public void testApplyMethodWithCallPrivate() throws Exception { class C { void m() { m2(); } private void m2() { } } Predicate<MethodRef> predicate = new AnalyzingMethodRefPredicate(getBytes(C.class), TRUE_PREDICATE); assertFalse(predicate.test(getMethodRef(C.class.getDeclaredMethod("m")))); }
@Test public void testApplyMethodWithCallStatic() throws Exception { Predicate<MethodRef> predicate = new AnalyzingMethodRefPredicate(getBytes(Static.class), TRUE_PREDICATE); assertFalse(predicate.test(getMethodRef(Static.class.getDeclaredMethod("m")))); }
@Test public void testApplyMethodWithCallFinal() throws Exception { class C { void m() { m2(); } final void m2() { } } Predicate<MethodRef> predicate = new AnalyzingMethodRefPredicate(getBytes(C.class), TRUE_PREDICATE); assertFalse(predicate.test(getMethodRef(C.class.getDeclaredMethod("m")))); }
@Test public void testApplyMethodWithCallRecursion() throws Exception { class C { void m1() { m2(); } private void m2() { m1(); } } Predicate<MethodRef> predicate = new AnalyzingMethodRefPredicate(getBytes(C.class), TRUE_PREDICATE); assertTrue(predicate.test(getMethodRef(C.class.getDeclaredMethod("m1")))); assertTrue(predicate.test(getMethodRef(C.class.getDeclaredMethod("m2")))); }
@Test public void testApplyMethodWithCallRecursionPrivate() throws Exception { class C { private void m1() { m2(); } private void m2() { m1(); } } Predicate<MethodRef> predicate = new AnalyzingMethodRefPredicate(getBytes(C.class), TRUE_PREDICATE); assertFalse(predicate.test(getMethodRef(C.class.getDeclaredMethod("m1")))); assertFalse(predicate.test(getMethodRef(C.class.getDeclaredMethod("m2")))); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testApplyNonExistentMethod() throws Exception { Predicate<MethodRef> predicate = new AnalyzingMethodRefPredicate(getBytes(getClass()), TRUE_PREDICATE); predicate.test(new MethodRef("nonExistentMethod", "()V")); }