Package jodd.proxetta

Source Code of jodd.proxetta.AdviceWithMethodTest

// Copyright (c) 2003-2014, Jodd Team (jodd.org). All Rights Reserved.

package jodd.proxetta;

import jodd.proxetta.data.CollectorAdvice;
import jodd.proxetta.data.Foo;
import jodd.proxetta.impl.ProxyProxetta;
import jodd.proxetta.pointcuts.AllTopMethodsPointcut;
import org.junit.Test;

import java.lang.reflect.Field;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class AdviceWithMethodTest {

  @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));
  }
}
TOP

Related Classes of jodd.proxetta.AdviceWithMethodTest

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.