mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
junit: run method in parameterized test (IDEA-79475)
This commit is contained in:
@@ -17,6 +17,8 @@ package com.intellij.junit4;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.internal.AssumptionViolatedException;
|
||||
import org.junit.internal.builders.AllDefaultPossibilitiesBuilder;
|
||||
import org.junit.internal.builders.AnnotatedBuilder;
|
||||
import org.junit.internal.requests.ClassRequest;
|
||||
import org.junit.internal.runners.model.EachTestNotifier;
|
||||
import org.junit.runner.Description;
|
||||
@@ -26,11 +28,15 @@ import org.junit.runner.Runner;
|
||||
import org.junit.runner.manipulation.Filter;
|
||||
import org.junit.runner.notification.RunNotifier;
|
||||
import org.junit.runners.BlockJUnit4ClassRunner;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.ParentRunner;
|
||||
import org.junit.runners.model.FrameworkMethod;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
@@ -115,7 +121,8 @@ public class JUnit4TestRunnerUtil {
|
||||
if (index != -1) {
|
||||
final Class clazz = loadTestClass(suiteClassName.substring(0, index));
|
||||
final String methodName = suiteClassName.substring(index + 1);
|
||||
if (clazz.getAnnotation(RunWith.class) == null) { //do not override external runners
|
||||
final RunWith clazzAnnotation = (RunWith)clazz.getAnnotation(RunWith.class);
|
||||
if (clazzAnnotation == null) { //do not override external runners
|
||||
try {
|
||||
Class.forName("org.junit.runners.BlockJUnit4ClassRunner"); //ignore IgnoreIgnored for junit4.4 and <
|
||||
final Method method = clazz.getMethod(methodName, null);
|
||||
@@ -146,6 +153,17 @@ public class JUnit4TestRunnerUtil {
|
||||
catch (Exception ignored) {
|
||||
//return simple method runner
|
||||
}
|
||||
} else {
|
||||
final Class runnerClass = clazzAnnotation.value();
|
||||
if (runnerClass.isAssignableFrom(Parameterized.class)) {
|
||||
try {
|
||||
Class.forName("org.junit.runners.BlockJUnit4ClassRunner"); //ignore for junit4.4 and <
|
||||
return Request.runner(new ParameterizedMethodRunner(clazz, methodName));
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
//return simple method runner
|
||||
}
|
||||
}
|
||||
}
|
||||
return Request.method(clazz, methodName);
|
||||
}
|
||||
@@ -230,4 +248,35 @@ public class JUnit4TestRunnerUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class ParameterizedMethodRunner extends Parameterized {
|
||||
private final String myMethodName;
|
||||
|
||||
public ParameterizedMethodRunner(Class clazz, String methodName) throws Throwable {
|
||||
super(clazz);
|
||||
myMethodName = methodName;
|
||||
}
|
||||
|
||||
protected List getChildren() {
|
||||
final List children = super.getChildren();
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
try {
|
||||
final BlockJUnit4ClassRunner child = (BlockJUnit4ClassRunner)children.get(i);
|
||||
final Method getChildrenMethod = BlockJUnit4ClassRunner.class.getDeclaredMethod("getChildren", new Class[0]);
|
||||
getChildrenMethod.setAccessible(true);
|
||||
final List list = (List)getChildrenMethod.invoke(child, new Object[0]);
|
||||
for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {
|
||||
final FrameworkMethod description = (FrameworkMethod)iterator.next();
|
||||
if (!description.getName().equals(myMethodName)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return children;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user