use of jodd.proxetta.pointcuts.ProxyPointcutSupport in project jodd by oblac.
the class WrapperTest method testClassWrapper.
@Test
public void testClassWrapper() throws Exception {
Calc calc = new CalcImpl();
WrapperProxetta proxetta = WrapperProxetta.withAspects(new ProxyAspect(StatCounterAdvice.class, new ProxyPointcutSupport() {
public boolean apply(MethodInfo methodInfo) {
return !isRootMethod(methodInfo) && isPublic(methodInfo);
}
}));
// proxetta.setDebugFolder("d:\\");
// wrapper over CLASS
// resulting object has ALL interfaces
// resulting object wraps ALL target class methods
WrapperProxettaBuilder builder = proxetta.builder(calc.getClass());
Class calc2Class = builder.define();
Object object = calc2Class.newInstance();
assertTrue(object instanceof Calc);
assertEquals(CalcImpl.class, ProxettaUtil.getTargetClass(object.getClass()));
assertEquals(1, calc2Class.getInterfaces().length);
builder.injectTargetIntoWrapper(calc, object);
// counter in static block !!!
assertEquals(1, StatCounter.counter);
Method method = calc2Class.getMethod("hello");
assertNotNull(method);
method.invoke(object);
assertEquals(2, StatCounter.counter);
method = calc2Class.getMethod("calculate", int.class, int.class);
assertNotNull(method);
Integer result = (Integer) method.invoke(object, 3, 7);
assertEquals(10, result.intValue());
assertEquals(3, StatCounter.counter);
assertNotNull(calc2Class.getMethod("customMethod"));
}
Aggregations