Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Declaring Annotations - testCase

hi Andrew, thanks for replying me so fast.

i tried to provide a case as simple as possible, even changing the logic of the test (because the previous was weird and probably misleading to something different).

So, here we go:
( for a nicely highlighted version http://veleno.pastebin.com/311945 and http://veleno.pastebin.com/311950 )

junit.framework.AssertionFailedError
   at junit.framework.Assert.fail(Assert.java:47)
   at junit.framework.Assert.assertTrue(Assert.java:20)
   at junit.framework.Assert.assertTrue(Assert.java:27)
at aormf.tests.AnnotationDeclarationTest.testDeclareAnnotationPOJO(AnnotationDeclarationTest.java:108)

public void testDeclareAnnotationPOJO() throws SecurityException, NoSuchMethodException { Pusher pi = new PusherImpl(); Class[] itfs = pi.getClass().getInterfaces(); Class annotatedPusherInterface = null; for (Class itf: itfs)
           if (itf.getName() == "aormf.components.Pusher")
           annotatedPusherInterface = itf;
assertTrue(annotatedPusherInterface.getName().equalsIgnoreCase(fPusherInterfaceName)); Method pushMethod = annotatedPusherInterface.getMethod(fPushMethod, String.class); assertTrue(pushMethod.isAnnotationPresent(ManagedResourceAnnotation.class)); }

public aspect AnnotatorAspect {

       declare @method: public * Pusher+.*(..): @ManagedResourceAnnotation;
}

public interface Pusher {
void push (String s);

}

public class PusherImpl implements Pusher {

   public void push(String s) {
       // TODO Auto-generated method stub
   }
}

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;

/**
* Marker annotation to indicate that a resource has to be monitored
*
* @author valerio
*
*/

/*meta-annotation target only methods */
@Target({ElementType.METHOD})

/*meta-annotation to change default retention policy to runtime*/
@Retention(RetentionPolicy.RUNTIME)

public @interface ManagedResourceAnnotation  {

}


The purpose, as before, is to test the presence of a given annotation (ManagedResourceAnnotation)

Andrew Clement ha scritto:

Couple of things, firstly you might have hit bug bug 98901 (
https://bugs.eclipse.org/bugs/show_bug.cgi?id=98901 )  - it has been fixed
but the fix isn't available in a build yet.

Secondly, do you know which method is returning an empty set of
annotations?  It might be worth printing it out to confirm its one you
expect to be matched by the declared @method construct - since I see no
logic in your loop that only ensures you ask for the  annotations on the
public declared methods.

cheers,
Andy.




Back to the top