Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Defining pointcuts or aspects within a normal java class

Hi Piers,
you can define pointcuts in normal java classes, and then use it from
aspects outside that class, as long as they are public or of a suitable
access type (like, package protected and the aspect in the same
package). You can also define an aspect as an inner class, so that the
code is in a single place.

Hope this helps,
Simone

Piers wrote:
> Hi
>
> I am a total newbie to AspectJ, so apologies in advance if this
> question is stupid.
>
> Quick question - Is either of the above possible and how?
>
> If more explanation is required then read on -
>
> I want to create an aspect for unit testing that can be used to
> replace method call return values with mock objects. I can do this
> already but I have to define the mocks, pointcuts and advice in an
> aspect and define separate pointcuts and advice for each object I want
> to replace. The downside is that looking at the test function it is
> not clear what is going on and I am defining a lot of around advice
> which essentially all does the same thing -(return a mock for a given
> pointcut).  I was thinking that maybe it would be possible to make a
> method call within the test class, having for parameters a list of
> mock objects and a list of pointcuts, which is intercepted by an
> aspect that exposes the pointcuts and objects and can then use around
> advice on the specified pointcuts to replace the return values of
> those calls with the mock objects.
>
> Or I would like to define an aspect within my test class so that it
> can have access to all the mock objects used.
>
> Thanks
>
> Piers
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users


-- 
Simone Gianni            Semeru s.r.l.           Apache Committer
http://www.simonegianni.it/



Back to the top