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.

CflowTest.java 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. * initial implementation Alexandre Vasseur
  11. *******************************************************************************/
  12. package ataspectj;
  13. import org.aspectj.lang.annotation.Aspect;
  14. import org.aspectj.lang.annotation.Before;
  15. import org.aspectj.lang.annotation.Before;
  16. import org.aspectj.lang.annotation.SuppressAjWarnings;
  17. import org.aspectj.lang.JoinPoint;
  18. import org.aspectj.lang.ProceedingJoinPoint;
  19. import org.aspectj.runtime.internal.CFlowCounter;
  20. import junit.framework.TestCase;
  21. /**
  22. * Test cflow (LTW of the aspect to add cflow fields to it)
  23. *
  24. * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
  25. */
  26. public class CflowTest extends TestCase {
  27. static StringBuffer s_log = new StringBuffer();
  28. static void log(String s) {
  29. s_log.append(s).append(" ");
  30. }
  31. public static void main(String[] args) {
  32. TestHelper.runAndThrowOnFailure(suite());
  33. }
  34. public static junit.framework.Test suite() {
  35. return new junit.framework.TestSuite(CflowTest.class);
  36. }
  37. public void hello() {
  38. log("hello");
  39. }
  40. public void startCflow() {
  41. hello();
  42. }
  43. public void testCflow() {
  44. CflowTest me = new CflowTest();
  45. s_log = new StringBuffer();
  46. me.hello();
  47. assertEquals("hello ", s_log.toString());
  48. s_log = new StringBuffer();
  49. me.startCflow();
  50. assertEquals("before hello ", s_log.toString());
  51. }
  52. @Aspect
  53. public static class TestAspect {
  54. //LTW will add:
  55. //public static final CFlowCounter ajc$cflowCounter$0 = new CFlowCounter();
  56. @SuppressAjWarnings
  57. @Before("execution(* ataspectj.CflowTest.hello(..)) && this(t) && cflow(execution(* ataspectj.CflowTest.startCflow(..)))")
  58. public void before(Object t, JoinPoint jp) {
  59. assertEquals(CflowTest.class.getName(), t.getClass().getName());
  60. try {
  61. //jp.proceed();
  62. } catch (Throwable throwable) {
  63. fail("proceed called in before Advice must be a NO-OP:" + throwable.toString());
  64. }
  65. log("before");
  66. }
  67. }
  68. }