mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
Generification, for-each loop, other warnings fixed
GitOrigin-RevId: aa737f386ad5f59aa7efaf5c7e8343f79394a2ae
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c8decba90a
commit
8dca11ef81
@@ -8,8 +8,8 @@ public abstract class TestDiscoveryListener {
|
||||
public void testStarted(String className, String methodName) {
|
||||
try {
|
||||
final Object data = getData();
|
||||
Method testStarted = data.getClass().getMethod("testDiscoveryStarted", new Class[] {String.class, String.class});
|
||||
testStarted.invoke(data, new Object[] {className, methodName});
|
||||
Method testStarted = data.getClass().getMethod("testDiscoveryStarted", String.class, String.class);
|
||||
testStarted.invoke(data, className, methodName);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
@@ -19,8 +19,8 @@ public abstract class TestDiscoveryListener {
|
||||
if (succeed) {
|
||||
try {
|
||||
final Object data = getData();
|
||||
Method testEnded = data.getClass().getMethod("testDiscoveryEnded", new Class[] {String.class, String.class});
|
||||
testEnded.invoke(data, new Object[] {className, methodName});
|
||||
Method testEnded = data.getClass().getMethod("testDiscoveryEnded", String.class, String.class);
|
||||
testEnded.invoke(data, className, methodName);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
@@ -29,8 +29,8 @@ public abstract class TestDiscoveryListener {
|
||||
|
||||
protected Object getData() throws Exception {
|
||||
return Class.forName("com.intellij.rt.coverage.data.TestDiscoveryProjectData")
|
||||
.getMethod("getProjectData", new Class[0])
|
||||
.invoke(null, new Object[0]);
|
||||
.getMethod("getProjectData")
|
||||
.invoke(null);
|
||||
}
|
||||
|
||||
public void testRunStarted(String name) {}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class FormPreviewFrame {
|
||||
|
||||
JFrame frame = new JFrame(ourBundle.getString("form.preview.title"));
|
||||
frame.setContentPane(f.myComponent);
|
||||
frame.setDefaultCloseOperation(3); //WindowConstants.EXIT_ON_CLOSE is not presented in JDK 1.3
|
||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
|
||||
// Add menu bar
|
||||
final JMenuBar menuBar = new JMenuBar();
|
||||
@@ -36,8 +36,8 @@ public class FormPreviewFrame {
|
||||
menuBar.add(viewMenu);
|
||||
|
||||
final UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels();
|
||||
for(int i = 0; i < lafs.length; i++){
|
||||
viewMenu.add(new MySetLafAction(frame, lafs[i]));
|
||||
for (UIManager.LookAndFeelInfo laf : lafs) {
|
||||
viewMenu.add(new MySetLafAction(frame, laf));
|
||||
}
|
||||
|
||||
frame.pack();
|
||||
@@ -93,7 +93,7 @@ public class FormPreviewFrame {
|
||||
catch(Exception exc){
|
||||
JOptionPane.showMessageDialog(
|
||||
myFrame,
|
||||
MessageFormat.format(ourBundle.getString("error.cannot.change.look.feel"), new Object[] {exc.getMessage()}),
|
||||
MessageFormat.format(ourBundle.getString("error.cannot.change.look.feel"), exc.getMessage()),
|
||||
ourBundle.getString("error.title"),
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
|
||||
@@ -56,7 +56,7 @@ public class TestAllInPackage2 extends TestSuite {
|
||||
}
|
||||
}
|
||||
}
|
||||
String message = TestRunnerUtil.testsFoundInPackageMesage(testClassCount, name);
|
||||
String message = TestRunnerUtil.testsFoundInPackageMessage(testClassCount, name);
|
||||
System.out.println(message);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Vector;
|
||||
|
||||
public class TestRunnerUtil {
|
||||
/** @noinspection HardCodedStringLiteral*/
|
||||
@@ -40,9 +40,8 @@ public class TestRunnerUtil {
|
||||
if (suiteClassNames.length == 0) {
|
||||
return null;
|
||||
}
|
||||
Vector result = new Vector();
|
||||
for (int i = 0; i < suiteClassNames.length; i++) {
|
||||
String suiteClassName = suiteClassNames[i];
|
||||
ArrayList<Test> result = new ArrayList<Test>();
|
||||
for (String suiteClassName : suiteClassNames) {
|
||||
Test test;
|
||||
if (suiteClassName.charAt(0) == '@') {
|
||||
// all tests in the package specified
|
||||
@@ -50,17 +49,17 @@ public class TestRunnerUtil {
|
||||
String suiteName;
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(suiteClassName.substring(1)), "UTF-8"));
|
||||
Vector vector;
|
||||
ArrayList<String> vector;
|
||||
try {
|
||||
suiteName = reader.readLine();
|
||||
|
||||
reader.readLine(); //category
|
||||
reader.readLine();//filters
|
||||
|
||||
vector = new Vector();
|
||||
vector = new ArrayList<String>();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
vector.addElement(line);
|
||||
vector.add(line);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
@@ -68,13 +67,11 @@ public class TestRunnerUtil {
|
||||
}
|
||||
|
||||
// toArray cannot be used here because the class must be compilable with 1.1
|
||||
classNames = new String[vector.size()];
|
||||
for (int j = 0; j < classNames.length; j++) {
|
||||
classNames[j] = (String)vector.elementAt(j);
|
||||
}
|
||||
//noinspection SSBasedInspection
|
||||
classNames = vector.toArray(new String[0]);
|
||||
}
|
||||
catch (Exception e) {
|
||||
runner.runFailed(MessageFormat.format(ourBundle.getString("junit.runner.error"), new Object[] {e.toString()}));
|
||||
runner.runFailed(MessageFormat.format(ourBundle.getString("junit.runner.error"), e.toString()));
|
||||
return null;
|
||||
}
|
||||
test = new TestAllInPackage2(runner, suiteName, classNames);
|
||||
@@ -83,15 +80,14 @@ public class TestRunnerUtil {
|
||||
test = createClassOrMethodSuite(runner, suiteClassName);
|
||||
if (test == null) return null;
|
||||
}
|
||||
result.addElement(test);
|
||||
result.add(test);
|
||||
}
|
||||
if (result.size() == 1) {
|
||||
return (Test)result.elementAt(0);
|
||||
return result.get(0);
|
||||
}
|
||||
else {
|
||||
TestSuite suite = new TestSuite();
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
final Test test = (Test)result.elementAt(i);
|
||||
for (final Test test : result) {
|
||||
suite.addTest(test);
|
||||
}
|
||||
return suite;
|
||||
@@ -106,38 +102,39 @@ public class TestRunnerUtil {
|
||||
suiteClassName = suiteClassName.substring(0, index);
|
||||
}
|
||||
|
||||
Class testClass = loadTestClass(runner, suiteClassName);
|
||||
Class<?> testClass = loadTestClass(runner, suiteClassName);
|
||||
if (testClass == null) return null;
|
||||
Test test = null;
|
||||
if (methodName == null) {
|
||||
if (test == null) {
|
||||
try {
|
||||
Method suiteMethod = testClass.getMethod(BaseTestRunner.SUITE_METHODNAME, new Class[0]);
|
||||
Method suiteMethod = testClass.getMethod(BaseTestRunner.SUITE_METHODNAME);
|
||||
if (!Modifier.isStatic(suiteMethod.getModifiers())) {
|
||||
String message = MessageFormat.format(ourBundle.getString("junit.suite.must.be.static"), new Object[]{testClass.getName()});
|
||||
String message = MessageFormat.format(ourBundle.getString("junit.suite.must.be.static"), testClass.getName());
|
||||
System.err.println(message);
|
||||
//runFailed(message);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
//noinspection SSBasedInspection
|
||||
test = (Test)suiteMethod.invoke(null, new Class[0]); // static method
|
||||
test = (Test)suiteMethod.invoke(null); // static method
|
||||
if (test == null) {
|
||||
return new FailedTestCase(testClass, BaseTestRunner.SUITE_METHODNAME,
|
||||
MessageFormat.format(ourBundle.getString("junit.failed.to.invoke.suite"), new Object[]{"method " + suiteClassName + ".suite() evaluates to null"}),
|
||||
MessageFormat.format(ourBundle.getString("junit.failed.to.invoke.suite"),
|
||||
"method " + suiteClassName + ".suite() evaluates to null"),
|
||||
null);
|
||||
}
|
||||
test = new SuiteMethodWrapper(test, suiteClassName);
|
||||
}
|
||||
catch (final InvocationTargetException e) {
|
||||
final String message = MessageFormat.format(ourBundle.getString("junit.failed.to.invoke.suite"), new Object[]{testClass + " " + e.getTargetException().toString()});
|
||||
final String message = MessageFormat.format(ourBundle.getString("junit.failed.to.invoke.suite"),
|
||||
testClass + " " + e.getTargetException().toString());
|
||||
//System.err.println(message);
|
||||
//runner.runFailed(message);
|
||||
runner.clearStatus();
|
||||
return new FailedTestCase(testClass, BaseTestRunner.SUITE_METHODNAME, message, e);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
String message = MessageFormat.format(ourBundle.getString("junit.failed.to.invoke.suite"), new Object[]{testClass + " " + e.toString()});
|
||||
String message = MessageFormat.format(ourBundle.getString("junit.failed.to.invoke.suite"), testClass + " " + e.toString());
|
||||
//System.err.println(message);
|
||||
//runner.runFailed(message);
|
||||
return new FailedTestCase(testClass, BaseTestRunner.SUITE_METHODNAME, message, e);
|
||||
@@ -156,7 +153,7 @@ public class TestRunnerUtil {
|
||||
return test;
|
||||
}
|
||||
|
||||
private static Class loadTestClass(JUnit3IdeaTestRunner runner, String suiteClassName) {
|
||||
private static Class<?> loadTestClass(JUnit3IdeaTestRunner runner, String suiteClassName) {
|
||||
try {
|
||||
return Class.forName(suiteClassName, false, TestRunnerUtil.class.getClassLoader());
|
||||
}
|
||||
@@ -165,58 +162,57 @@ public class TestRunnerUtil {
|
||||
if (clazz == null) {
|
||||
clazz = suiteClassName;
|
||||
}
|
||||
runner.runFailed(MessageFormat.format(ourBundle.getString("junit.class.not.found"), new Object[] {clazz}));
|
||||
runner.runFailed(MessageFormat.format(ourBundle.getString("junit.class.not.found"), clazz));
|
||||
}
|
||||
catch (Exception e) {
|
||||
runner.runFailed(MessageFormat.format(ourBundle.getString("junit.cannot.instantiate.tests"), new Object[]{e.toString()}));
|
||||
runner.runFailed(MessageFormat.format(ourBundle.getString("junit.cannot.instantiate.tests"), e.toString()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Test createMethodSuite(JUnit3IdeaTestRunner runner, Class testClass, String methodName) {
|
||||
private static Test createMethodSuite(JUnit3IdeaTestRunner runner, Class<?> testClass, String methodName) {
|
||||
runner.clearStatus();
|
||||
try {
|
||||
Constructor constructor = testClass.getConstructor(new Class[]{String.class});
|
||||
return (Test)constructor.newInstance(new Object[]{methodName});
|
||||
Constructor<?> constructor = testClass.getConstructor(String.class);
|
||||
return (Test)constructor.newInstance(methodName);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
try {
|
||||
Constructor constructor = testClass.getConstructor(new Class[0]);
|
||||
TestCase test = (TestCase)constructor.newInstance(new Object[0]);
|
||||
Constructor<?> constructor = testClass.getConstructor();
|
||||
TestCase test = (TestCase)constructor.newInstance();
|
||||
test.setName(methodName);
|
||||
return test;
|
||||
}
|
||||
catch(ClassCastException e1) {
|
||||
boolean methodExists;
|
||||
try {
|
||||
//noinspection SSBasedInspection
|
||||
testClass.getMethod(methodName, new Class[0]);
|
||||
testClass.getMethod(methodName);
|
||||
methodExists = true;
|
||||
}
|
||||
catch (NoSuchMethodException e2) {
|
||||
methodExists = false;
|
||||
}
|
||||
if (!methodExists) {
|
||||
String error = MessageFormat.format(ourBundle.getString("junit.method.not.found"), new Object[]{methodName});
|
||||
String message = MessageFormat.format(ourBundle.getString("junit.cannot.instantiate.tests"), new Object[]{error});
|
||||
String error = MessageFormat.format(ourBundle.getString("junit.method.not.found"), methodName);
|
||||
String message = MessageFormat.format(ourBundle.getString("junit.cannot.instantiate.tests"), error);
|
||||
return new FailedTestCase(testClass, methodName, message, null);
|
||||
}
|
||||
runner.runFailed(MessageFormat.format(ourBundle.getString("junit.class.not.derived"), new Object[]{testClass.getName()}));
|
||||
runner.runFailed(MessageFormat.format(ourBundle.getString("junit.class.not.derived"), testClass.getName()));
|
||||
return null;
|
||||
}
|
||||
catch (Exception e1) {
|
||||
String message = MessageFormat.format(ourBundle.getString("junit.cannot.instantiate.tests"), new Object[]{e1.toString()});
|
||||
String message = MessageFormat.format(ourBundle.getString("junit.cannot.instantiate.tests"), e1.toString());
|
||||
return new FailedTestCase(testClass, methodName, message, e1);
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
String message = MessageFormat.format(ourBundle.getString("junit.cannot.instantiate.tests"), new Object[]{e.toString()});
|
||||
String message = MessageFormat.format(ourBundle.getString("junit.cannot.instantiate.tests"), e.toString());
|
||||
return new FailedTestCase(testClass, methodName, message, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String testsFoundInPackageMesage(int testCount, String name) {
|
||||
return MessageFormat.format(ourBundle.getString("tests.found.in.package"), new Object[]{new Integer(testCount), name});
|
||||
public static String testsFoundInPackageMessage(int testCount, String name) {
|
||||
return MessageFormat.format(ourBundle.getString("tests.found.in.package"), new Integer(testCount), name);
|
||||
}
|
||||
|
||||
/** @noinspection JUnitTestClassNamingConvention, JUnitTestCaseWithNonTrivialConstructors, JUnitTestCaseWithNoTests */
|
||||
@@ -225,7 +221,7 @@ public class TestRunnerUtil {
|
||||
private final String myMessage;
|
||||
private final Throwable myThrowable;
|
||||
|
||||
public FailedTestCase(final Class testClass, final String methodName, final String message, final Throwable e) {
|
||||
public FailedTestCase(final Class<?> testClass, final String methodName, final String message, final Throwable e) {
|
||||
super(testClass.getName());
|
||||
myMethodName = methodName;
|
||||
myMessage = message;
|
||||
@@ -240,9 +236,8 @@ public class TestRunnerUtil {
|
||||
return myMessage;
|
||||
}
|
||||
|
||||
protected void runTest() throws Throwable {
|
||||
protected void runTest() {
|
||||
try {
|
||||
//noinspection Since15
|
||||
throw new RuntimeException(myMessage, myThrowable);
|
||||
}
|
||||
catch (NoSuchMethodError e) {
|
||||
|
||||
@@ -33,9 +33,9 @@ import org.junit.runners.model.FrameworkMethod;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class JUnit45ClassesRequestBuilder {
|
||||
public static Request getClassesRequest(String suiteName, Class[] classes) {
|
||||
public static Request getClassesRequest(String suiteName, Class<?>[] classes) {
|
||||
try {
|
||||
return Request.runner(new IdeaSuite(new org.junit.internal.builders.AllDefaultPossibilitiesBuilder(true), classes, suiteName));
|
||||
return Request.runner(new IdeaSuite(new AllDefaultPossibilitiesBuilder(true), classes, suiteName));
|
||||
}
|
||||
catch (Exception initializationError) {
|
||||
initializationError.printStackTrace();
|
||||
@@ -44,7 +44,7 @@ public class JUnit45ClassesRequestBuilder {
|
||||
}
|
||||
|
||||
|
||||
static Request createIgnoreIgnoredClassRequest(final Class clazz, final boolean recursively) throws ClassNotFoundException {
|
||||
static Request createIgnoreIgnoredClassRequest(final Class<?> clazz, final boolean recursively) throws ClassNotFoundException {
|
||||
Class.forName("org.junit.runners.BlockJUnit4ClassRunner"); //ignore IgnoreIgnored for junit4.4 and <
|
||||
return new ClassRequest(clazz) {
|
||||
public Runner getRunner() {
|
||||
@@ -63,7 +63,7 @@ public class JUnit45ClassesRequestBuilder {
|
||||
public Runner runnerForClass(Class testClass) throws Throwable {
|
||||
if (!recursively) return super.runnerForClass(testClass);
|
||||
try {
|
||||
Method ignored = BlockJUnit4ClassRunner.class.getDeclaredMethod("isIgnored", new Class[]{FrameworkMethod.class});
|
||||
Method ignored = BlockJUnit4ClassRunner.class.getDeclaredMethod("isIgnored", FrameworkMethod.class);
|
||||
if (ignored != null) {
|
||||
return new BlockJUnit4ClassRunner(testClass) {
|
||||
protected boolean isIgnored(FrameworkMethod child) {
|
||||
@@ -105,11 +105,11 @@ public class JUnit45ClassesRequestBuilder {
|
||||
};
|
||||
}
|
||||
|
||||
static Runner createIgnoreAnnotationAndJUnit4ClassRunner(Class clazz) throws Throwable {
|
||||
static Runner createIgnoreAnnotationAndJUnit4ClassRunner(Class<?> clazz) throws Throwable {
|
||||
return new AllDefaultPossibilitiesBuilder(true) {
|
||||
protected AnnotatedBuilder annotatedBuilder() {
|
||||
return new AnnotatedBuilder(this) {
|
||||
public Runner runnerForClass(Class testClass) throws Exception {
|
||||
public Runner runnerForClass(Class testClass) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -117,7 +117,7 @@ public class JUnit45ClassesRequestBuilder {
|
||||
|
||||
protected JUnit4Builder junit4Builder() {
|
||||
return new JUnit4Builder() {
|
||||
public Runner runnerForClass(Class testClass) throws Throwable {
|
||||
public Runner runnerForClass(Class testClass) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -28,22 +28,21 @@ import org.junit.runner.notification.RunListener;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.*;
|
||||
|
||||
public class JUnit4TestListener extends RunListener {
|
||||
public static final String EMPTY_SUITE_NAME = "junit.framework.TestSuite$1";
|
||||
public static final String EMPTY_SUITE_WARNING = "warning";
|
||||
|
||||
private final List myStartedSuites = new ArrayList();
|
||||
private final Map myParents = new HashMap();
|
||||
private final Map myMethodNames = new HashMap();
|
||||
private final List<Description> myStartedSuites = new ArrayList<Description>();
|
||||
private final Map<Description, List<List<Description>>> myParents = new HashMap<Description, List<List<Description>>>();
|
||||
private final Map<Description, String> myMethodNames = new HashMap<Description, String>();
|
||||
private final PrintStream myPrintStream;
|
||||
private String myRootName;
|
||||
private long myCurrentTestStart;
|
||||
|
||||
private Description myCurrentTest;
|
||||
private final Map myWaitingQueue = new LinkedHashMap();
|
||||
private final Map<Description, TestEvent> myWaitingQueue = new LinkedHashMap<Description, TestEvent>();
|
||||
private static final JUnitTestTreeNodeManager NODE_NAMES_MANAGER = getTestTreeNodeManager();
|
||||
|
||||
|
||||
@@ -60,14 +59,13 @@ public class JUnit4TestListener extends RunListener {
|
||||
return MapSerializerUtil.escapeStr(str, MapSerializerUtil.STD_ESCAPER);
|
||||
}
|
||||
|
||||
public void testRunStarted(Description description) throws Exception {
|
||||
public void testRunStarted(Description description) {
|
||||
if (myRootName != null && !myRootName.startsWith("[")) {
|
||||
JUnitTestTreeNodeManager.TestNodePresentation rootNodePresentation = NODE_NAMES_MANAGER.getRootNodePresentation(myRootName);
|
||||
|
||||
myPrintStream.println("##teamcity[rootName name = \'" + escapeName(rootNodePresentation.getName()) +
|
||||
(rootNodePresentation.getComment() != null ? ("\' comment = \'" + escapeName(rootNodePresentation.getComment())) : "") + "\'" +
|
||||
" location = \'java:suite://" + escapeName(myRootName) +
|
||||
"\']");
|
||||
myPrintStream.println("##teamcity[rootName name = '" + escapeName(rootNodePresentation.getName()) +
|
||||
(rootNodePresentation.getComment() != null ? ("' comment = '" + escapeName(rootNodePresentation.getComment())) : "") +
|
||||
"' location = 'java:suite://" + escapeName(myRootName) + "']");
|
||||
myRootName = getShortName(myRootName);
|
||||
}
|
||||
}
|
||||
@@ -78,9 +76,9 @@ public class JUnit4TestListener extends RunListener {
|
||||
}
|
||||
finally {
|
||||
for (int i = myStartedSuites.size() - 1; i>= 0; i--) {
|
||||
String className = JUnit4ReflectionUtil.getClassName((Description)myStartedSuites.get(i));
|
||||
String className = JUnit4ReflectionUtil.getClassName(myStartedSuites.get(i));
|
||||
if (!className.equals(myRootName)) {
|
||||
myPrintStream.println("##teamcity[testSuiteFinished name=\'" + escapeName(getShortName(className)) + "\']");
|
||||
myPrintStream.println("##teamcity[testSuiteFinished name='" + escapeName(getShortName(className)) + "']");
|
||||
}
|
||||
}
|
||||
myStartedSuites.clear();
|
||||
@@ -92,8 +90,8 @@ public class JUnit4TestListener extends RunListener {
|
||||
}
|
||||
|
||||
private void testStarted(Description description, String methodName) {
|
||||
final List parents = (List)myParents.get(description);
|
||||
if (myCurrentTest != null && (parents == null || parents.isEmpty() || !((List)parents.get(0)).contains(myCurrentTest))) {
|
||||
final List<List<Description>> parents = myParents.get(description);
|
||||
if (myCurrentTest != null && (parents == null || parents.isEmpty() || !parents.get(0).contains(myCurrentTest))) {
|
||||
if (!myWaitingQueue.containsKey(description)) {
|
||||
myWaitingQueue.put(description, new TestEvent());
|
||||
return;
|
||||
@@ -105,18 +103,18 @@ public class JUnit4TestListener extends RunListener {
|
||||
final String classFQN = JUnit4ReflectionUtil.getClassName(description);
|
||||
|
||||
|
||||
List parentsHierarchy = new ArrayList();
|
||||
List<Description> parentsHierarchy = new ArrayList<Description>();
|
||||
if (parents != null && !parents.isEmpty()) {
|
||||
parentsHierarchy = (List)parents.remove(0);
|
||||
parentsHierarchy = parents.remove(0);
|
||||
}
|
||||
|
||||
if (parentsHierarchy.isEmpty()) {
|
||||
parentsHierarchy = Collections.singletonList(Description.createSuiteDescription(classFQN, new Annotation[0]));
|
||||
parentsHierarchy = Collections.singletonList(Description.createSuiteDescription(classFQN));
|
||||
}
|
||||
|
||||
if (methodName == null) {
|
||||
methodName = getFullMethodName(description, parentsHierarchy.isEmpty() ? null
|
||||
: (Description)parentsHierarchy.get(parentsHierarchy.size() - 1));
|
||||
: parentsHierarchy.get(parentsHierarchy.size() - 1));
|
||||
if (methodName == null) return;
|
||||
}
|
||||
|
||||
@@ -124,8 +122,8 @@ public class JUnit4TestListener extends RunListener {
|
||||
Description currentClass;
|
||||
Description currentParent;
|
||||
while (idx < myStartedSuites.size() && idx < parentsHierarchy.size()) {
|
||||
currentClass = (Description)myStartedSuites.get(idx);
|
||||
currentParent = (Description)parentsHierarchy.get(parentsHierarchy.size() - 1 - idx);
|
||||
currentClass = myStartedSuites.get(idx);
|
||||
currentParent = parentsHierarchy.get(parentsHierarchy.size() - 1 - idx);
|
||||
if (isHierarchyDifferent(parents, currentClass, currentParent)) {
|
||||
break;
|
||||
}
|
||||
@@ -133,26 +131,28 @@ public class JUnit4TestListener extends RunListener {
|
||||
}
|
||||
|
||||
for (int i = myStartedSuites.size() - 1; i >= idx; i--) {
|
||||
currentClass = (Description)myStartedSuites.remove(i);
|
||||
myPrintStream.println("##teamcity[testSuiteFinished name=\'" + escapeName(getShortName(JUnit4ReflectionUtil.getClassName(currentClass))) + "\']");
|
||||
currentClass = myStartedSuites.remove(i);
|
||||
myPrintStream.println(
|
||||
"##teamcity[testSuiteFinished name='" + escapeName(getShortName(JUnit4ReflectionUtil.getClassName(currentClass))) + "']");
|
||||
}
|
||||
|
||||
for (int i = idx; i < parentsHierarchy.size(); i++) {
|
||||
final Description descriptionFromHistory = (Description)parentsHierarchy.get(parentsHierarchy.size() - 1 - i);
|
||||
final Description descriptionFromHistory = parentsHierarchy.get(parentsHierarchy.size() - 1 - i);
|
||||
final String fqName = JUnit4ReflectionUtil.getClassName(descriptionFromHistory);
|
||||
final String className = getShortName(fqName);
|
||||
if (!className.equals(myRootName)) {
|
||||
myPrintStream.println("##teamcity[testSuiteStarted name=\'" + escapeName(className) + "\'" + getSuiteLocation(descriptionFromHistory, description, fqName) + "]");
|
||||
myPrintStream.println("##teamcity[testSuiteStarted name='" + escapeName(className) +
|
||||
"'" + getSuiteLocation(descriptionFromHistory, description, fqName) + "]");
|
||||
}
|
||||
myStartedSuites.add(descriptionFromHistory);
|
||||
}
|
||||
|
||||
myPrintStream.println("##teamcity[testStarted name=\'" + escapeName(methodName.replaceFirst("/", ".")) + "\' " +
|
||||
myPrintStream.println("##teamcity[testStarted name='" + escapeName(methodName.replaceFirst("/", ".")) + "' " +
|
||||
NODE_NAMES_MANAGER.getTestLocation(description, classFQN, methodName) + "]");
|
||||
myCurrentTestStart = currentTime();
|
||||
}
|
||||
|
||||
private static boolean isHierarchyDifferent(List parents,
|
||||
private static boolean isHierarchyDifferent(List<?> parents,
|
||||
Description currentClass,
|
||||
Description currentParent) {
|
||||
if (parents == null) {
|
||||
@@ -169,7 +169,7 @@ public class JUnit4TestListener extends RunListener {
|
||||
|
||||
public void testFinished(Description description) {
|
||||
if (startedInParallel(description)) {
|
||||
TestEvent testEvent = (TestEvent)myWaitingQueue.get(description);
|
||||
TestEvent testEvent = myWaitingQueue.get(description);
|
||||
testEvent.setFinished(true);
|
||||
return;
|
||||
}
|
||||
@@ -195,8 +195,8 @@ public class JUnit4TestListener extends RunListener {
|
||||
private void testFinishedNoDumping(final String methodName) {
|
||||
if (methodName != null) {
|
||||
final long duration = currentTime() - myCurrentTestStart;
|
||||
myPrintStream.println("##teamcity[testFinished name=\'" + escapeName(methodName.replaceFirst("/", ".")) +
|
||||
(duration > 0 ? "\' duration=\'" + duration : "") + "\']");
|
||||
myPrintStream.println("##teamcity[testFinished name='" + escapeName(methodName.replaceFirst("/", ".")) +
|
||||
(duration > 0 ? "' duration='" + duration : "") + "']");
|
||||
}
|
||||
myCurrentTest = null;
|
||||
}
|
||||
@@ -215,8 +215,7 @@ public class JUnit4TestListener extends RunListener {
|
||||
classConfigurationFinished(description);
|
||||
}
|
||||
if (myStartedSuites.isEmpty() || !description.equals(myStartedSuites.get(myStartedSuites.size() - 1))) {
|
||||
for (Iterator iterator = description.getChildren().iterator(); iterator.hasNext(); ) {
|
||||
Description next = (Description)iterator.next();
|
||||
for (Description next : description.getChildren()) {
|
||||
testStarted(next);
|
||||
testFailure(isIgnored ? failure : null, next, MapSerializerUtil.TEST_IGNORED);
|
||||
testFinished(next);
|
||||
@@ -230,12 +229,12 @@ public class JUnit4TestListener extends RunListener {
|
||||
|
||||
private void classConfigurationFinished(Description description) {
|
||||
if (startedInParallel(description)) {
|
||||
TestEvent testEvent = (TestEvent)myWaitingQueue.get(description);
|
||||
TestEvent testEvent = myWaitingQueue.get(description);
|
||||
testEvent.setFinished(true);
|
||||
return;
|
||||
}
|
||||
|
||||
myPrintStream.println("##teamcity[testFinished name=\'" + escapeName(TestListenerProtocol.CLASS_CONFIGURATION) + "\']");
|
||||
myPrintStream.println("##teamcity[testFinished name='" + escapeName(TestListenerProtocol.CLASS_CONFIGURATION) + "']");
|
||||
myCurrentTest = null;
|
||||
}
|
||||
|
||||
@@ -248,13 +247,14 @@ public class JUnit4TestListener extends RunListener {
|
||||
}
|
||||
|
||||
myCurrentTest = description;
|
||||
myPrintStream.println("##teamcity[testStarted name=\'" + escapeName(TestListenerProtocol.CLASS_CONFIGURATION) + "\'" + getSuiteLocation(JUnit4ReflectionUtil.getClassName(description)) + " ]");
|
||||
myPrintStream.println("##teamcity[testStarted name='" + escapeName(TestListenerProtocol.CLASS_CONFIGURATION) +
|
||||
"'" + getSuiteLocation(JUnit4ReflectionUtil.getClassName(description)) + " ]");
|
||||
}
|
||||
|
||||
private void testFailure(Failure failure, Description description, String messageName, String methodName) {
|
||||
final boolean isIgnored = MapSerializerUtil.TEST_IGNORED.equals(messageName);
|
||||
if (startedInParallel(description)) {
|
||||
TestEvent testEvent = (TestEvent)myWaitingQueue.get(description);
|
||||
TestEvent testEvent = myWaitingQueue.get(description);
|
||||
if (testEvent == null) {
|
||||
testEvent = new TestEvent();
|
||||
myWaitingQueue.put(description, testEvent);
|
||||
@@ -264,7 +264,7 @@ public class JUnit4TestListener extends RunListener {
|
||||
return;
|
||||
}
|
||||
|
||||
final Map attrs = new LinkedHashMap();
|
||||
final Map<String, String> attrs = new LinkedHashMap<String, String>();
|
||||
attrs.put("name", methodName);
|
||||
final long duration = currentTime() - myCurrentTestStart;
|
||||
if (duration > 0) {
|
||||
@@ -308,7 +308,7 @@ public class JUnit4TestListener extends RunListener {
|
||||
private String getFullMethodName(Description description,
|
||||
Description parent,
|
||||
boolean acceptNull) {
|
||||
String methodName = (String)myMethodNames.get(description);
|
||||
String methodName = myMethodNames.get(description);
|
||||
if (methodName == null) {
|
||||
methodName = JUnit4ReflectionUtil.getMethodName(description);
|
||||
if (methodName != null && (parent == null || !isParameter(parent))) {
|
||||
@@ -328,8 +328,7 @@ public class JUnit4TestListener extends RunListener {
|
||||
public void testIgnored(Description description) {
|
||||
final String methodName = getFullMethodName(description);
|
||||
if (methodName == null) {
|
||||
for (Iterator iterator = description.getChildren().iterator(); iterator.hasNext(); ) {
|
||||
final Description testDescription = (Description)iterator.next();
|
||||
for (final Description testDescription : description.getChildren()) {
|
||||
testIgnored(testDescription, getFullMethodName(testDescription));//todo
|
||||
}
|
||||
}
|
||||
@@ -340,9 +339,9 @@ public class JUnit4TestListener extends RunListener {
|
||||
|
||||
private void testIgnored(Description description, String methodName) {
|
||||
testStarted(description);
|
||||
Map attrs = new HashMap();
|
||||
Map<String, String> attrs = new HashMap<String, String>();
|
||||
try {
|
||||
final Ignore ignoredAnnotation = (Ignore)description.getAnnotation(Ignore.class);
|
||||
final Ignore ignoredAnnotation = description.getAnnotation(Ignore.class);
|
||||
if (ignoredAnnotation != null) {
|
||||
final String val = ignoredAnnotation.value();
|
||||
if (val != null) {
|
||||
@@ -356,7 +355,7 @@ public class JUnit4TestListener extends RunListener {
|
||||
attrs.put("name", methodName);
|
||||
|
||||
if (startedInParallel(description)) {
|
||||
TestEvent testEvent = (TestEvent)myWaitingQueue.get(description);
|
||||
TestEvent testEvent = myWaitingQueue.get(description);
|
||||
if (testEvent == null) {
|
||||
testEvent = new TestEvent();
|
||||
myWaitingQueue.put(description, testEvent);
|
||||
@@ -371,9 +370,9 @@ public class JUnit4TestListener extends RunListener {
|
||||
}
|
||||
|
||||
private void dumpQueue(boolean acceptUnfinished) {
|
||||
for (Iterator iterator = myWaitingQueue.keySet().iterator(); iterator.hasNext(); ) {
|
||||
Description description = (Description)iterator.next();
|
||||
TestEvent testEvent = (TestEvent)myWaitingQueue.get(description);
|
||||
for (Iterator<Description> iterator = myWaitingQueue.keySet().iterator(); iterator.hasNext(); ) {
|
||||
Description description = iterator.next();
|
||||
TestEvent testEvent = myWaitingQueue.get(description);
|
||||
if (acceptUnfinished || testEvent.isFinished()) {
|
||||
testStarted(description, testEvent.getMethodName());
|
||||
|
||||
@@ -381,7 +380,7 @@ public class JUnit4TestListener extends RunListener {
|
||||
|
||||
Failure failure = testEvent.getFailure();
|
||||
if (testEvent.isIgnored()) {
|
||||
Map attrs = testEvent.getAttrs();
|
||||
Map<String, String> attrs = testEvent.getAttrs();
|
||||
if (attrs == null) {
|
||||
testFailure(failure, description, MapSerializerUtil.TEST_IGNORED);
|
||||
}
|
||||
@@ -403,7 +402,7 @@ public class JUnit4TestListener extends RunListener {
|
||||
private Failure myFailure;
|
||||
private boolean myIgnored;
|
||||
private boolean myFinished;
|
||||
private Map myAttrs;
|
||||
private Map<String, String> myAttrs;
|
||||
private String myMethodName;
|
||||
|
||||
public Failure getFailure() {
|
||||
@@ -430,11 +429,11 @@ public class JUnit4TestListener extends RunListener {
|
||||
myIgnored = ignored;
|
||||
}
|
||||
|
||||
public void setAttrs(Map attrs) {
|
||||
public void setAttrs(Map<String, String> attrs) {
|
||||
myAttrs = attrs;
|
||||
}
|
||||
|
||||
public Map getAttrs() {
|
||||
public Map<String, String> getAttrs() {
|
||||
return myAttrs;
|
||||
}
|
||||
|
||||
@@ -447,8 +446,8 @@ public class JUnit4TestListener extends RunListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void sendTree(Description description, Description parent, List currentParents) {
|
||||
List pParents = new ArrayList(3);
|
||||
private void sendTree(Description description, Description parent, List<Description> currentParents) {
|
||||
List<Description> pParents = new ArrayList<Description>(3);
|
||||
pParents.addAll(currentParents);
|
||||
if (parent != null) {
|
||||
final String parentClassName = JUnit4ReflectionUtil.getClassName(parent);
|
||||
@@ -457,42 +456,44 @@ public class JUnit4TestListener extends RunListener {
|
||||
}
|
||||
}
|
||||
|
||||
List parents = (List)myParents.get(description);
|
||||
List<List<Description>> parents = myParents.get(description);
|
||||
if (parents == null) {
|
||||
parents = new ArrayList(1);
|
||||
parents = new ArrayList<List<Description>>(1);
|
||||
myParents.put(description, parents);
|
||||
}
|
||||
parents.add(pParents);
|
||||
|
||||
String className = JUnit4ReflectionUtil.getClassName(description);
|
||||
if (description.isTest()) {
|
||||
final String methodName = getFullMethodName((Description)description, parent, true);
|
||||
final String methodName = getFullMethodName(description, parent, true);
|
||||
if (methodName != null ) {
|
||||
if (isWarning(methodName, className) && parent != null) {
|
||||
className = JUnit4ReflectionUtil.getClassName(parent);
|
||||
}
|
||||
myPrintStream.println("##teamcity[suiteTreeNode name=\'" + escapeName(methodName.replaceFirst("/", ".")) + "\' " + NODE_NAMES_MANAGER.getTestLocation(description, className, methodName) + "]");
|
||||
myPrintStream.println("##teamcity[suiteTreeNode name='" + escapeName(methodName.replaceFirst("/", ".")) +
|
||||
"' " + NODE_NAMES_MANAGER.getTestLocation(description, className, methodName) + "]");
|
||||
}
|
||||
else {
|
||||
myPrintStream.println("##teamcity[suiteTreeStarted name=\'" + escapeName(getShortName(className)) + "\' locationHint=\'java:suite://" + escapeName(className) + "\']");
|
||||
myPrintStream.println("##teamcity[suiteTreeEnded name=\'" + escapeName(getShortName(className)) + "\']");
|
||||
myPrintStream.println("##teamcity[suiteTreeStarted name='" + escapeName(getShortName(className)) +
|
||||
"' locationHint='java:suite://" + escapeName(className) + "']");
|
||||
myPrintStream.println("##teamcity[suiteTreeEnded name='" + escapeName(getShortName(className)) + "']");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
List tests = description.getChildren();
|
||||
List<Description> tests = description.getChildren();
|
||||
boolean pass = false;
|
||||
for (Iterator iterator = tests.iterator(); iterator.hasNext(); ) {
|
||||
final Object next = iterator.next();
|
||||
final Description nextDescription = (Description)next;
|
||||
for (final Description nextDescription : tests) {
|
||||
if ((myRootName == null || !myRootName.equals(className)) && !pass) {
|
||||
pass = true;
|
||||
myPrintStream.println("##teamcity[suiteTreeStarted name=\'" + escapeName(getShortName(className)) + "\'" + getSuiteLocation(description, nextDescription, className) + "]");
|
||||
myPrintStream.println("##teamcity[suiteTreeStarted name='" + escapeName(getShortName(className)) + "'" +
|
||||
getSuiteLocation(description, nextDescription, className) + "]");
|
||||
}
|
||||
sendTree(nextDescription, description, pParents);
|
||||
}
|
||||
if (pass) {
|
||||
myPrintStream.println("##teamcity[suiteTreeEnded name=\'" + escapeName(getShortName(JUnit4ReflectionUtil.getClassName((Description)description))) + "\']");
|
||||
myPrintStream.println(
|
||||
"##teamcity[suiteTreeEnded name='" + escapeName(getShortName(JUnit4ReflectionUtil.getClassName(description))) + "']");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,7 +513,7 @@ public class JUnit4TestListener extends RunListener {
|
||||
}
|
||||
|
||||
private static String getSuiteLocation(String locationHint) {
|
||||
return " locationHint=\'java:suite://" + escapeName(locationHint) + "\'";
|
||||
return " locationHint='java:suite://" + escapeName(locationHint) + "'";
|
||||
}
|
||||
|
||||
private static boolean isWarning(String methodName, String className) {
|
||||
@@ -525,8 +526,8 @@ public class JUnit4TestListener extends RunListener {
|
||||
}
|
||||
|
||||
public void sendTree(Description description) {
|
||||
myRootName = JUnit4ReflectionUtil.getClassName((Description)description);
|
||||
sendTree(description, null, new ArrayList());
|
||||
myRootName = JUnit4ReflectionUtil.getClassName(description);
|
||||
sendTree(description, null, new ArrayList<Description>());
|
||||
myPrintStream.println("##teamcity[treeEnded]");
|
||||
}
|
||||
|
||||
@@ -544,8 +545,9 @@ public class JUnit4TestListener extends RunListener {
|
||||
JUnitTestTreeNodeManager result = JUnitTestTreeNodeManager.JAVA_NODE_NAMES_MANAGER;
|
||||
if (junitNodeNamesManagerClassName != null) {
|
||||
try {
|
||||
Class junitNodeNamesManagerClass = Class.forName(junitNodeNamesManagerClassName);
|
||||
result = (JUnitTestTreeNodeManager)junitNodeNamesManagerClass.newInstance();
|
||||
Class<? extends JUnitTestTreeNodeManager> junitNodeNamesManagerClass = Class.forName(junitNodeNamesManagerClassName)
|
||||
.asSubclass(JUnitTestTreeNodeManager.class);
|
||||
result = junitNodeNamesManagerClass.newInstance();
|
||||
}
|
||||
catch (ClassCastException ignored) {
|
||||
}
|
||||
|
||||
@@ -41,20 +41,19 @@ public class JUnit4TestRunnerUtil {
|
||||
if (suiteClassNames.length == 0) {
|
||||
return null;
|
||||
}
|
||||
Vector result = new Vector();
|
||||
for (int i = 0; i < suiteClassNames.length; i++) {
|
||||
String suiteClassName = suiteClassNames[i];
|
||||
ArrayList<Class<?>> result = new ArrayList<Class<?>>();
|
||||
for (String suiteClassName : suiteClassNames) {
|
||||
if (suiteClassName.charAt(0) == '@') {
|
||||
// all tests in the package specified
|
||||
try {
|
||||
final Map classMethods = new HashMap();
|
||||
final Map<String, Set<String>> classMethods = new HashMap<String, Set<String>>();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(suiteClassName.substring(1)), "UTF-8"));
|
||||
try {
|
||||
final String packageName = reader.readLine();
|
||||
if (packageName == null) return null;
|
||||
|
||||
final String categoryName = reader.readLine();
|
||||
final Class category = categoryName != null && categoryName.length() > 0 ? loadTestClass(categoryName) : null;
|
||||
final Class<?> category = categoryName != null && categoryName.length() > 0 ? loadTestClass(categoryName) : null;
|
||||
final String filters = reader.readLine();
|
||||
|
||||
String line;
|
||||
@@ -64,20 +63,19 @@ public class JUnit4TestRunnerUtil {
|
||||
final int idx = line.indexOf(',');
|
||||
if (idx != -1) {
|
||||
className = line.substring(0, idx);
|
||||
Set methodNames = (Set)classMethods.get(className);
|
||||
Set<String> methodNames = classMethods.get(className);
|
||||
if (methodNames == null) {
|
||||
methodNames = new HashSet();
|
||||
methodNames = new HashSet<String>();
|
||||
classMethods.put(className, methodNames);
|
||||
}
|
||||
methodNames.add(line.substring(idx + 1));
|
||||
|
||||
}
|
||||
appendTestClass(result, className);
|
||||
}
|
||||
String suiteName = packageName.length() == 0 ? "<default package>": packageName;
|
||||
Class[] classes = getArrayOfClasses(result);
|
||||
String suiteName = packageName.length() == 0 ? "<default package>" : packageName;
|
||||
Class<?>[] classes = getArrayOfClasses(result);
|
||||
if (classes.length == 0) {
|
||||
System.out.println(TestRunnerUtil.testsFoundInPackageMesage(0, suiteName));
|
||||
System.out.println(TestRunnerUtil.testsFoundInPackageMessage(0, suiteName));
|
||||
return null;
|
||||
}
|
||||
Request allClasses;
|
||||
@@ -95,7 +93,7 @@ public class JUnit4TestRunnerUtil {
|
||||
return classMethods.isEmpty() ? allClasses : allClasses.filterWith(new Filter() {
|
||||
public boolean shouldRun(Description description) {
|
||||
if (description.isTest()) {
|
||||
final Set methods = (Set)classMethods.get(JUnit4ReflectionUtil.getClassName(description));
|
||||
final Set<String> methods = classMethods.get(JUnit4ReflectionUtil.getClassName(description));
|
||||
if (methods == null) {
|
||||
return true;
|
||||
}
|
||||
@@ -108,9 +106,9 @@ public class JUnit4TestRunnerUtil {
|
||||
methods.contains(methodName.substring(0, methodName.length() - name.length()));
|
||||
}
|
||||
|
||||
final Class testClass = description.getTestClass();
|
||||
final Class<?> testClass = description.getTestClass();
|
||||
if (testClass != null) {
|
||||
final RunWith classAnnotation = (RunWith)testClass.getAnnotation(RunWith.class);
|
||||
final RunWith classAnnotation = testClass.getAnnotation(RunWith.class);
|
||||
if (classAnnotation != null && Parameterized.class.isAssignableFrom(classAnnotation.value())) {
|
||||
final int idx = methodName.indexOf("[");
|
||||
if (idx > -1) {
|
||||
@@ -140,14 +138,16 @@ public class JUnit4TestRunnerUtil {
|
||||
else {
|
||||
int index = suiteClassName.indexOf(',');
|
||||
if (index != -1) {
|
||||
final Class clazz = loadTestClass(suiteClassName.substring(0, index));
|
||||
final Class<?> clazz = loadTestClass(suiteClassName.substring(0, index));
|
||||
final String methodName = suiteClassName.substring(index + 1);
|
||||
final RunWith clazzAnnotation = (RunWith)clazz.getAnnotation(RunWith.class);
|
||||
final RunWith clazzAnnotation = clazz.getAnnotation(RunWith.class);
|
||||
final Description testMethodDescription = Description.createTestDescription(clazz, methodName);
|
||||
if (clazzAnnotation == null) { //do not override external runners
|
||||
try {
|
||||
final Method method = clazz.getMethod(methodName, null);
|
||||
if (method != null && notForked && (method.getAnnotation(Ignore.class) != null || clazz.getAnnotation(Ignore.class) != null)) { //override ignored case only
|
||||
final Method method = clazz.getMethod(methodName);
|
||||
if (method != null &&
|
||||
notForked &&
|
||||
(method.getAnnotation(Ignore.class) != null || clazz.getAnnotation(Ignore.class) != null)) { //override ignored case only
|
||||
final Request classRequest = JUnit45ClassesRequestBuilder.createIgnoreIgnoredClassRequest(clazz, true);
|
||||
final Filter ignoredTestFilter = Filter.matchMethodDescription(testMethodDescription);
|
||||
return classRequest.filterWith(new Filter() {
|
||||
@@ -164,14 +164,15 @@ public class JUnit4TestRunnerUtil {
|
||||
catch (Throwable ignored) {
|
||||
//return simple method runner
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
final Request request = getParameterizedRequest(name, methodName, clazz, clazzAnnotation);
|
||||
if (request != null) {
|
||||
return request;
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (clazz.getMethod("suite", new Class[0]) != null && !methodName.equals("suite")) {
|
||||
if (clazz.getMethod("suite") != null && !methodName.equals("suite")) {
|
||||
return Request.classWithoutSuiteMethod(clazz).filterWith(testMethodDescription);
|
||||
}
|
||||
}
|
||||
@@ -199,10 +200,11 @@ public class JUnit4TestRunnerUtil {
|
||||
return methodFilter.describe();
|
||||
}
|
||||
});
|
||||
} else if (name != null && suiteClassNames.length == 1) {
|
||||
final Class clazz = loadTestClass(suiteClassName);
|
||||
}
|
||||
else if (name != null && suiteClassNames.length == 1) {
|
||||
final Class<?> clazz = loadTestClass(suiteClassName);
|
||||
if (clazz != null) {
|
||||
final RunWith clazzAnnotation = (RunWith)clazz.getAnnotation(RunWith.class);
|
||||
final RunWith clazzAnnotation = clazz.getAnnotation(RunWith.class);
|
||||
final Request request = getParameterizedRequest(name, null, clazz, clazzAnnotation);
|
||||
if (request != null) {
|
||||
return request;
|
||||
@@ -214,7 +216,7 @@ public class JUnit4TestRunnerUtil {
|
||||
}
|
||||
|
||||
if (result.size() == 1) {
|
||||
final Class clazz = (Class)result.get(0);
|
||||
final Class<?> clazz = result.get(0);
|
||||
try {
|
||||
if (clazz.getAnnotation(Ignore.class) != null) { //override ignored case only
|
||||
return JUnit45ClassesRequestBuilder.createIgnoreIgnoredClassRequest(clazz, false);
|
||||
@@ -230,22 +232,22 @@ public class JUnit4TestRunnerUtil {
|
||||
|
||||
private static Request getParameterizedRequest(final String parameterString,
|
||||
final String methodName,
|
||||
Class clazz,
|
||||
Class<?> clazz,
|
||||
RunWith clazzAnnotation) {
|
||||
if (clazzAnnotation == null) return null;
|
||||
|
||||
final Class runnerClass = clazzAnnotation.value();
|
||||
final Class<? extends Runner> runnerClass = clazzAnnotation.value();
|
||||
if (Parameterized.class.isAssignableFrom(runnerClass)) {
|
||||
try {
|
||||
if (methodName != null) {
|
||||
final Method method = clazz.getMethod(methodName, new Class[0]);
|
||||
final Method method = clazz.getMethod(methodName);
|
||||
if (method != null && !method.isAnnotationPresent(Test.class) && TestCase.class.isAssignableFrom(clazz)) {
|
||||
return Request.runner(JUnit45ClassesRequestBuilder.createIgnoreAnnotationAndJUnit4ClassRunner(clazz));
|
||||
}
|
||||
}
|
||||
Class.forName("org.junit.runners.BlockJUnit4ClassRunner"); //ignore for junit4.4 and <
|
||||
final Constructor runnerConstructor = runnerClass.getConstructor(new Class[]{Class.class});
|
||||
return Request.runner((Runner)runnerConstructor.newInstance(new Object[] {clazz})).filterWith(new Filter() {
|
||||
final Constructor<? extends Runner> runnerConstructor = runnerClass.getConstructor(Class.class);
|
||||
return Request.runner(runnerConstructor.newInstance(clazz)).filterWith(new Filter() {
|
||||
public boolean shouldRun(Description description) {
|
||||
final String descriptionMethodName = description.getMethodName();
|
||||
//filter by params
|
||||
@@ -280,7 +282,7 @@ public class JUnit4TestRunnerUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Request getClassRequestsUsing44API(String suiteName, Class[] classes) {
|
||||
private static Request getClassRequestsUsing44API(String suiteName, Class<?>[] classes) {
|
||||
Request allClasses;
|
||||
try {
|
||||
Class.forName("org.junit.internal.requests.ClassesRequest");
|
||||
@@ -292,22 +294,19 @@ public class JUnit4TestRunnerUtil {
|
||||
return allClasses;
|
||||
}
|
||||
|
||||
private static void appendTestClass(Vector result, String className) {
|
||||
final Class aClass = loadTestClass(className);
|
||||
private static void appendTestClass(List<Class<?>> result, String className) {
|
||||
final Class<?> aClass = loadTestClass(className);
|
||||
if (!result.contains(aClass)) { //do not append classes twice: rerun failed tests from one test suite
|
||||
result.addElement(aClass);
|
||||
result.add(aClass);
|
||||
}
|
||||
}
|
||||
|
||||
private static Class[] getArrayOfClasses(Vector result) {
|
||||
Class[] classes = new Class[result.size()];
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
classes[i] = (Class)result.get(i);
|
||||
}
|
||||
return classes;
|
||||
private static Class<?>[] getArrayOfClasses(List<Class<?>> result) {
|
||||
//noinspection SSBasedInspection
|
||||
return result.toArray(new Class[0]);
|
||||
}
|
||||
|
||||
private static Class loadTestClass(String suiteClassName) {
|
||||
private static Class<?> loadTestClass(String suiteClassName) {
|
||||
try {
|
||||
return Class.forName(suiteClassName, false, JUnit4TestRunnerUtil.class.getClassLoader());
|
||||
}
|
||||
@@ -316,11 +315,12 @@ public class JUnit4TestRunnerUtil {
|
||||
if (clazz == null) {
|
||||
clazz = suiteClassName;
|
||||
}
|
||||
System.err.print(MessageFormat.format(ResourceBundle.getBundle("RuntimeBundle").getString("junit.class.not.found"), new Object[]{clazz}));
|
||||
System.err.print(MessageFormat.format(ResourceBundle.getBundle("RuntimeBundle").getString("junit.class.not.found"), clazz));
|
||||
System.exit(1);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println(MessageFormat.format(ResourceBundle.getBundle("RuntimeBundle").getString("junit.cannot.instantiate.tests"), new Object[]{e.toString()}));
|
||||
System.err.println(MessageFormat.format(ResourceBundle.getBundle("RuntimeBundle").getString("junit.cannot.instantiate.tests"),
|
||||
e.toString()));
|
||||
System.exit(1);
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user