Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-dev] Testing advice blocks using reflection, a tool users perspective question

Hi everyone,

I've hit an issue with how to invoke advice usefully from the unit test method bodies in aUnit. What makes the most sense when it comes to invoking the methods? How do we identify, by name, a specific advice block that uses a different, or the same, set of pointcuts? Don't want to tie this to source code ordering if possible. The problem is:

If I have an aspect such as:

public aspect BeforeAdviceExampleAspect
{
   before() : within(BeforeAdviceExampleAspect) && !within(BeforeAdviceExampleAspect)
   {
      System.out.println("Executing Before Advice");
   }
   
   before() : within(BeforeAdviceExampleAspect) && !within(BeforeAdviceExampleAspect)
   {
      System.out.println("Executing Second Before Advice");
   }
   
   public void callMethod()
   {
      System.out.println("Called method on before advice");
   }
}

Both advice blocks will select the same join point and their signatures using un-enhanced AspectJ/Java reflection are:

Advice block found: public void aunit.tests.usecases.BeforeAdviceExampleAspect.ajc$before$aunit_tests_usecases_BeforeAdviceExampleAspect$1$999acf7c()
Executing Before Advice

Advice block found: public void aunit.tests.usecases.BeforeAdviceExampleAspect.ajc$before$aunit_tests_usecases_BeforeAdviceExampleAspect$2$999acf7c()
Executing Second Before Advice

So, the ordering seems to be given by the $1 or $2 part of the name. But apart from that there is no way to tell the advice blocks apart. After reversing the order of the advice in the source aspect the results looks like:

Advice block found: public void aunit.tests.usecases.BeforeAdviceExampleAspect.ajc$before$aunit_tests_usecases_BeforeAdviceExampleAspect$1$999acf7c()
Executing Second Before Advice

Advice block found: public void aunit.tests.usecases.BeforeAdviceExampleAspect.ajc$before$aunit_tests_usecases_BeforeAdviceExampleAspect$2$999acf7c()
Executing Before Advice

This proves to me that the $1 and $2 are source code location dependant; makes sense really. But this doesn't help in trying to understand how developers could easily specify that they are testing a particular piece of advice using regular Java syntax.

Any suggestions from the community?

Cheers,

Russ



Back to the top