5dd905f suffered from a ClassLoader issue visible only in maven-junit-plugin (not Surefire).

This commit is contained in:
Jesse Glick committed 2012-09-05 19:18:43 -04:00
1 parent 0805db1e24
commit 4557a436bf
2 files changed
+10 -10

No files matched your search

@@ -58,6 +58,7 @@ public class TestEnvironment {
/**
* Current test case being run (works for JUnit 3 or 4).
* Warning: {@link Description#getTestClass} is currently broken in some environments. Use {@link Description#getClassName} instead.
*/
public @Nonnull Description description() {
if (description != null) {
@@ -65,25 +65,24 @@ public class TestExtensionLoader extends GuiceExtensionAnnotation<TestExtension>
Description description = env.description();
if (testName.length()>0 && !testName.equals(description.getMethodName()))
return false; // doesn't apply to this test
String className = description.getClassName();
if (e instanceof Class) {
return isActive(description, (Class)e);
for (Class<?> outer = (Class) e; outer != null; outer = outer.getEnclosingClass()) {
if (outer.getName().equals(className)) {
return true; // enclosed
}
}
return false;
}
if (e instanceof Field) {
Field f = (Field) e;
return f.getDeclaringClass() == description.getTestClass();
return f.getDeclaringClass().getName().equals(className);
}
if (e instanceof Method) {
Method m = (Method) e;
return m.getDeclaringClass() == description.getTestClass();
return m.getDeclaringClass().getName().equals(className);
}
return false;
}
private boolean isActive(Description description, Class<?> extType) {
for (Class<?> outer = extType; outer!=null; outer=outer.getEnclosingClass())
if (outer == description.getTestClass())
return true; // enclosed
return false;
}
}