Package com.firefly.utils.ReflectUtils

Examples of com.firefly.utils.ReflectUtils.MethodProxy.invoke()


 
  @Test
  public void testProxyMethod() throws NoSuchMethodException, SecurityException, Throwable {
    Foo foo = new Foo();
    MethodProxy proxy = ReflectUtils.getMethodProxy(Foo.class.getMethod("setProperty", String.class, boolean.class));
    Assert.assertThat(proxy.invoke(foo, "proxy foo", true), nullValue());
    Assert.assertThat(foo.getName(), is("proxy foo"));
    Assert.assertThat(foo.isFailure(), is(true));
   
    proxy = ReflectUtils.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "name"));
    Assert.assertThat((String)proxy.invoke(foo), is("proxy foo"));
View Full Code Here


    Assert.assertThat(proxy.invoke(foo, "proxy foo", true), nullValue());
    Assert.assertThat(foo.getName(), is("proxy foo"));
    Assert.assertThat(foo.isFailure(), is(true));
   
    proxy = ReflectUtils.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "name"));
    Assert.assertThat((String)proxy.invoke(foo), is("proxy foo"));
   
    proxy = ReflectUtils.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "failure"));
    Assert.assertThat((Boolean)proxy.invoke(foo), is(true));
   
    proxy = ReflectUtils.getMethodProxy(ReflectUtils.getSetterMethod(Foo.class, "price"));
View Full Code Here

   
    proxy = ReflectUtils.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "name"));
    Assert.assertThat((String)proxy.invoke(foo), is("proxy foo"));
   
    proxy = ReflectUtils.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "failure"));
    Assert.assertThat((Boolean)proxy.invoke(foo), is(true));
   
    proxy = ReflectUtils.getMethodProxy(ReflectUtils.getSetterMethod(Foo.class, "price"));
    Assert.assertThat(proxy.invoke(foo, 35.5), nullValue());
    Assert.assertThat(foo.getPrice(), is(35.5));
   
View Full Code Here

   
    proxy = ReflectUtils.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "failure"));
    Assert.assertThat((Boolean)proxy.invoke(foo), is(true));
   
    proxy = ReflectUtils.getMethodProxy(ReflectUtils.getSetterMethod(Foo.class, "price"));
    Assert.assertThat(proxy.invoke(foo, 35.5), nullValue());
    Assert.assertThat(foo.getPrice(), is(35.5));
   
    MethodProxyFactoryUsingJavaCompiler proxyUsingJavaCompiler = MethodProxyFactoryUsingJavaCompiler.INSTANCE;
    Foo foo2 = new Foo();
    MethodProxy proxy2 = proxyUsingJavaCompiler.getMethodProxy(Foo.class.getMethod("setProperty", String.class, boolean.class));
View Full Code Here

    Assert.assertThat(foo.getPrice(), is(35.5));
   
    MethodProxyFactoryUsingJavaCompiler proxyUsingJavaCompiler = MethodProxyFactoryUsingJavaCompiler.INSTANCE;
    Foo foo2 = new Foo();
    MethodProxy proxy2 = proxyUsingJavaCompiler.getMethodProxy(Foo.class.getMethod("setProperty", String.class, boolean.class));
    Assert.assertThat(proxy2.invoke(foo2, "proxy foo", true), nullValue());
    Assert.assertThat(foo2.getName(), is("proxy foo"));
    Assert.assertThat(foo2.isFailure(), is(true));
   
    proxy2 = proxyUsingJavaCompiler.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "name"));
    Assert.assertThat((String)proxy2.invoke(foo2), is("proxy foo"));
View Full Code Here

    Assert.assertThat(proxy2.invoke(foo2, "proxy foo", true), nullValue());
    Assert.assertThat(foo2.getName(), is("proxy foo"));
    Assert.assertThat(foo2.isFailure(), is(true));
   
    proxy2 = proxyUsingJavaCompiler.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "name"));
    Assert.assertThat((String)proxy2.invoke(foo2), is("proxy foo"));
   
   
    proxy2 = proxyUsingJavaCompiler.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "failure"));
    Assert.assertThat((Boolean)proxy2.invoke(foo2), is(true));
   
View Full Code Here

    proxy2 = proxyUsingJavaCompiler.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "name"));
    Assert.assertThat((String)proxy2.invoke(foo2), is("proxy foo"));
   
   
    proxy2 = proxyUsingJavaCompiler.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "failure"));
    Assert.assertThat((Boolean)proxy2.invoke(foo2), is(true));
   
    proxy2 = proxyUsingJavaCompiler.getMethodProxy(ReflectUtils.getSetterMethod(Foo.class, "price"));
    Assert.assertThat(proxy2.invoke(foo2, 35.5), nullValue());
    Assert.assertThat(foo2.getPrice(), is(35.5));
  }
View Full Code Here

   
    proxy2 = proxyUsingJavaCompiler.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "failure"));
    Assert.assertThat((Boolean)proxy2.invoke(foo2), is(true));
   
    proxy2 = proxyUsingJavaCompiler.getMethodProxy(ReflectUtils.getSetterMethod(Foo.class, "price"));
    Assert.assertThat(proxy2.invoke(foo2, 35.5), nullValue());
    Assert.assertThat(foo2.getPrice(), is(35.5));
  }
 
  @Test
  public void testProxyField() throws Throwable {
View Full Code Here

 
  public static void main7(String[] args) throws Throwable {
    Foo foo = new Foo();
    MethodProxyFactoryUsingJavaCompiler proxy = MethodProxyFactoryUsingJavaCompiler.INSTANCE;
    MethodProxy setPriceProxy = proxy.getMethodProxy(ReflectUtils.getSetterMethod(Foo.class, "price"));
    setPriceProxy.invoke(foo, 3.3);
   
    MethodProxy getPriceProxy = proxy.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "price"));
    System.out.println(getPriceProxy.invoke(foo));
   
    MethodProxy getPriceProxy2 = ReflectUtils.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "price"));
View Full Code Here

    MethodProxyFactoryUsingJavaCompiler proxy = MethodProxyFactoryUsingJavaCompiler.INSTANCE;
    MethodProxy setPriceProxy = proxy.getMethodProxy(ReflectUtils.getSetterMethod(Foo.class, "price"));
    setPriceProxy.invoke(foo, 3.3);
   
    MethodProxy getPriceProxy = proxy.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "price"));
    System.out.println(getPriceProxy.invoke(foo));
   
    MethodProxy getPriceProxy2 = ReflectUtils.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "price"));
    System.out.println(getPriceProxy2.invoke(foo));
   
    int times = 1000 * 1000 * 1000;
 
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.