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.

PointcutsTest.java 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* *******************************************************************
  2. * Copyright (c) 2005 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Wes Isberg initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.lib.pointcuts;
  13. import junit.framework.TestCase;
  14. /**
  15. *
  16. */
  17. public class PointcutsTest extends TestCase {
  18. public void test_anyPublicMethodExecution() {
  19. try {
  20. Test_anyPublicMethodExecution.error();
  21. assertTrue("no exception thrown", false);
  22. } catch (Error e) {
  23. // ok, advice worked
  24. }
  25. }
  26. private static aspect Test_anyPublicMethodExecution {
  27. public static void error() {
  28. throw new RuntimeException("wrong exception");
  29. }
  30. static void nonpublic() {}
  31. before() :
  32. execution(static void Test_anyPublicMethodExecution.error())
  33. && Pointcuts.anyPublicMethodExecution() {
  34. throw new Error("");
  35. }
  36. declare error :
  37. execution(static void Test_anyPublicMethodExecution.nonpublic())
  38. && Pointcuts.anyPublicMethodExecution()
  39. : "anyPublicMethodExecution failed - not public";
  40. }
  41. private static aspect compileChecks {
  42. /** balk if Pointcuts has code - s.b. only pointcuts */
  43. declare error : within(Pointcuts) &&
  44. (set(* *) || Pointcuts.anyMethodExecution() ||
  45. (Pointcuts.anyConstructorExecution()
  46. && !execution(private Pointcuts.new()))) :
  47. "only pointcuts permitted in Pointcuts";
  48. }
  49. }