package com.mysema.query;

import java.lang.annotation.Annotation;

import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;

import com.mysema.testutil.EmptyStatement;

/**
 * @author tiwe
 *
 */
public class JPAProviderRule implements MethodRule {

    @Override
    public Statement apply(Statement base, FrameworkMethod method, Object target) {
        boolean noEclipseLink = hasAnnotation(method, NoEclipseLink.class);
        boolean noOpenJPA = hasAnnotation(method, NoOpenJPA.class);
        boolean noBatooJPA = hasAnnotation(method, NoBatooJPA.class);
        boolean noHibernate = hasAnnotation(method, NoHibernate.class);
        String mode = Mode.mode.get();
        if (mode == null) {
            return base;
        } else if (noEclipseLink && mode.contains("-eclipselink")) {
            return EmptyStatement.DEFAULT;
        } else if (noOpenJPA && mode.contains("-openjpa")) {
            return EmptyStatement.DEFAULT;
        } else if (noBatooJPA && mode.contains("-batoo")) {
            return EmptyStatement.DEFAULT;
        } else if (noHibernate && !mode.contains("-")) {
            return EmptyStatement.DEFAULT;
        } else {
            return base;
        }
    }
    
    private <T extends Annotation> boolean hasAnnotation(FrameworkMethod method, Class<T> clazz) {
        T rv = method.getMethod().getAnnotation(clazz);
        if (rv == null) {
            rv = method.getMethod().getDeclaringClass().getAnnotation(clazz);
        }
        return rv != null;
    }

}

@@ -1381,14 +1381,14 @@
     
-T rv =
+return
  met
@@ -1403,19 +1403,18 @@
 ethod().
-get
+is
 Annotati
@@ -1411,32 +1411,38 @@
 isAnnotation
+Present
 (clazz)
-;
 %0A        if 
@@ -1442,42 +1442,18 @@
     
-if (rv == null) %7B%0A            rv =
+        %7C%7C
  met
@@ -1488,19 +1488,18 @@
 Class().
-get
+is
 Annotati
@@ -1504,52 +1504,22 @@
 tion
+Present
 (clazz)
-;%0A        %7D%0A        return rv != null
 ;%0A  

Use the isAnnotationPresent method for annotation presence checking