Search in sources :

Example 1 with AllTopMethodsPointcut

use of jodd.proxetta.pointcuts.AllTopMethodsPointcut in project jodd by oblac.

the class MethrefTest method testMethRefOnProxifiedClass.

@Test
public void testMethRefOnProxifiedClass() {
    Methref<? extends Oink> m = Methref.on(Oink.class);
    m.to().woink();
    assertEquals("woink", m.ref());
    ProxyAspect a1 = new ProxyAspect(DummyAdvice.class, new AllTopMethodsPointcut());
    ProxyProxetta pp = ProxyProxetta.withAspects(a1);
    Oink oink = (Oink) pp.builder(Oink.class).newInstance();
    assertFalse(oink.getClass().equals(Oink.class));
    m = Methref.on(oink.getClass());
    m.to().woink();
    assertEquals("woink", m.ref());
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) AllTopMethodsPointcut(jodd.proxetta.pointcuts.AllTopMethodsPointcut) ProxyAspect(jodd.proxetta.ProxyAspect) Test(org.junit.Test)

Example 2 with AllTopMethodsPointcut

use of jodd.proxetta.pointcuts.AllTopMethodsPointcut in project jodd by oblac.

the class AdviceWithMethodTest method testCollector.

@Test
public void testCollector() throws NoSuchFieldException, IllegalAccessException {
    ProxyProxetta proxetta = ProxyProxetta.withAspects(new ProxyAspect(CollectorAdvice.class, new AllTopMethodsPointcut()));
    //		proxetta.setDebugFolder("d:\\");
    Foo foo = (Foo) proxetta.builder(Foo.class).newInstance();
    Field field = foo.getClass().getDeclaredField("$__methods$0");
    field.setAccessible(true);
    List<String> list = (List<String>) field.get(foo);
    assertNotNull(list);
    assertEquals(0, list.size());
    foo.m1();
    assertEquals(1, list.size());
    assertEquals("m1", list.get(0));
    foo.m1();
    assertEquals(2, list.size());
    assertEquals("m1", list.get(0));
    assertEquals("m1", list.get(1));
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) Field(java.lang.reflect.Field) Foo(jodd.proxetta.data.Foo) AllTopMethodsPointcut(jodd.proxetta.pointcuts.AllTopMethodsPointcut) CollectorAdvice(jodd.proxetta.data.CollectorAdvice) List(java.util.List) Test(org.junit.Test)

Aggregations

ProxyProxetta (jodd.proxetta.impl.ProxyProxetta)2 AllTopMethodsPointcut (jodd.proxetta.pointcuts.AllTopMethodsPointcut)2 Test (org.junit.Test)2 Field (java.lang.reflect.Field)1 List (java.util.List)1 ProxyAspect (jodd.proxetta.ProxyAspect)1 CollectorAdvice (jodd.proxetta.data.CollectorAdvice)1 Foo (jodd.proxetta.data.Foo)1