Search in sources :

Example 1 with WrapperInvocationHandler

use of com.android.tools.idea.gradle.util.ProxyUtil.WrapperInvocationHandler in project android by JetBrains.

the class ProxyUtilTest method testNewMethod.

public void testNewMethod() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    MyInterface reproxy = reproxy(MyInterface.class, myProxy);
    assertNotNull(reproxy);
    InvocationHandler handler = Proxy.getInvocationHandler(reproxy);
    assertTrue(handler instanceof WrapperInvocationHandler);
    WrapperInvocationHandler wrapper = (WrapperInvocationHandler) handler;
    Method m = MyInterface.class.getMethod("getString");
    wrapper.values.remove(m.toGenericString());
    try {
        reproxy.getString();
        fail("Removed method should throw an exception");
    } catch (UnsupportedMethodException e) {
    // Expected.
    }
}
Also used : UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException) WrapperInvocationHandler(com.android.tools.idea.gradle.util.ProxyUtil.WrapperInvocationHandler) WrapperInvocationHandler(com.android.tools.idea.gradle.util.ProxyUtil.WrapperInvocationHandler)

Example 2 with WrapperInvocationHandler

use of com.android.tools.idea.gradle.util.ProxyUtil.WrapperInvocationHandler in project android by JetBrains.

the class ProxyUtilTest method testValidityNegative.

public void testValidityNegative() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    MyInterface reproxy = reproxy(MyInterface.class, myProxy);
    assertNotNull(reproxy);
    InvocationHandler handler = Proxy.getInvocationHandler(reproxy);
    assertTrue(handler instanceof WrapperInvocationHandler);
    WrapperInvocationHandler wrapper = (WrapperInvocationHandler) handler;
    Method m = MyInterface.class.getMethod("getString");
    wrapper.values.remove(m.toGenericString());
    // Removed method should result in validity check failure
    assertFalse(isValidProxyObject(reproxy));
}
Also used : WrapperInvocationHandler(com.android.tools.idea.gradle.util.ProxyUtil.WrapperInvocationHandler) WrapperInvocationHandler(com.android.tools.idea.gradle.util.ProxyUtil.WrapperInvocationHandler)

Aggregations

WrapperInvocationHandler (com.android.tools.idea.gradle.util.ProxyUtil.WrapperInvocationHandler)2 UnsupportedMethodException (org.gradle.tooling.model.UnsupportedMethodException)1