Community
Participate
Working Groups
I was working on aspect that should raise an error for junit test methods that didn't use any assertions. Apparently I had to use pointcut like "call(void Assert+.assert*(..))" on which ajdt compiler complained about using "assert" keyword. I don't think such warning should be shown in such case. Anyway, here is the complete aspect code. import junit.framework.Test; import junit.framework.Assert; import junit.framework.AssertionFailedError; public aspect AssertionCounter { private ThreadLocal counts = new ThreadLocal(); public pointcut testMethodExecution() : execution(void Test+.test*()); public pointcut assertCall() : cflow(testMethodExecution()) && call(void Assert+.assert*(..)); void around() : testMethodExecution() { counts.set( new Counter()); proceed(); if(((Counter) counts.get()).getCount()==0) { throw new AssertionFailedError("No assertions had been called"); } } before() : assertCall() { ((Counter) counts.get()).inc(); } }
The code to generate the warning was deep in the JDT parser. This issue (and a related one of using "enum" inside a pointcut expression in a similar way) is now fixed... by an aspect that suppresses the warning if made whilst processing a pseudo-token stream. Fix will be available in next published build from AspectJ downloads page, and incorporated into AJDT on Monday of next week (21st).