use of jodd.proxetta.data.Foo in project jodd by oblac.
the class MethodInfoTest method testMethodInfo.
@Test
public void testMethodInfo() {
final ValueHolder<MethodInfo> valueHolder = ValueHolderWrapper.create();
ProxyAspect proxyAspect = new ProxyAspect(FooProxyAdvice.class, new ProxyPointcut() {
public boolean apply(MethodInfo methodInfo) {
if (methodInfo.getMethodName().equals("p1")) {
valueHolder.set(methodInfo);
return true;
}
return false;
}
});
ProxyProxetta proxyProxetta = ProxyProxetta.withAspects(proxyAspect);
proxyProxetta.setClassNameSuffix("$$$Proxetta888");
ProxyProxettaBuilder pb = proxyProxetta.builder();
pb.setTarget(Foo.class);
Foo foo = (Foo) pb.newInstance();
assertNotNull(foo);
MethodInfo mi = valueHolder.get();
assertEquals("p1", mi.getMethodName());
assertEquals(Foo.class.getName().replace('.', '/'), mi.getClassname());
assertEquals("(java.lang.String)", mi.getDeclaration());
assertEquals("(Ljava/lang/String;)Ljava/lang/String;", mi.getDescription());
assertEquals("java.lang.String", mi.getReturnType());
assertEquals("Ljava/lang/String;", mi.getReturnTypeName());
assertEquals("java.lang.String p1(java.lang.String)", mi.getSignature());
assertEquals(1, mi.getArgumentsCount());
assertEquals("Ljava/lang/String;", mi.getArgumentTypeName(1));
assertTrue(mi.isTopLevelMethod());
AnnotationInfo[] anns = mi.getArgumentAnnotations(0);
assertNotNull(anns);
assertEquals(1, anns.length);
assertEquals(FooAnn.class.getName(), anns[0].getAnnotationClassname());
}
use of jodd.proxetta.data.Foo 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));
}
Aggregations