You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Bug.java 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package example;
  2. import java.lang.annotation.ElementType;
  3. import java.lang.annotation.Inherited;
  4. import java.lang.annotation.Retention;
  5. import java.lang.annotation.RetentionPolicy;
  6. import java.lang.annotation.Target;
  7. import junit.framework.TestCase;
  8. import org.aspectj.lang.Aspects;
  9. import org.aspectj.lang.annotation.Aspect;
  10. import org.aspectj.lang.annotation.Before;
  11. public class Bug extends TestCase {
  12. public void testAdviceMatch() {
  13. TestImpl impl = new TestImpl();
  14. impl.method();
  15. assertEquals(0, Aspects.aspectOf(TestAtAspect.class).count);
  16. // assertEquals(0, TestAspect.aspectOf().count);
  17. }
  18. @Retention(RetentionPolicy.RUNTIME)
  19. @Target(ElementType.TYPE)
  20. @Inherited
  21. static @interface TestAnnotation {
  22. }
  23. @TestAnnotation
  24. static interface TestInterface {
  25. void method();
  26. }
  27. static class TestImpl implements TestInterface {
  28. // @Override
  29. public void method() {
  30. }
  31. }
  32. // static aspect TestAspect {
  33. // int count = 0;
  34. //
  35. // before() : @target(example.Bug.TestAnnotation)+ && execution(* *(..)) {
  36. // count++;
  37. // }
  38. // }
  39. @Aspect
  40. static class TestAtAspect {
  41. int count = 0;
  42. @Before("@target(example.Bug.TestAnnotation)+ && execution(* *(..))")
  43. public void increment() {
  44. count++;
  45. }
  46. }
  47. }