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.

DeclareParentsInterfaceTest.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. * Alexandre Vasseur initial implementation
  11. *******************************************************************************/
  12. package ataspectj;
  13. import junit.framework.TestCase;
  14. import org.aspectj.lang.annotation.Aspect;
  15. import org.aspectj.lang.annotation.Before;
  16. import org.aspectj.lang.annotation.DeclareParents;
  17. import java.util.Arrays;
  18. /**
  19. * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
  20. */
  21. public class DeclareParentsInterfaceTest extends TestCase {
  22. static class Target {
  23. void target() {
  24. log("hello");
  25. }
  26. }
  27. static interface Marker {}
  28. @Aspect
  29. static class TestAspect {
  30. @DeclareParents("ataspectj.DeclareParentsInterfaceTest.Target")
  31. Marker introduce;
  32. @Before("execution(* ataspectj.DeclareParentsInterfaceTest.Marker+.target())")
  33. public void before() {
  34. log("aop");
  35. }
  36. }
  37. static StringBuffer s_log = new StringBuffer();
  38. static void log(String s) {
  39. s_log.append(s).append(" ");
  40. }
  41. public void testDecPInt() {
  42. Class[] intfs = Target.class.getInterfaces();
  43. assertTrue("Was not introduced", Arrays.asList(intfs).contains(Marker.class));
  44. }
  45. public void testDecPIntAdvised() {
  46. s_log = new StringBuffer();
  47. new Target().target();
  48. assertEquals("aop hello ", s_log.toString());
  49. }
  50. public static void main(String[] args) {
  51. TestHelper.runAndThrowOnFailure(suite());
  52. }
  53. public static junit.framework.Test suite() {
  54. return new junit.framework.TestSuite(DeclareParentsInterfaceTest.class);
  55. }
  56. }