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.

PrecedenceTest.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*******************************************************************************
  2. * Copyright (c) Jonas Bonér, Alexandre Vasseur
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Common Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/cpl-v10.html
  7. *******************************************************************************/
  8. package ataspectj;
  9. import junit.framework.TestCase;
  10. import org.aspectj.lang.annotation.Before;
  11. import org.aspectj.lang.annotation.Aspect;
  12. import org.aspectj.lang.annotation.DeclarePrecedence;
  13. import org.aspectj.lang.annotation.Aspect;
  14. import org.aspectj.lang.annotation.Before;
  15. /**
  16. * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
  17. */
  18. public class PrecedenceTest extends TestCase {
  19. static StringBuffer s_log = new StringBuffer();
  20. static void log(String s) {
  21. s_log.append(s).append(" ");
  22. }
  23. public static void main(String[] args) {
  24. TestHelper.runAndThrowOnFailure(suite());
  25. }
  26. public static junit.framework.Test suite() {
  27. return new junit.framework.TestSuite(PrecedenceTest.class);
  28. }
  29. public void hello() {
  30. log("hello");
  31. }
  32. public void testPrecedence() {
  33. s_log = new StringBuffer();
  34. hello();
  35. assertEquals("TestAspect_3 TestAspect_2 TestAspect_1 hello", s_log.toString());
  36. }
  37. @Aspect()
  38. public static class TestAspect_1 {
  39. @Before("execution(* ataspectj.PrecedenceTest.hello())")
  40. void before() {
  41. log("TestAspect_1");
  42. }
  43. }
  44. @Aspect()
  45. @DeclarePrecedence("ataspectj.PrecedenceTest.TestAspect_3, ataspectj.PrecedenceTest.TestAspect_1")
  46. public static class TestAspect_2 {
  47. @Before("execution(* ataspectj.PrecedenceTest.hello())")
  48. void before() {
  49. log("TestAspect_2");
  50. }
  51. }
  52. @Aspect()
  53. public static class TestAspect_3 {
  54. @Before("execution(* ataspectj.PrecedenceTest.hello())")
  55. void before() {
  56. log("TestAspect_3");
  57. }
  58. }
  59. @Aspect()
  60. @DeclarePrecedence("ataspectj.PrecedenceTest.TestAspect_3, ataspectj.PrecedenceTest.TestAspect_2, ataspectj.PrecedenceTest.TestAspect_1, *")
  61. public static class TestAspect_Order {
  62. }
  63. }