Fix warnings in rt modules

1. Generify everywhere
2. @Override
3. Redundant throws removed
4. Enhanced for
5. String concatenation to StringBuilder
6. Misc

GitOrigin-RevId: 1e4c9dd7a44360b187d23370586c81a78047cdaf
This commit is contained in:
Tagir Valeev
2020-06-03 07:17:36 +03:00
committed by intellij-monorepo-bot
parent 0968a5611f
commit d2ef69f336
40 changed files with 289 additions and 183 deletions
@@ -26,20 +26,20 @@ public class AbstractExpectedPatterns {
private static final Pattern ASSERT_EQUALS_PATTERN = Pattern.compile("expected:<(.*)> but was:<(.*)>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
private static final Pattern ASSERT_EQUALS_CHAINED_PATTERN = Pattern.compile("but was:<(.*)>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
protected static void registerPatterns(String[] patternStrings, List patterns) {
for (int i = 0; i < patternStrings.length; i++) {
patterns.add(Pattern.compile(patternStrings[i], Pattern.DOTALL | Pattern.CASE_INSENSITIVE));
protected static void registerPatterns(String[] patternStrings, List<Pattern> patterns) {
for (String string : patternStrings) {
patterns.add(Pattern.compile(string, Pattern.DOTALL | Pattern.CASE_INSENSITIVE));
}
}
protected static ComparisonFailureData createExceptionNotification(String message, List patterns) {
protected static ComparisonFailureData createExceptionNotification(String message, List<Pattern> patterns) {
ComparisonFailureData assertEqualsNotification = createExceptionNotification(message, ASSERT_EQUALS_PATTERN);
if (assertEqualsNotification != null) {
return ASSERT_EQUALS_CHAINED_PATTERN.matcher(assertEqualsNotification.getExpected()).find() ? null : assertEqualsNotification;
}
for (int i = 0; i < patterns.size(); i++) {
ComparisonFailureData notification = createExceptionNotification(message, (Pattern)patterns.get(i));
for (Pattern pattern : patterns) {
ComparisonFailureData notification = createExceptionNotification(message, pattern);
if (notification != null) {
return notification;
}
@@ -28,11 +28,11 @@ public abstract class ForkedByModuleSplitter {
protected final ForkedDebuggerHelper myForkedDebuggerHelper = new ForkedDebuggerHelper();
protected final String myWorkingDirsPath;
protected final String myForkMode;
protected final List myNewArgs;
protected final List<String> myNewArgs;
protected String myDynamicClasspath;
protected List myVMParameters;
protected List<String> myVMParameters;
public ForkedByModuleSplitter(String workingDirsPath, String forkMode, List newArgs) {
public ForkedByModuleSplitter(String workingDirsPath, String forkMode, List<String> newArgs) {
myWorkingDirsPath = workingDirsPath;
myForkMode = forkMode;
myNewArgs = newArgs;
@@ -44,7 +44,7 @@ public abstract class ForkedByModuleSplitter {
String repeatCount) throws Exception {
args = myForkedDebuggerHelper.excludeDebugPortFromArgs(args);
myVMParameters = new ArrayList();
myVMParameters = new ArrayList<String>();
final BufferedReader bufferedReader = new BufferedReader(new FileReader(commandLinePath));
myDynamicClasspath = bufferedReader.readLine();
try {
@@ -63,8 +63,12 @@ public abstract class ForkedByModuleSplitter {
}
//read output from wrappers
protected int startChildFork(final List args, File workingDir, String classpath, List moduleOptions, String repeatCount) throws IOException, InterruptedException {
List vmParameters = new ArrayList(myVMParameters);
protected int startChildFork(final List<String> args,
File workingDir,
String classpath,
List<String> moduleOptions,
String repeatCount) throws IOException, InterruptedException {
List<String> vmParameters = new ArrayList<String>(myVMParameters);
myForkedDebuggerHelper.setupDebugger(vmParameters);
final ProcessBuilder builder = new ProcessBuilder();
@@ -108,6 +112,7 @@ public abstract class ForkedByModuleSplitter {
private static Runnable createInputReader(final InputStream inputStream, final PrintStream outputStream) {
return new Runnable() {
@Override
public void run() {
try {
final BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
@@ -140,7 +145,7 @@ public abstract class ForkedByModuleSplitter {
while ((workingDir = perDirReader.readLine()) != null) {
final String moduleName = perDirReader.readLine();
final String classpath = perDirReader.readLine();
List moduleOptions = new ArrayList();
List<String> moduleOptions = new ArrayList<String>();
String modulePath = perDirReader.readLine();
if (modulePath != null && modulePath.length() > 0) {
moduleOptions.add("-p");
@@ -152,7 +157,7 @@ public abstract class ForkedByModuleSplitter {
}
try {
List classNames = new ArrayList();
List<String> classNames = new ArrayList<String>();
final int classNamesSize = Integer.parseInt(perDirReader.readLine());
for (int i = 0; i < classNamesSize; i++) {
String className = perDirReader.readLine();
@@ -182,11 +187,11 @@ public abstract class ForkedByModuleSplitter {
protected abstract int startSplitting(String[] args, String configName, String repeatCount) throws Exception;
protected abstract int startPerModuleFork(String moduleName,
List classNames,
List<String> classNames,
String packageName,
String workingDir,
String classpath,
List moduleOptions,
List<String> moduleOptions,
String repeatCount,
int result,
String filters) throws Exception;
@@ -197,25 +202,24 @@ public abstract class ForkedByModuleSplitter {
final Attributes attributes = manifest.getMainAttributes();
attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
String classpathForManifest = "";
StringBuilder classpathForManifest = new StringBuilder();
int idx = 0;
int endIdx = 0;
while (endIdx >= 0) {
endIdx = classpath.indexOf(File.pathSeparator, idx);
String path = endIdx < 0 ? classpath.substring(idx) : classpath.substring(idx, endIdx);
if (classpathForManifest.length() > 0) {
classpathForManifest += " ";
classpathForManifest.append(" ");
}
try {
//noinspection Since15
classpathForManifest += new File(path).toURI().toURL().toString();
classpathForManifest.append(new File(path).toURI().toURL().toString());
}
catch (NoSuchMethodError e) {
classpathForManifest += new File(path).toURL().toString();
classpathForManifest.append(new File(path).toURL().toString());
}
idx = endIdx + File.pathSeparator.length();
}
attributes.put(Attributes.Name.CLASS_PATH, classpathForManifest);
attributes.put(Attributes.Name.CLASS_PATH, classpathForManifest.toString());
File jarFile = File.createTempFile("classpath", ".jar");
ZipOutputStream jarPlugin = null;
@@ -38,12 +38,12 @@ public class ForkedDebuggerHelper {
}
}
public void setupDebugger(List parameters) throws IOException {
public void setupDebugger(List<String> parameters) throws IOException {
if (myDebugPort > -1) {
int debugAddress = findAvailableSocketPort();
boolean found = false;
for (int i = 0; i < parameters.size(); i++) {
String parameter = (String)parameters.get(i);
String parameter = parameters.get(i);
final int indexOf = Math.max(parameter.indexOf("transport=dt_socket"), parameter.indexOf("transport=dt_shmem"));
if (indexOf >= 0) {
if (debugAddress > -1) {
@@ -80,9 +80,9 @@ public class ForkedDebuggerHelper {
for (int i = 0; i < args.length; i++) {
String arg = args[i];
if (arg.startsWith(DEBUG_SOCKET)) {
final List list = new ArrayList(Arrays.asList(args));
final List<String> list = new ArrayList<String>(Arrays.asList(args));
list.remove(arg);
args = (String[])list.toArray(new String[0]);
args = list.toArray(new String[0]);
myDebugPort = Integer.parseInt(arg.substring(DEBUG_SOCKET.length()));
break;
}
@@ -31,6 +31,7 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter {
super(workingDirsPath, forkMode, newArgs);
}
@Override
protected int startSplitting(String[] args,
String configName,
String repeatCount) throws Exception {
@@ -41,7 +42,7 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter {
if (myWorkingDirsPath == null || new File(myWorkingDirsPath).length() == 0) {
final String classpath = System.getProperty("java.class.path");
final String modulePath = System.getProperty("jdk.module.path");
final List moduleOptions = new ArrayList();
final List<String> moduleOptions = new ArrayList<String>();
if (modulePath != null && modulePath.length() > 0) {
moduleOptions.add("-p");
moduleOptions.add(modulePath);
@@ -49,7 +50,7 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter {
if (repeatCount != null && RepeatCount.getCount(repeatCount) != 0 && myForkMode.equals("repeat")) {
return startChildFork(createChildArgs(myRootDescription), null, classpath, moduleOptions, repeatCount);
}
final List children = getChildren(myRootDescription);
final List<?> children = getChildren(myRootDescription);
final boolean forkTillMethod = myForkMode.equalsIgnoreCase("method");
return splitChildren(children, 0, forkTillMethod, null, classpath, moduleOptions, repeatCount);
}
@@ -58,22 +59,23 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter {
}
}
@Override
protected int startPerModuleFork(String moduleName,
List classNames,
List<String> classNames,
String packageName,
String workingDir,
String classpath,
List moduleOptions,
List<String> moduleOptions,
String repeatCount,
int result,
String filters) throws Exception {
if (myForkMode.equals("none")) {
final List childArgs = createPerModuleArgs(packageName, workingDir, classNames, myRootDescription, filters);
final List<String> childArgs = createPerModuleArgs(packageName, workingDir, classNames, myRootDescription, filters);
return startChildFork(childArgs, new File(workingDir), classpath, moduleOptions, repeatCount);
}
else {
final List children = new ArrayList(getChildren(myRootDescription));
for (Iterator iterator = children.iterator(); iterator.hasNext(); ) {
final List<?> children = new ArrayList<Object>(getChildren(myRootDescription));
for (Iterator<?> iterator = children.iterator(); iterator.hasNext(); ) {
if (!classNames.contains(getTestClassName(iterator.next()))) {
iterator.remove();
}
@@ -83,16 +85,15 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter {
}
}
protected int splitChildren(List children,
protected int splitChildren(List<?> children,
int result,
boolean forkTillMethod,
File workingDir,
String classpath,
List moduleOptions,
List<String> moduleOptions,
String repeatCount) throws IOException, InterruptedException {
for (int i = 0, argsLength = children.size(); i < argsLength; i++) {
final Object child = children.get(i);
final List childTests = getChildren(child);
for (final Object child : children) {
final List<?> childTests = getChildren(child);
final int childResult;
if (childTests.isEmpty() || !forkTillMethod) {
childResult = startChildFork(createChildArgs(child), workingDir, classpath, moduleOptions, repeatCount);
@@ -105,17 +106,17 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter {
return result;
}
protected abstract List createPerModuleArgs(String packageName,
String workingDir,
List classNames,
Object rootDescriptor,
String filters) throws IOException;
protected abstract List<String> createPerModuleArgs(String packageName,
String workingDir,
List<String> classNames,
Object rootDescriptor,
String filters) throws IOException;
protected abstract Object createRootDescription(String[] args, String configName) throws Exception;
protected abstract String getTestClassName(Object child);
protected abstract List createChildArgs(Object child);
protected abstract List<String> createChildArgs(Object child);
protected abstract List getChildren(Object child);
protected abstract List<?> getChildren(Object child);
}
@@ -16,11 +16,11 @@
package com.siyeh.ig.psiutils;
import com.intellij.codeInspection.reference.RefMethod;
import com.intellij.util.containers.Stack;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.Stack;
public class MethodInheritanceUtils {
@@ -22,14 +22,14 @@ import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.PropertyUtil;
import com.intellij.psi.util.PsiTreeUtil;
import java.util.HashMap;
import com.intellij.util.containers.Stack;
import com.siyeh.ig.psiutils.SynchronizationUtil;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.Stack;
class VariableAccessVisitor extends JavaRecursiveElementWalkingVisitor {
@@ -87,8 +87,9 @@ class VariableAccessVisitor extends JavaRecursiveElementWalkingVisitor {
return;
}
if (m_inInitializer) {
return;
}
else if (m_inSynchronizedContextCount > 0) {
if (m_inSynchronizedContextCount > 0) {
m_synchronizedAccesses.add((PsiField)element);
}
else if (ref.getParent() instanceof PsiSynchronizedStatement) {
@@ -123,8 +124,9 @@ class VariableAccessVisitor extends JavaRecursiveElementWalkingVisitor {
return;
}
if (m_inInitializer) {
return;
}
else if (m_inSynchronizedContextCount > 0) {
if (m_inSynchronizedContextCount > 0) {
m_synchronizedAccesses.add(field);
}
else {
@@ -3,7 +3,6 @@ package org.jetbrains.plugins.cucumber.java.run;
import com.intellij.junit4.JUnitTestTreeNodeManager;
import com.intellij.rt.execution.junit.MapSerializerUtil;
import org.junit.runner.Description;
import java.io.File;
@@ -16,14 +15,17 @@ public class CucumberTestTreeNodeManager implements JUnitTestTreeNodeManager {
private static final String FILE_COLON_PREFIX = "file:";
private static final String FILE_URL_PREFIX = "file://";
@Override
public JUnitTestTreeNodeManager.TestNodePresentation getRootNodePresentation(String fullName) {
return new JUnitTestTreeNodeManager.TestNodePresentation(fullName, null);
}
@Override
public String getNodeName(String fqName, boolean splitBySlash) {
return fqName;
}
@Override
public String getTestLocation(Description description, String className, String methodName) {
try {
Field descriptionField = Description.class.getDeclaredField("fUniqueId");
@@ -29,11 +29,11 @@ import java.util.stream.Collectors;
public class JUnit5IdeaTestRunner implements IdeaTestRunner {
private final List<JUnit5TestExecutionListener> myExecutionListeners = new ArrayList<>();
private ArrayList myListeners;
private ArrayList<String> myListeners;
private Launcher myLauncher;
@Override
public void createListeners(ArrayList listeners, int count) {
public void createListeners(ArrayList<String> listeners, int count) {
myListeners = listeners;
do {
JUnit5TestExecutionListener currentListener = new JUnit5TestExecutionListener();
@@ -96,7 +96,7 @@ public class JUnit5IdeaTestRunner implements IdeaTestRunner {
}
@Override
public List getChildTests(Object description) {
public List<?> getChildTests(Object description) {
if (description == FAKE_ROOT) {
return myForkedTestPlan.getRoots()
.stream()
@@ -28,17 +28,19 @@ import java.util.*;
public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner {
private SMTestListener myTestsListener;
private ArrayList myListeners;
private ArrayList<String> myListeners;
public JUnit3IdeaTestRunner() {
super(DeafStream.DEAF_PRINT_STREAM);
}
public void createListeners(ArrayList listeners, int count) {
@Override
public void createListeners(ArrayList<String> listeners, int count) {
myTestsListener = new SMTestListener();
myListeners = listeners;
}
@Override
public int startRunnerWithArgs(String[] args, String name, int count, boolean sendTree) {
setPrinter(new MockResultPrinter());
try {
@@ -52,26 +54,32 @@ public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner {
}
}
@Override
public void clearStatus() {
super.clearStatus();
}
@Override
public void runFailed(String message) {
super.runFailed(message);
}
@Override
public Object getTestToStart(String[] args, String name) {
return TestRunnerUtil.getTestSuite(this, args);
}
public List getChildTests(Object description) {
@Override
public List<?> getChildTests(Object description) {
return getTestCasesOf((Test)description);
}
@Override
public String getTestClassName(Object child) {
return child instanceof TestSuite ? ((TestSuite)child).getName() : child.getClass().getName();
}
@Override
public String getStartDescription(Object child) {
final Test test = (Test)child;
if (test instanceof TestCase) {
@@ -80,23 +88,28 @@ public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner {
return test.toString();
}
@Override
protected TestResult createTestResult() {
TestResult testResult = super.createTestResult();
testResult.addListener(myTestsListener);
try {
for (int i = 0; i < myListeners.size(); i++) {
final IDEAJUnitListener junitListener = (IDEAJUnitListener)Class.forName((String)myListeners.get(i)).newInstance();
for (String listener : myListeners) {
final IDEAJUnitListener junitListener = Class.forName(listener).asSubclass(IDEAJUnitListener.class).getConstructor().newInstance();
testResult.addListener(new TestListener() {
@Override
public void addError(Test test, Throwable t) {}
@Override
public void addFailure(Test test, AssertionFailedError t) {}
@Override
public void endTest(Test test) {
if (test instanceof TestCase) {
junitListener.testFinished(test.getClass().getName(), ((TestCase)test).getName());
}
}
@Override
public void startTest(Test test) {
if (test instanceof TestCase) {
junitListener.testStarted(test.getClass().getName(), ((TestCase)test).getName());
@@ -111,6 +124,7 @@ public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner {
return testResult;
}
@Override
public TestResult doRun(Test suite, boolean wait) { //todo
final TestResult testResult = super.doRun(suite, wait);
myTestsListener.finishSuite();
@@ -118,18 +132,18 @@ public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner {
return testResult;
}
static Vector getTestCasesOf(Test test) {
Vector testCases = new Vector();
static List<Test> getTestCasesOf(Test test) {
List<Test> testCases = new ArrayList<Test>();
if (test instanceof TestRunnerUtil.SuiteMethodWrapper) {
test = ((TestRunnerUtil.SuiteMethodWrapper)test).getSuite();
}
if (test instanceof TestSuite) {
TestSuite testSuite = (TestSuite)test;
for (Enumeration each = testSuite.tests(); each.hasMoreElements();) {
Object childTest = each.nextElement();
for (Enumeration<Test> each = testSuite.tests(); each.hasMoreElements();) {
Test childTest = each.nextElement();
if (childTest instanceof TestSuite && !((TestSuite)childTest).tests().hasMoreElements()) continue;
testCases.addElement(childTest);
testCases.add(childTest);
}
}
return testCases;
@@ -145,12 +159,13 @@ public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner {
private String myClassName;
private long myCurrentTestStart;
@Override
public void addError(Test test, Throwable e) {
testFailure(e, MapSerializerUtil.TEST_FAILED, getMethodName(test));
}
private void testFailure(Throwable failure, String messageName, String methodName) {
final Map attrs = new HashMap();
final Map<String, String> attrs = new HashMap<String, String>();
attrs.put("name", methodName);
final long duration = System.currentTimeMillis() - myCurrentTestStart;
if (duration > 0) {
@@ -199,16 +214,19 @@ public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner {
return braceIdx > 0 && toString.endsWith(")") ? toString.substring(braceIdx + 1, toString.length() - 1) : null;
}
@Override
public void addFailure(Test test, AssertionFailedError e) {
addError(test, e);
}
@Override
public void endTest(Test test) {
final long duration = System.currentTimeMillis() - myCurrentTestStart;
System.out.println("\n##teamcity[testFinished name='" + escapeName(getMethodName(test)) +
(duration > 0 ? "' duration='" + duration : "") + "']");
}
@Override
public void startTest(Test test) {
myCurrentTestStart = System.currentTimeMillis();
final String className = getClassName(test);
@@ -26,16 +26,14 @@ public class TestAllInPackage2 extends TestSuite {
public TestAllInPackage2(JUnit3IdeaTestRunner runner, final String name, String[] classMethodNames) {
super(name);
int testClassCount = 0;
final Set allNames = new HashSet(Arrays.asList(classMethodNames));
for (int i = 0; i < classMethodNames.length; i++) {
String classMethodName = classMethodNames[i];
final Set<String> allNames = new HashSet<String>(Arrays.asList(classMethodNames));
for (String classMethodName : classMethodNames) {
Test suite = TestRunnerUtil.createClassOrMethodSuite(runner, classMethodName);
if (suite != null) {
skipSuiteComponents(allNames, suite);
}
}
for (int i = 0; i < classMethodNames.length; i++) {
String classMethodName = classMethodNames[i];
for (String classMethodName : classMethodNames) {
Test suite = TestRunnerUtil.createClassOrMethodSuite(runner, classMethodName);
if (suite != null) {
boolean skip;
@@ -60,7 +58,7 @@ public class TestAllInPackage2 extends TestSuite {
System.out.println(message);
}
private static void skipSuiteComponents(Set allNames, Test suite) {
private static void skipSuiteComponents(Set<String> allNames, Test suite) {
if (suite instanceof TestRunnerUtil.SuiteMethodWrapper) {
final Test test = ((TestRunnerUtil.SuiteMethodWrapper)suite).getSuite();
final String currentSuiteName = ((TestRunnerUtil.SuiteMethodWrapper)suite).getClassName();
@@ -68,7 +66,7 @@ public class TestAllInPackage2 extends TestSuite {
}
}
private static void skipSubtests(Set allNames, Test test, String currentSuiteName) {
private static void skipSubtests(Set<String> allNames, Test test, String currentSuiteName) {
if (test instanceof TestSuite) {
for (int idx = 0; idx < ((TestSuite)test).testCount(); idx++) {
Test childTest = ((TestSuite)test).testAt(idx);
@@ -236,6 +236,7 @@ public class TestRunnerUtil {
return myMessage;
}
@Override
protected void runTest() {
try {
throw new RuntimeException(myMessage, myThrowable);
@@ -259,10 +260,12 @@ public class TestRunnerUtil {
return myClassName;
}
@Override
public int countTestCases() {
return mySuite.countTestCases();
}
@Override
public void run(TestResult result) {
mySuite.run(result);
}
@@ -18,14 +18,14 @@ package com.intellij.junit4;
import org.junit.internal.runners.SuiteMethod;
class ClassAwareSuiteMethod extends SuiteMethod {
private final Class myKlass;
private final Class<?> myKlass;
ClassAwareSuiteMethod(Class klass) throws Throwable {
ClassAwareSuiteMethod(Class<?> klass) throws Throwable {
super(klass);
myKlass = klass;
}
public Class getKlass() {
public Class<?> getKlass() {
return myKlass;
}
}
@@ -20,9 +20,10 @@ import com.intellij.rt.execution.testFrameworks.AbstractExpectedPatterns;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class ExpectedPatterns extends AbstractExpectedPatterns {
private static final List PATTERNS = new ArrayList();
private static final List<Pattern> PATTERNS = new ArrayList<Pattern>();
private static final String[] PATTERN_STRINGS = new String[]{
"\nexpected: is \"(.*)\"\n\\s*got: \"(.*)\"\n",
@@ -76,7 +77,7 @@ public class ExpectedPatterns extends AbstractExpectedPatterns {
return isComparisonFailure(throwable.getClass());
}
private static boolean isComparisonFailure(Class aClass) {
private static boolean isComparisonFailure(Class<?> aClass) {
if (aClass == null) return false;
final String throwableClassName = aClass.getName();
if (throwableClassName.equals(JUNIT_FRAMEWORK_COMPARISON_NAME) ||
@@ -34,16 +34,17 @@ import java.util.*;
class IdeaSuite extends Suite {
private final String myName;
IdeaSuite(List runners, String name) throws InitializationError {
IdeaSuite(List<Runner> runners, String name) throws InitializationError {
super(null, runners);
myName = name;
}
IdeaSuite(final RunnerBuilder builder, Class[] classes, String name) throws InitializationError {
IdeaSuite(final RunnerBuilder builder, Class<?>[] classes, String name) throws InitializationError {
super(builder, classes);
myName = name;
}
@Override
public Description getDescription() {
Description description = Description.createSuiteDescription(myName, getTestClass().getAnnotations());
try {
@@ -60,6 +61,7 @@ class IdeaSuite extends Suite {
return description;
}
@Override
protected Description describeChild(Runner child) {
final Description superDescription = super.describeChild(child);
if (child instanceof ClassAwareSuiteMethod) {
@@ -73,6 +75,7 @@ class IdeaSuite extends Suite {
return superDescription;
}
@Override
protected List<Runner> getChildren() {
final List<Runner> children = new ArrayList<Runner>(super.getChildren());
boolean containsSuiteInside = false;
@@ -16,6 +16,7 @@
package com.intellij.junit4;
import org.junit.experimental.categories.Categories;
import org.junit.runner.Runner;
import org.junit.runner.manipulation.NoTestsRemainException;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.RunnerBuilder;
@@ -23,17 +24,17 @@ import org.junit.runners.model.RunnerBuilder;
import java.util.List;
public class IdeaSuite48 extends IdeaSuite {
public IdeaSuite48(List runners, String name, Class category) throws InitializationError {
public IdeaSuite48(List<Runner> runners, String name, Class<?> category) throws InitializationError {
super(runners, name);
filterByCategory(category);
}
public IdeaSuite48(RunnerBuilder builder, Class[] classes, String name, Class category) throws InitializationError {
public IdeaSuite48(RunnerBuilder builder, Class<?>[] classes, String name, Class<?> category) throws InitializationError {
super(builder, classes, name);
filterByCategory(category);
}
private void filterByCategory(Class category) throws InitializationError {
private void filterByCategory(Class<?> category) {
if (category != null) {
try {
final Categories.CategoryFilter categoryFilter = Categories.CategoryFilter.include(category);
@@ -47,25 +47,31 @@ public class JUnit45ClassesRequestBuilder {
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) {
@Override
public Runner getRunner() {
try {
return new AllDefaultPossibilitiesBuilder(true) {
@Override
protected IgnoredBuilder ignoredBuilder() {
return new IgnoredBuilder() {
@Override
public Runner runnerForClass(Class testClass) {
return null;
}
};
}
@Override
protected JUnit4Builder junit4Builder() {
return new JUnit4Builder() {
@Override
public Runner runnerForClass(Class testClass) throws Throwable {
if (!recursively) return super.runnerForClass(testClass);
try {
Method ignored = BlockJUnit4ClassRunner.class.getDeclaredMethod("isIgnored", FrameworkMethod.class);
if (ignored != null) {
return new BlockJUnit4ClassRunner(testClass) {
@Override
protected boolean isIgnored(FrameworkMethod child) {
return false;
}
@@ -75,6 +81,7 @@ public class JUnit45ClassesRequestBuilder {
catch (NoSuchMethodException ignored) {}
//older versions
return new BlockJUnit4ClassRunner(testClass) {
@Override
protected void runChild(FrameworkMethod method, RunNotifier notifier) {
final Description description = describeChild(method);
final EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description);
@@ -107,16 +114,20 @@ public class JUnit45ClassesRequestBuilder {
static Runner createIgnoreAnnotationAndJUnit4ClassRunner(Class<?> clazz) throws Throwable {
return new AllDefaultPossibilitiesBuilder(true) {
@Override
protected AnnotatedBuilder annotatedBuilder() {
return new AnnotatedBuilder(this) {
@Override
public Runner runnerForClass(Class testClass) {
return null;
}
};
}
@Override
protected JUnit4Builder junit4Builder() {
return new JUnit4Builder() {
@Override
public Runner runnerForClass(Class testClass) {
return null;
}
@@ -23,12 +23,18 @@ import org.junit.runner.Request;
import org.junit.runner.Runner;
import org.junit.runners.model.InitializationError;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class JUnit46ClassesRequestBuilder {
private JUnit46ClassesRequestBuilder() {}
public static Request getClassesRequest(final String suiteName, Class[] classes, Map classMethods, Class category) {
public static Request getClassesRequest(final String suiteName,
Class<?>[] classes,
Map<String, Set<String>> classMethods,
Class<?> category) {
boolean canUseSuiteMethod = canUseSuiteMethod(classMethods);
try {
if (category != null) {
@@ -66,12 +72,11 @@ public class JUnit46ClassesRequestBuilder {
}
}
private static List collectWrappedRunners(Class[] classes) throws InitializationError {
final List runners = new ArrayList();
final List nonSuiteClasses = new ArrayList();
private static List<Runner> collectWrappedRunners(Class<?>[] classes) throws InitializationError {
final List<Runner> runners = new ArrayList<Runner>();
final List<Class<?>> nonSuiteClasses = new ArrayList<Class<?>>();
final SuiteMethodBuilder suiteMethodBuilder = new SuiteMethodBuilder();
for (int i = 0, length = classes.length; i < length; i++) {
Class aClass = classes[i];
for (Class<?> aClass : classes) {
if (suiteMethodBuilder.hasSuiteMethod(aClass)) {
try {
runners.add(new ClassAwareSuiteMethod(aClass));
@@ -83,19 +88,16 @@ public class JUnit46ClassesRequestBuilder {
nonSuiteClasses.add(aClass);
}
}
runners.addAll(new AllDefaultPossibilitiesBuilder(false).runners(null, (Class[])nonSuiteClasses.toArray(new Class[0])));
runners.addAll(new AllDefaultPossibilitiesBuilder(false).runners(null, nonSuiteClasses.toArray(new Class[0])));
return runners;
}
private static boolean canUseSuiteMethod(Map classMethods) {
for (Iterator iterator = classMethods.keySet().iterator(); iterator.hasNext(); ) {
Object className = iterator.next();
Set methods = (Set) classMethods.get(className);
private static boolean canUseSuiteMethod(Map<String, Set<String>> classMethods) {
for (Set<String> methods : classMethods.values()) {
if (methods == null) {
return true;
}
for (Iterator iterator1 = methods.iterator(); iterator1.hasNext(); ) {
String methodName = (String)iterator1.next();
for (String methodName : methods) {
if ("suite".equals(methodName)) {
return true;
}
@@ -19,7 +19,7 @@ package com.intellij.junit4;
import org.junit.runner.Request;
public class JUnit4ClassesRequestBuilder {
public static Request getClassesRequest(String suiteName, Class[] classes) {
public static Request getClassesRequest(String suiteName, Class<?>[] classes) {
try {
return (Request)Class.forName("org.junit.internal.requests.ClassesRequest")
.getConstructor(new Class[]{String.class, Class[].class})
@@ -28,19 +28,20 @@ import org.junit.runner.notification.RunListener;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/** @noinspection UnusedDeclaration*/
public class JUnit4IdeaTestRunner implements IdeaTestRunner {
private JUnit4TestListener myTestsListener;
private ArrayList myListeners;
private ArrayList<String> myListeners;
public void createListeners(ArrayList listeners, int count) {
@Override
public void createListeners(ArrayList<String> listeners, int count) {
myListeners = listeners;
myTestsListener = new JUnit4TestListener();
}
@Override
public int startRunnerWithArgs(String[] args, String name, int count, boolean sendTree) {
try {
final Request request = JUnit4TestRunnerUtil.buildRequest(args, name, sendTree);
@@ -54,15 +55,15 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
if (sendTree) {
do {
((JUnit4TestListener)myTestsListener).sendTree(description);
myTestsListener.sendTree(description);
}
while (--count > 0);
}
final JUnitCore runner = new JUnitCore();
runner.addListener(myTestsListener);
for (Iterator iterator = myListeners.iterator(); iterator.hasNext();) {
final IDEAJUnitListener junitListener = (IDEAJUnitListener)Class.forName((String)iterator.next()).newInstance();
for (String listener : myListeners) {
final IDEAJUnitListener junitListener = Class.forName(listener).asSubclass(IDEAJUnitListener.class).getConstructor().newInstance();
runner.addListener(new MyCustomRunListenerWrapper(junitListener, description.getDisplayName()));
}
final Result result = runner.run(testRunner);
@@ -102,19 +103,18 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
final String filterDescription = filter.describe();
if (filterDescription != null) {
boolean isMethodFilter = filterDescription.startsWith("Method");
if (isMethodFilter && canCompress(description)) return (Description)description.getChildren().get(0);
if (isMethodFilter && canCompress(description)) return description.getChildren().get(0);
try {
final Description failedTestsDescription = Description.createSuiteDescription(filterDescription, null);
if (filterDescription.startsWith("Tests") || filterDescription.startsWith("Ignored")) {
for (Iterator iterator = description.getChildren().iterator(); iterator.hasNext(); ) {
final Description childDescription = (Description)iterator.next();
for (final Description childDescription : description.getChildren()) {
if (filter.shouldRun(childDescription)) {
failedTestsDescription.addChild(childDescription);
}
}
description = failedTestsDescription;
} else if (isMethodFilter && canCompress(failedTestsDescription)) {
description = (Description)failedTestsDescription.getChildren().get(0);
description = failedTestsDescription.getChildren().get(0);
}
}
catch (NoSuchMethodError e) {
@@ -137,15 +137,16 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
field = ClassRequest.class.getDeclaredField("testClass");
}
field.setAccessible(true);
final Description methodDescription = Description.createSuiteDescription((Class)field.get(request));
for (Iterator iterator = description.getChildren().iterator(); iterator.hasNext();) {
methodDescription.addChild((Description)iterator.next());
final Description methodDescription = Description.createSuiteDescription((Class<?>)field.get(request));
for (Description value : description.getChildren()) {
methodDescription.addChild(value);
}
description = methodDescription;
return description;
}
@Override
public Object getTestToStart(String[] args, String name) {
final Request request = JUnit4TestRunnerUtil.buildRequest(args, name, false);
if (request == null) return null;
@@ -161,14 +162,17 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
}
}
public List getChildTests(Object description) {
@Override
public List<?> getChildTests(Object description) {
return ((Description)description).getChildren();
}
@Override
public String getTestClassName(Object child) {
return ((Description)child).getClassName();
}
@Override
public String getStartDescription(Object child) {
final Description description = (Description)child;
final String methodName = description.getMethodName();
@@ -185,24 +189,29 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
myDisplayName = displayName;
}
public void testStarted(Description description) throws Exception {
@Override
public void testStarted(Description description) {
mySuccess = true;
myJunitListener.testStarted(JUnit4ReflectionUtil.getClassName(description), JUnit4ReflectionUtil.getMethodName(description));
}
public void testFailure(Failure failure) throws Exception {
@Override
public void testFailure(Failure failure) {
mySuccess = ComparisonFailureData.isAssertionError(failure.getException().getClass());
}
@Override
public void testAssumptionFailure(Failure failure) {
mySuccess = false;
}
public void testIgnored(Description description) throws Exception {
@Override
public void testIgnored(Description description) {
mySuccess = false;
}
public void testFinished(Description description) throws Exception {
@Override
public void testFinished(Description description) {
final String className = JUnit4ReflectionUtil.getClassName(description);
final String methodName = JUnit4ReflectionUtil.getMethodName(description);
if (myJunitListener instanceof IDEAJUnitListenerEx) {
@@ -212,13 +221,15 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
}
}
public void testRunStarted(Description description) throws Exception {
@Override
public void testRunStarted(Description description) {
if (myJunitListener instanceof IDEAJUnitListenerEx) {
((IDEAJUnitListenerEx)myJunitListener).testRunStarted(description.getDisplayName());
}
}
public void testRunFinished(Result result) throws Exception {
@Override
public void testRunFinished(Result result) {
if (myJunitListener instanceof IDEAJUnitListenerEx) {
((IDEAJUnitListenerEx)myJunitListener).testRunFinished(myDisplayName);
}
@@ -59,6 +59,7 @@ public class JUnit4TestListener extends RunListener {
return MapSerializerUtil.escapeStr(str, MapSerializerUtil.STD_ESCAPER);
}
@Override
public void testRunStarted(Description description) {
if (myRootName != null && !myRootName.startsWith("[")) {
JUnitTestTreeNodeManager.TestNodePresentation rootNodePresentation = NODE_NAMES_MANAGER.getRootNodePresentation(myRootName);
@@ -70,6 +71,7 @@ public class JUnit4TestListener extends RunListener {
}
}
@Override
public void testRunFinished(Result result) {
try {
dumpQueue(true);
@@ -85,6 +87,7 @@ public class JUnit4TestListener extends RunListener {
}
}
@Override
public void testStarted(Description description) {
testStarted(description, null);
}
@@ -167,6 +170,7 @@ public class JUnit4TestListener extends RunListener {
return System.currentTimeMillis();
}
@Override
public void testFinished(Description description) {
if (startedInParallel(description)) {
TestEvent testEvent = myWaitingQueue.get(description);
@@ -201,6 +205,7 @@ public class JUnit4TestListener extends RunListener {
myCurrentTest = null;
}
@Override
public void testFailure(Failure failure) {
testFailure(failure, failure.getDescription(), MapSerializerUtil.TEST_FAILED);
}
@@ -293,6 +298,7 @@ public class JUnit4TestListener extends RunListener {
return failure.getTrace();
}
@Override
public void testAssumptionFailure(Failure failure) {
testFailure(failure, failure.getDescription(), MapSerializerUtil.TEST_IGNORED);
}
@@ -325,6 +331,7 @@ public class JUnit4TestListener extends RunListener {
return methodName;
}
@Override
public void testIgnored(Description description) {
final String methodName = getFullMethodName(description);
if (methodName == null) {
@@ -91,6 +91,7 @@ public class JUnit4TestRunnerUtil {
}
return classMethods.isEmpty() ? allClasses : allClasses.filterWith(new Filter() {
@Override
public boolean shouldRun(Description description) {
if (description.isTest()) {
final Set<String> methods = classMethods.get(JUnit4ReflectionUtil.getClassName(description));
@@ -121,6 +122,7 @@ public class JUnit4TestRunnerUtil {
return true;
}
@Override
public String describe() {
return "Tests";
}
@@ -151,10 +153,12 @@ public class JUnit4TestRunnerUtil {
final Request classRequest = JUnit45ClassesRequestBuilder.createIgnoreIgnoredClassRequest(clazz, true);
final Filter ignoredTestFilter = Filter.matchMethodDescription(testMethodDescription);
return classRequest.filterWith(new Filter() {
@Override
public boolean shouldRun(Description description) {
return ignoredTestFilter.shouldRun(description);
}
@Override
public String describe() {
return "Ignored " + methodName;
}
@@ -188,6 +192,7 @@ public class JUnit4TestRunnerUtil {
return Request.method(clazz, methodName);
}
return Request.aClass(clazz).filterWith(new Filter() {
@Override
public boolean shouldRun(Description description) {
if (description.isTest() && description.getDisplayName().startsWith("warning(junit.framework.TestSuite$")) {
return true;
@@ -196,6 +201,7 @@ public class JUnit4TestRunnerUtil {
return methodFilter.shouldRun(description);
}
@Override
public String describe() {
return methodFilter.describe();
}
@@ -248,6 +254,7 @@ public class JUnit4TestRunnerUtil {
Class.forName("org.junit.runners.BlockJUnit4ClassRunner"); //ignore for junit4.4 and <
final Constructor<? extends Runner> runnerConstructor = runnerClass.getConstructor(Class.class);
return Request.runner(runnerConstructor.newInstance(clazz)).filterWith(new Filter() {
@Override
public boolean shouldRun(Description description) {
final String descriptionMethodName = description.getMethodName();
//filter by params
@@ -264,6 +271,7 @@ public class JUnit4TestRunnerUtil {
return true;
}
@Override
public String describe() {
if (parameterString == null) {
return methodName + " with any parameter";
@@ -19,10 +19,12 @@ import com.intellij.execution.TestDiscoveryListener;
import com.intellij.rt.execution.junit.IDEAJUnitListenerEx;
public class JUnitTestDiscoveryListener extends TestDiscoveryListener implements IDEAJUnitListenerEx {
@Override
public String getFrameworkId() {
return "j";
}
@Override
public void testFinished(String className, String methodName) {
testFinished(className, methodName, true);
}
@@ -14,6 +14,7 @@ public interface JUnitTestTreeNodeManager {
String getTestLocation(Description description, String className, String methodName);
JUnitTestTreeNodeManager JAVA_NODE_NAMES_MANAGER = new JUnitTestTreeNodeManager() {
@Override
public TestNodePresentation getRootNodePresentation(String fullName) {
if (fullName == null) {
return new TestNodePresentation(null, null);
@@ -28,6 +29,7 @@ public interface JUnitTestTreeNodeManager {
return new TestNodePresentation(name, comment);
}
@Override
public String getNodeName(String fqName, boolean splitBySlash) {
if (fqName == null) return null;
final int idx = fqName.indexOf("[");
@@ -45,6 +47,7 @@ public interface JUnitTestTreeNodeManager {
return dotInClassFQNIdx > -1 ? fqName.substring(dotInClassFQNIdx + 1) : fqName;
}
@Override
public String getTestLocation(Description description, String className, String methodName) {
return "locationHint='java:test://" +
MapSerializerUtil.escapeStr(className + "/" + getNodeName(methodName, true), MapSerializerUtil.STD_ESCAPER) +
@@ -1,7 +1,6 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.rt.junit;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
@@ -9,6 +8,7 @@ public class DeafStream extends OutputStream {
public static final DeafStream CURRENT = new DeafStream();
public static final PrintStream DEAF_PRINT_STREAM = new PrintStream(CURRENT);
public void write(int b) throws IOException {
@Override
public void write(int b) {
}
}
@@ -6,7 +6,7 @@ import java.util.ArrayList;
import java.util.List;
public interface IdeaTestRunner {
void createListeners(ArrayList listeners, int count);
void createListeners(ArrayList<String> listeners, int count);
/**
* @return -2 internal failure
@@ -16,7 +16,7 @@ public interface IdeaTestRunner {
int startRunnerWithArgs(String[] args, String name, int count, boolean sendTree);
Object getTestToStart(String[] args, String name);
List getChildTests(Object description);
List<?> getChildTests(Object description);
String getStartDescription(Object child);
String getTestClassName(Object child);
@@ -24,7 +24,7 @@ public interface IdeaTestRunner {
class Repeater {
public static int startRunnerWithArgs(IdeaTestRunner testRunner,
String[] args,
ArrayList listeners,
ArrayList<String> listeners,
String name,
int count,
boolean sendTree) {
@@ -33,8 +33,8 @@ public interface IdeaTestRunner {
return testRunner.startRunnerWithArgs(args, name, count, sendTree);
}
else {
boolean success = true;
if (count > 0) {
boolean success = true;
int i = 0;
while (i++ < count) {
final int result = testRunner.startRunnerWithArgs(args, name, count, sendTree);
@@ -48,7 +48,6 @@ public interface IdeaTestRunner {
return success ? 0 : -1;
}
else {
boolean success = true;
while (true) {
int result = testRunner.startRunnerWithArgs(args, name, count, sendTree);
if (result == -2) {
@@ -20,43 +20,49 @@ public class JUnitForkedSplitter extends ForkedSplitter {
}
@Override
protected String getStarterName() {
return JUnitForkedStarter.class.getName();
}
@Override
protected Object createRootDescription(String[] args, String configName)
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
myTestRunner = (IdeaTestRunner)JUnitStarter.getAgentClass((String)myNewArgs.get(0)).newInstance();
myTestRunner = (IdeaTestRunner)JUnitStarter.getAgentClass(myNewArgs.get(0)).newInstance();
return myTestRunner.getTestToStart(args, configName);
}
@Override
protected String getTestClassName(Object child) {
return myTestRunner.getTestClassName(child);
}
protected List createChildArgs(Object child) {
List newArgs = new ArrayList();
@Override
protected List<String> createChildArgs(Object child) {
List<String> newArgs = new ArrayList<String>();
newArgs.add(myTestRunner.getStartDescription(child));
newArgs.addAll(myNewArgs);
return newArgs;
}
protected List createPerModuleArgs(String packageName,
String workingDir,
List classNames,
Object rootDescription,
String filters) throws IOException {
@Override
protected List<String> createPerModuleArgs(String packageName,
String workingDir,
List<String> classNames,
Object rootDescription,
String filters) throws IOException {
File tempFile = File.createTempFile("idea_junit", ".tmp");
tempFile.deleteOnExit();
JUnitStarter.printClassesList(classNames, packageName, "", filters, tempFile);
final List childArgs = new ArrayList();
final List<String> childArgs = new ArrayList<String>();
childArgs.add("@" + tempFile.getAbsolutePath());
childArgs.addAll(myNewArgs);
return childArgs;
}
protected List getChildren(Object child) {
@Override
protected List<?> getChildren(Object child) {
return myTestRunner.getChildTests(child);
}
}
@@ -9,19 +9,19 @@ import java.util.List;
public class JUnitForkedStarter {
public static void main(String[] args) throws Exception {
List argList = new ArrayList();
for (int i = 0; i < args.length; i++) {
final int count = RepeatCount.getCount(args[i]);
List<String> argList = new ArrayList<String>();
for (String arg : args) {
final int count = RepeatCount.getCount(arg);
if (count != 0) {
JUnitStarter.ourCount = count;
continue;
}
argList.add(args[i]);
argList.add(arg);
}
args = (String[])argList.toArray(new String[0]);
args = argList.toArray(new String[0]);
final String[] childTestDescription = {args[0]};
final String argentName = args[1];
final ArrayList listeners = new ArrayList();
final ArrayList<String> listeners = new ArrayList<String>();
for (int i = 2, argsLength = args.length; i < argsLength; i++) {
listeners.add(args[i]);
}
@@ -7,8 +7,8 @@ import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Vector;
/**
* Before rename or move
@@ -34,14 +34,10 @@ public class JUnitStarter {
protected static int ourCount = 1;
public static String ourRepeatCount = null;
public static void main(String[] args) throws IOException {
Vector argList = new Vector();
for (int i = 0; i < args.length; i++) {
String arg = args[i];
argList.addElement(arg);
}
public static void main(String[] args) {
List<String> argList = new ArrayList<String>(Arrays.asList(args));
final ArrayList listeners = new ArrayList();
final ArrayList<String> listeners = new ArrayList<String>();
final String[] name = new String[1];
String agentName = processParameters(argList, listeners, name);
@@ -53,17 +49,15 @@ public class JUnitStarter {
System.exit(-3);
}
String[] array = new String[argList.size()];
argList.copyInto(array);
String[] array = argList.toArray(new String[0]);
int exitCode = prepareStreamsAndStart(array, agentName, listeners, name[0]);
System.exit(exitCode);
}
private static String processParameters(Vector args, final List listeners, String[] params) {
private static String processParameters(List<String> args, final List<String> listeners, String[] params) {
String agentName = isJUnit5Preferred() ? JUNIT5_RUNNER_NAME : JUNIT4_RUNNER_NAME;
Vector result = new Vector(args.size());
for (int i = 0; i < args.size(); i++) {
String arg = (String)args.get(i);
List<String> result = new ArrayList<String>(args.size());
for (String arg : args) {
if (arg.startsWith(IDE_VERSION)) {
//ignore
}
@@ -128,14 +122,11 @@ public class JUnitStarter {
continue;
}
result.addElement(arg);
result.add(arg);
}
}
args.removeAllElements();
for (int i = 0; i < result.size(); i++) {
String arg = (String)result.get(i);
args.addElement(arg);
}
args.clear();
args.addAll(result);
if (JUNIT3_RUNNER_NAME.equals(agentName)) {
try {
Class.forName("org.junit.runner.Computer");
@@ -175,16 +166,15 @@ public class JUnitStarter {
}
public static boolean checkVersion(String[] args, PrintStream printStream) {
for (int i = 0; i < args.length; i++) {
String arg = args[i];
for (String arg : args) {
if (arg.startsWith(IDE_VERSION)) {
int ideVersion = Integer.parseInt(arg.substring(IDE_VERSION.length()));
if (ideVersion != VERSION) {
printStream.println("Wrong agent version: " + VERSION + ". IDE expects version: " + ideVersion);
printStream.flush();
return false;
} else
return true;
}
return true;
}
}
return false;
@@ -214,13 +204,13 @@ public class JUnitStarter {
private static int prepareStreamsAndStart(String[] args,
final String agentName,
ArrayList listeners,
ArrayList<String> listeners,
String name) {
try {
IdeaTestRunner testRunner = (IdeaTestRunner)getAgentClass(agentName).newInstance();
if (ourCommandFileName != null) {
if (!"none".equals(ourForkMode) || ourWorkingDirs != null && new File(ourWorkingDirs).length() > 0) {
final List newArgs = new ArrayList();
final List<String> newArgs = new ArrayList<String>();
newArgs.add(agentName);
newArgs.addAll(listeners);
return new JUnitForkedSplitter(ourWorkingDirs, ourForkMode, newArgs)
@@ -236,19 +226,19 @@ public class JUnitStarter {
}
static Class getAgentClass(String agentName) throws ClassNotFoundException {
static Class<?> getAgentClass(String agentName) throws ClassNotFoundException {
return Class.forName(agentName);
}
public static void printClassesList(List classNames, String packageName, String category, String filters, File tempFile) throws IOException {
public static void printClassesList(List<String> classNames, String packageName, String category, String filters, File tempFile) throws IOException {
final PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(tempFile), "UTF-8"));
try {
writer.println(packageName); //package name
writer.println(category); //category
writer.println(filters); //patterns
for (int i = 0; i < classNames.size(); i++) {
writer.println(classNames.get(i));
for (String name : classNames) {
writer.println(name);
}
}
finally {
@@ -39,14 +39,14 @@ public class TestNGForkTest {
new TestNGForkedSplitter(tempFile.getCanonicalPath(), Collections.singletonList(tempFile.getCanonicalPath())) {
private boolean myStarted = false;
@Override
protected int startChildFork(List args, File workingDir, String classpath, List moduleOptions, String repeatCount) throws IOException {
protected int startChildFork(List<String> args, File workingDir, String classpath, List<String> moduleOptions, String repeatCount) throws IOException {
Assert.assertEquals(dynamicClasspath, myDynamicClasspath);
Assert.assertArrayEquals(vmParams, myVMParameters.toArray());
Assert.assertEquals(workingDirFromFile, workingDir.getName());
Assert.assertEquals(classpathFromFile, classpath);
Assert.assertEquals(moduleExpectedOptions, moduleOptions);
Assert.assertEquals(1, args.size());
final String generatedSuite = FileUtil.loadFile(new File((String)args.get(0)));
final String generatedSuite = FileUtil.loadFile(new File(args.get(0)));
Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE suite SYSTEM \"http://testng.org/testng-1.0.dtd\">\n" +
"<suite name=\"Default Suite\">\n" +
@@ -12,14 +12,17 @@ public class IDEATestNGConfigurationListener implements IConfigurationListener {
myListener = listener;
}
@Override
public void onConfigurationSuccess(ITestResult itr) {
myListener.onConfigurationSuccess(itr, !myStarted);
}
@Override
public void onConfigurationFailure(ITestResult itr) {
myListener.onConfigurationFailure(itr, !myStarted);
}
@Override
public void onConfigurationSkip(ITestResult itr) {
myListener.onConfigurationSkip(itr);
}
@@ -12,6 +12,7 @@ public class IDEATestNGInvokedMethodListener implements IInvokedMethodListener {
myListener = listener;
}
@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
synchronized (myListener) {
if (!testResult.getMethod().isTest()) {
@@ -21,5 +22,6 @@ public class IDEATestNGInvokedMethodListener implements IInvokedMethodListener {
}
//should be covered by test listeners
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {}
}
@@ -387,26 +387,32 @@ public class IDEATestNGRemoteListener {
return testNameFromAnnotation == null || testNameFromAnnotation.length() == 0 ? method.getMethodName() : testNameFromAnnotation;
}
@Override
public Object[] getParameters() {
return myResult.getParameters();
}
@Override
public String getMethodName() {
return myResult.getMethod().getMethodName();
}
@Override
public String getDisplayMethodName() {
return myTestName;
}
@Override
public String getClassName() {
return myResult.getMethod().getTestClass().getName();
}
@Override
public long getDuration() {
return myResult.getEndMillis() - myResult.getStartMillis();
}
@Override
public List<String> getTestHierarchy() {
final List<String> hierarchy;
final XmlTest xmlTest = myResult.getTestClass().getXmlTest();
@@ -418,21 +424,25 @@ public class IDEATestNGRemoteListener {
return hierarchy;
}
@Override
public String getFileName() {
final XmlTest xmlTest = myResult.getTestClass().getXmlTest();
return xmlTest != null ? xmlTest.getSuite().getFileName() : null;
}
@Override
public String getXmlTestName() {
final XmlTest xmlTest = myResult.getTestClass().getXmlTest();
return xmlTest != null ? xmlTest.getName() : null;
}
@Override
public Throwable getThrowable() {
return myResult.getThrowable();
}
@Override
public List<Integer> getIncludeMethods() {
IClass testClass = myResult.getTestClass();
if (testClass == null) return null;
@@ -11,10 +11,12 @@ public class IDEATestNGSuiteListener implements ISuiteListener {
myListener = listener;
}
@Override
public void onStart(ISuite suite) {
myListener.onStart(suite);
}
@Override
public void onFinish(ISuite suite) {
myListener.onFinish(suite);
}
@@ -12,30 +12,37 @@ public class IDEATestNGTestListener implements ITestListener {
myListener = listener;
}
@Override
public void onTestStart(ITestResult result) {
myListener.onTestStart(result);
}
@Override
public void onTestSuccess(ITestResult result) {
myListener.onTestSuccess(result);
}
@Override
public void onTestFailure(ITestResult result) {
myListener.onTestFailure(result);
}
@Override
public void onTestSkipped(ITestResult result) {
myListener.onTestSkipped(result);
}
@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
myListener.onTestFailedButWithinSuccessPercentage(result);
}
@Override
public void onStart(ITestContext context) {
myListener.onStart(context);
}
@Override
public void onFinish(ITestContext context) {
myListener.onFinish(context);
}
@@ -12,7 +12,6 @@ import java.net.Socket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Vector;
public class RemoteTestNGStarter {
private static final String SOCKET = "-socket";
@@ -22,7 +21,7 @@ public class RemoteTestNGStarter {
String param = null;
String commandFileName = null;
String workingDirs = null;
Vector resultArgs = new Vector();
List<String> resultArgs = new ArrayList<String>();
for (; i < args.length; i++) {
String arg = args[i];
if (arg.startsWith("@name")) {
@@ -67,7 +66,7 @@ public class RemoteTestNGStarter {
final BufferedReader reader = new BufferedReader(new FileReader(temp));
final List newArgs = new ArrayList();
final List<String> newArgs = new ArrayList<String>();
try {
final String cantRunMessage = "CantRunException";
while (true) {
@@ -105,7 +104,7 @@ public class RemoteTestNGStarter {
}
final IDEARemoteTestNG testNG = new IDEARemoteTestNG(param);
CommandLineArgs cla = new CommandLineArgs();
new JCommander(Collections.singletonList(cla), (String[])resultArgs.toArray(new String[0]));
new JCommander(Collections.singletonList(cla), resultArgs.toArray(new String[0]));
testNG.configure(cla);
testNG.run();
}
@@ -6,9 +6,10 @@ import com.intellij.rt.execution.testFrameworks.AbstractExpectedPatterns;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
class TestNGExpectedPatterns extends AbstractExpectedPatterns {
private static final List PATTERNS = new ArrayList();
private static final List<Pattern> PATTERNS = new ArrayList<Pattern>();
private static final String[] PATTERN_STRINGS = new String[]{
"expected same with:\\<(.*)\\> but was:\\<(.*)\\>",
@@ -12,7 +12,7 @@ import java.util.Map;
public class TestNGForkedSplitter extends ForkedByModuleSplitter {
public TestNGForkedSplitter(String workingDirsPath, List newArgs) {
public TestNGForkedSplitter(String workingDirsPath, List<String> newArgs) {
super(workingDirsPath, "none", newArgs);
}
@@ -29,11 +29,11 @@ public class TestNGForkedSplitter extends ForkedByModuleSplitter {
@Override
protected int startPerModuleFork(String moduleName,
List classNames,
List<String> classNames,
String packageName,
String workingDir,
String classpath,
List moduleOptions,
List<String> moduleOptions,
String repeatCount, int result, final String filters) throws Exception {
final LinkedHashMap<String, Map<String, List<String>>> classes = new LinkedHashMap<String, Map<String, List<String>>>();
for (Object className : classNames) {
@@ -42,7 +42,7 @@ public class TestNGForkedSplitter extends ForkedByModuleSplitter {
String rootPath = null;
if (!myNewArgs.isEmpty()) {
rootPath = new File((String)myNewArgs.get(0)).getParent();
rootPath = new File(myNewArgs.get(0)).getParent();
}
final File file =
@@ -8,7 +8,7 @@ import org.testng.remote.RemoteArgs;
import java.util.Arrays;
public class TestNGForkedStarter {
public static void main(String[] args) throws Exception {
public static void main(String[] args) {
final IDEARemoteTestNG testNG = new IDEARemoteTestNG(null);
CommandLineArgs cla = new CommandLineArgs();
RemoteArgs ra = new RemoteArgs();
@@ -9,32 +9,41 @@ import org.testng.ITestContext;
import org.testng.ITestResult;
public class TestNGTestDiscoveryListener extends TestDiscoveryListener implements IDEATestNGListener, ISuiteListener {
@Override
public void onTestStart(ITestResult result) {
testStarted(result.getTestClass().getName(), result.getTestName());
}
@Override
public void onTestSuccess(ITestResult result) {
testFinished(result.getTestClass().getName(), result.getName(), true);
}
@Override
public void onTestFailure(ITestResult result) {
testFinished(result.getTestClass().getName(), result.getName(), ComparisonFailureData.isAssertionError(result.getThrowable().getClass()));
}
@Override
public void onTestSkipped(ITestResult result) {
testFinished(result.getTestClass().getName(), result.getName(), false);
}
@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
testFinished(result.getTestClass().getName(), result.getName(), true);
}
@Override
public void onStart(ITestContext context) {}
@Override
public void onFinish(ITestContext context) {}
@Override
public void onStart(ISuite suite) {
testRunStarted(suite.getName());
}
@Override
public void onFinish(ISuite suite) {
testRunFinished(suite.getName());
}
@@ -17,6 +17,7 @@ import java.util.Map;
public class TestNGXmlSuiteHelper {
public interface Logger {
Logger DEAF = new Logger() {
@Override
public void log(Throwable e) {}
};