[testng] 246/355: Fix #87
Eugene Zhukov
eugene-guest at moszumanska.debian.org
Tue Aug 18 10:20:11 UTC 2015
This is an automated email from the git hooks/post-receive script.
eugene-guest pushed a commit to annotated tag OpenBSD
in repository testng.
commit e7eac6a771d8258a000d5f6e75145bbd48a128da
Author: Julien Herr <julien.herr at alcatel-lucent.com>
Date: Thu Apr 30 13:18:06 2015 +0200
Fix #87
---
.../org/testng/internal/MethodGroupsHelper.java | 2 +-
.../internal/annotations/AnnotationHelper.java | 4 +++
.../internal/annotations/IAnnotationFinder.java | 2 ++
.../annotations/JDK15AnnotationFinder.java | 31 ++++++++++++++++++----
4 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/testng/internal/MethodGroupsHelper.java b/src/main/java/org/testng/internal/MethodGroupsHelper.java
index 622a122..1923d07 100644
--- a/src/main/java/org/testng/internal/MethodGroupsHelper.java
+++ b/src/main/java/org/testng/internal/MethodGroupsHelper.java
@@ -64,7 +64,7 @@ public class MethodGroupsHelper {
}
}
else {
- in = MethodGroupsHelper.includeMethod(AnnotationHelper.findTest(finder, m),
+ in = MethodGroupsHelper.includeMethod(AnnotationHelper.findTest(finder, tm),
runInfo, tm, forTests, unique, outIncludedMethods);
}
}
diff --git a/src/main/java/org/testng/internal/annotations/AnnotationHelper.java b/src/main/java/org/testng/internal/annotations/AnnotationHelper.java
index 51b931a..6375c58 100755
--- a/src/main/java/org/testng/internal/annotations/AnnotationHelper.java
+++ b/src/main/java/org/testng/internal/annotations/AnnotationHelper.java
@@ -35,6 +35,10 @@ public class AnnotationHelper {
return finder.findAnnotation(m, ITestAnnotation.class);
}
+ public static ITestAnnotation findTest(IAnnotationFinder finder, ITestNGMethod m) {
+ return finder.findAnnotation(m, ITestAnnotation.class);
+ }
+
public static IFactoryAnnotation findFactory(IAnnotationFinder finder, Method m) {
return finder.findAnnotation(m, IFactoryAnnotation.class);
}
diff --git a/src/main/java/org/testng/internal/annotations/IAnnotationFinder.java b/src/main/java/org/testng/internal/annotations/IAnnotationFinder.java
index df57c0b..a52b6e5 100755
--- a/src/main/java/org/testng/internal/annotations/IAnnotationFinder.java
+++ b/src/main/java/org/testng/internal/annotations/IAnnotationFinder.java
@@ -1,5 +1,6 @@
package org.testng.internal.annotations;
+import org.testng.ITestNGMethod;
import org.testng.annotations.IAnnotation;
import java.lang.reflect.Constructor;
@@ -30,6 +31,7 @@ public interface IAnnotationFinder {
* If not found, return null.
*/
public <A extends IAnnotation> A findAnnotation(Method m, Class<A> annotationClass);
+ <A extends IAnnotation> A findAnnotation(ITestNGMethod m, Class<A> annotationClass);
/**
* @param cons
diff --git a/src/main/java/org/testng/internal/annotations/JDK15AnnotationFinder.java b/src/main/java/org/testng/internal/annotations/JDK15AnnotationFinder.java
index b3ef0bf..0130e1a 100755
--- a/src/main/java/org/testng/internal/annotations/JDK15AnnotationFinder.java
+++ b/src/main/java/org/testng/internal/annotations/JDK15AnnotationFinder.java
@@ -8,6 +8,7 @@ import java.util.Map;
import org.testng.IAnnotationTransformer;
import org.testng.IAnnotationTransformer2;
+import org.testng.ITestNGMethod;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.AfterMethod;
@@ -100,7 +101,27 @@ public class JDK15AnnotationFinder implements IAnnotationFinder {
if (a == null) {
throw new IllegalArgumentException("Java @Annotation class for '" + annotationClass + "' not found.");
}
- return findAnnotation(m.getDeclaringClass(), m.getAnnotation(a), annotationClass, null, null, m);
+ return findAnnotation(m.getAnnotation(a), annotationClass, m.getDeclaringClass(), null, m);
+ }
+
+ @Override
+ public <A extends IAnnotation> A findAnnotation(ITestNGMethod tm, Class<A> annotationClass) {
+ final Class<? extends Annotation> a = m_annotationMap.get(annotationClass);
+ if (a == null) {
+ throw new IllegalArgumentException("Java @Annotation class for '" + annotationClass + "' not found.");
+ }
+ Method m = tm.getMethod();
+ Class<?> testClass;
+ if (tm.getInstance() == null) {
+ testClass = m.getDeclaringClass();
+ } else {
+ testClass = tm.getInstance().getClass();
+ }
+ Annotation annotation = m.getAnnotation(a);
+ if (annotation == null) {
+ annotation = testClass.getAnnotation(a);
+ }
+ return findAnnotation(annotation, annotationClass, testClass, null, m);
}
private void transform(IAnnotation a, Class testClass,
@@ -146,7 +167,7 @@ public class JDK15AnnotationFinder implements IAnnotationFinder {
if (a == null) {
throw new IllegalArgumentException("Java @Annotation class for '" + annotationClass + "' not found.");
}
- return findAnnotation(cls, findAnnotationInSuperClasses(cls, a), annotationClass, cls, null, null);
+ return findAnnotation(findAnnotationInSuperClasses(cls, a), annotationClass, cls, null, null);
}
@Override
@@ -155,12 +176,12 @@ public class JDK15AnnotationFinder implements IAnnotationFinder {
if (a == null) {
throw new IllegalArgumentException("Java @Annotation class for '" + annotationClass + "' not found.");
}
- return findAnnotation(cons.getDeclaringClass(), cons.getAnnotation(a), annotationClass, null, cons, null);
+ return findAnnotation(cons.getAnnotation(a), annotationClass, cons.getDeclaringClass(), cons, null);
}
private Map<Pair<Annotation, ?>, IAnnotation> m_annotations = Maps.newHashMap();
- private <A extends IAnnotation> A findAnnotation(Class cls, Annotation a,
+ private <A extends IAnnotation> A findAnnotation(Annotation a,
Class<A> annotationClass,
Class testClass, Constructor testConstructor, Method testMethod) {
final Pair<Annotation, ?> p;
@@ -174,7 +195,7 @@ public class JDK15AnnotationFinder implements IAnnotationFinder {
//noinspection unchecked
A result = (A) m_annotations.get(p);
if (result == null) {
- result = m_tagFactory.createTag(cls, a, annotationClass, m_transformer);
+ result = m_tagFactory.createTag(testClass, a, annotationClass, m_transformer);
m_annotations.put(p, result);
transform(result, testClass, testConstructor, testMethod);
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/testng.git
More information about the pkg-java-commits
mailing list