Bug 521243: [JUnit 5] Find workarounds in place of bug 502563
Change-Id: Ie5524429ff89c869b02b4e720ef13ae2966ee937
diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/ITestRunListener2.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/ITestRunListener2.java
index a8c7229..63d1d06 100644
--- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/ITestRunListener2.java
+++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/ITestRunListener2.java
@@ -82,7 +82,7 @@
* isDynamicTest: true or false
* parentId: the unique testId of its parent if it is a dynamic test, otherwise can be "-1"
* displayName: the display name of the test
- * parameterTypes: comma-separated list of fully qualified type names of method parameters if applicable, otherwise an empty string
+ * parameterTypes: comma-separated list of method parameter types if applicable, otherwise an empty string
* uniqueId: the unique ID of the test provided by JUnit launcher, otherwise an empty string
*
* Example: 324968,testPass(junit.tests.MyTest),false,1,false,-1,A simple test case,"",""
diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestElement.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestElement.java
index d27c535..2062109 100644
--- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestElement.java
+++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestElement.java
@@ -179,8 +179,9 @@
private String fDisplayName;
/**
- * The array of fully qualified type names of method parameters if applicable, otherwise
- * <code>null</code>.
+ * The array of method parameter types (as given by
+ * org.junit.platform.engine.support.descriptor.MethodSource.getMethodParameterTypes()) if
+ * applicable, otherwise <code>null</code>.
*/
private String[] fParameterTypes;
@@ -213,10 +214,11 @@
* @param id the test id
* @param testName the test name
* @param displayName the test display name, can be <code>null</code>
- * @param parameterTypes the array of fully qualified type names of method parameters if
- * applicable, otherwise <code>null</code>
- * @param uniqueId the unique ID of the test element, can be <code>null</code> as it is applicable to JUnit 5 and above
-
+ * @param parameterTypes the array of method parameter types (as given by
+ * org.junit.platform.engine.support.descriptor.MethodSource.getMethodParameterTypes())
+ * if applicable, otherwise <code>null</code>
+ * @param uniqueId the unique ID of the test element, can be <code>null</code> as it is applicable
+ * to JUnit 5 and above
*/
public TestElement(TestSuiteElement parent, String id, String testName, String displayName, String[] parameterTypes, String uniqueId) {
Assert.isNotNull(id);
@@ -404,8 +406,9 @@
}
/**
- * @return the array of fully qualified type names of method parameters if applicable, otherwise
- * <code>null</code>
+ * @return the array of method parameter types (as given by
+ * org.junit.platform.engine.support.descriptor.MethodSource.getMethodParameterTypes()) if
+ * applicable, otherwise <code>null</code>
*/
public String[] getParameterTypes() {
return fParameterTypes;
@@ -422,11 +425,10 @@
}
/**
- * Creates encoded type signatures from fully qualified type names provided by
- * {@link #getParameterTypes()}.
+ * Creates encoded type signatures from type names provided by {@link #getParameterTypes()}.
*
- * @return the array of parameter type signatures obtained by converting the fully qualified
- * type names from {@link #getParameterTypes()}, can be <code>null</code>
+ * @return the array of parameter type signatures obtained by converting the type names from
+ * {@link #getParameterTypes()}, can be <code>null</code>
*/
public String[] getParameterTypeSignatures() {
// TODO - JUnit5: Create encoded type signatures so that IType.getMethod(String name, String[] parameterTypeSignatures) can find the method
diff --git a/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/MessageIds.java b/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/MessageIds.java
index b799921..6564040 100644
--- a/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/MessageIds.java
+++ b/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/MessageIds.java
@@ -113,7 +113,7 @@
* isDynamicTest = "true" or "false" <br>
* parentId = the unique id of its parent if it is a dynamic test, otherwise can be "-1" <br>
* displayName = the display name of the test <br>
- * parameterTypes = comma-separated list of fully qualified type names of method parameters if applicable, otherwise an empty string <br>
+ * parameterTypes = comma-separated list of method parameter types if applicable, otherwise an empty string <br>
* See: ITestRunListener2#testTreeEntry
*
*/
diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/util/JUnitStubUtility.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/util/JUnitStubUtility.java
index 82bdbab..e0e8f08 100644
--- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/util/JUnitStubUtility.java
+++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/util/JUnitStubUtility.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,6 +10,10 @@
*******************************************************************************/
package org.eclipse.jdt.internal.junit.util;
+import java.util.ArrayList;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.text.edits.MalformedTreeException;
@@ -264,6 +268,71 @@
return null;
}
+ /**
+ * Returns a comma-separated list of method parameter type names in parentheses or "" if the method
+ * has no parameters. If fully qualified type names are required, <code>$</code> is used as the
+ * enclosing type separator in the qualified type name. Type erasure is performed on a parameterized
+ * type, arrays use the square brackets and a type parameter is resolved while creating the return
+ * value.
+ *
+ * @param method the method whose parameter types are required
+ * @param useSimpleNames <code>true</code> if the last segment of the type name should be used
+ * instead of the fully qualified type name
+ * @return a comma-separated list of method parameter type names in parentheses
+ */
+ public static String getParameterTypes(final IMethod method, final boolean useSimpleNames) {
+ String paramTypes= ""; //$NON-NLS-1$
+
+ int numOfParams= method.getNumberOfParameters();
+ if (numOfParams > 0) {
+ String[] parameterTypeSignatures= method.getParameterTypes();
+ ArrayList<String> parameterTypeNames= new ArrayList<>(numOfParams);
+
+ try {
+ String[] fullNames= null;
+ for (int i= 0; i < parameterTypeSignatures.length; i++) {
+ String paramTypeSign= parameterTypeSignatures[i];
+ StringBuffer buf= new StringBuffer();
+
+ String typeSign= Signature.getTypeErasure(paramTypeSign);
+ String fullName;
+ if (useSimpleNames) {
+ fullName= JavaModelUtil.getResolvedTypeName(typeSign, method.getDeclaringType(), '.');
+ } else {
+ fullName= JavaModelUtil.getResolvedTypeName(typeSign, method.getDeclaringType(), '$');
+ }
+ if (fullName == null) { // e.g. a type parameter "QE;"
+ if (fullNames == null) {
+ fullNames= JUnitStubUtility.getParameterTypeNamesForSeeTag(method);
+ }
+ fullName= fullNames[i];
+ }
+
+ if (fullName != null) {
+ buf.append(fullName);
+ int dim= Signature.getArrayCount(typeSign);
+ while (dim > 0) {
+ buf.append("[]"); //$NON-NLS-1$
+ dim--;
+ }
+ }
+
+ parameterTypeNames.add(buf.toString());
+ }
+ } catch (JavaModelException e) {
+ // ignore
+ }
+
+ Stream<String> stream= parameterTypeNames.stream();
+ if (useSimpleNames) {
+ stream= stream.map(paramTypeName -> paramTypeName.substring(paramTypeName.lastIndexOf('.') + 1));
+ }
+ paramTypes= stream.collect(Collectors.joining(", ", "(", ")")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ return paramTypes;
+ }
+
/*
* Evaluates if a member (possible from another package) is visible from
* elements in a package.
diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/launcher/JUnitLaunchConfigurationTab.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/launcher/JUnitLaunchConfigurationTab.java
index b9f6a25..99e9ae1 100644
--- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/launcher/JUnitLaunchConfigurationTab.java
+++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/launcher/JUnitLaunchConfigurationTab.java
@@ -18,8 +18,6 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
@@ -90,7 +88,6 @@
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
-import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.junit.BasicElementLabels;
import org.eclipse.jdt.internal.junit.JUnitCorePlugin;
import org.eclipse.jdt.internal.junit.Messages;
@@ -731,7 +728,7 @@
if (!isJUnit3 && !Modifier.isPrivate(flags) && !Modifier.isStatic(flags)) {
IAnnotation annotation= method.getAnnotation("Test"); //$NON-NLS-1$
if (annotation.exists()) {
- methodNames.add(methodName + getParameterTypes(method, false));
+ methodNames.add(methodName + JUnitStubUtility.getParameterTypes(method, false));
} else if (isJUnit5) {
boolean hasAnyTestAnnotation= method.getAnnotation("TestFactory").exists() //$NON-NLS-1$
|| method.getAnnotation("Testable").exists() //$NON-NLS-1$
@@ -739,78 +736,13 @@
|| method.getAnnotation("ParameterizedTest").exists() //$NON-NLS-1$
|| method.getAnnotation("RepeatedTest").exists(); //$NON-NLS-1$
if (hasAnyTestAnnotation || isAnnotatedWithTestable(method, type, javaProject)) {
- methodNames.add(methodName + getParameterTypes(method, false));
+ methodNames.add(methodName + JUnitStubUtility.getParameterTypes(method, false));
}
}
}
}
}
- /**
- * Returns a comma-separated list of method parameter type names in parentheses or "" if the method
- * has no parameters. If fully qualified type names are required, <code>$</code> is used as the
- * enclosing type separator in the qualified type name. Type erasure is performed on a parameterized
- * type, arrays use the square brackets and a type parameter is resolved while creating the return
- * value.
- *
- * @param method the method whose parameter types are required
- * @param useSimpleNames <code>true</code> if the last segment of the type name should be used
- * instead of the fully qualified type name
- * @return a comma-separated list of method parameter type names in parentheses
- */
- static String getParameterTypes(final IMethod method, final boolean useSimpleNames) {
- String paramTypes= ""; //$NON-NLS-1$
-
- int numOfParams= method.getNumberOfParameters();
- if (numOfParams > 0) {
- String[] parameterTypeSignatures= method.getParameterTypes();
- ArrayList<String> parameterTypeNames= new ArrayList<>(numOfParams);
-
- try {
- String[] fullNames= null;
- for (int i= 0; i < parameterTypeSignatures.length; i++) {
- String paramTypeSign= parameterTypeSignatures[i];
- StringBuffer buf= new StringBuffer();
-
- String typeSign= Signature.getTypeErasure(paramTypeSign);
- String fullName;
- if (useSimpleNames) {
- fullName= JavaModelUtil.getResolvedTypeName(typeSign, method.getDeclaringType(), '.');
- } else {
- fullName= JavaModelUtil.getResolvedTypeName(typeSign, method.getDeclaringType(), '$');
- }
- if (fullName == null) { // e.g. a type parameter "QE;"
- if (fullNames == null) {
- fullNames= JUnitStubUtility.getParameterTypeNamesForSeeTag(method);
- }
- fullName= fullNames[i];
- }
-
- if (fullName != null) {
- buf.append(fullName);
- int dim= Signature.getArrayCount(typeSign);
- while (dim > 0) {
- buf.append("[]"); //$NON-NLS-1$
- dim--;
- }
- }
-
- parameterTypeNames.add(buf.toString());
- }
- } catch (JavaModelException e) {
- // ignore
- }
-
- Stream<String> stream= parameterTypeNames.stream();
- if (useSimpleNames) {
- stream= stream.map(paramTypeName -> paramTypeName.substring(paramTypeName.lastIndexOf('.') + 1));
- }
- paramTypes= stream.collect(Collectors.joining(", ", "(", ")")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- return paramTypes;
- }
-
// See JUnit5TestFinder.Annotation#annotates also.
private boolean isAnnotatedWithTestable(IMethod method, IType declaringType, IJavaProject javaProject) throws JavaModelException {
for (IAnnotation annotation : method.getAnnotations()) {
diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/launcher/JUnitLaunchShortcut.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/launcher/JUnitLaunchShortcut.java
index d0702c6..cf432c2 100644
--- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/launcher/JUnitLaunchShortcut.java
+++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/launcher/JUnitLaunchShortcut.java
@@ -69,6 +69,7 @@
import org.eclipse.jdt.internal.junit.ui.JUnitMessages;
import org.eclipse.jdt.internal.junit.ui.JUnitPlugin;
import org.eclipse.jdt.internal.junit.util.ExceptionHandler;
+import org.eclipse.jdt.internal.junit.util.JUnitStubUtility;
import org.eclipse.jdt.internal.junit.util.TestSearchEngine;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
@@ -347,7 +348,7 @@
case IJavaElement.METHOD: {
IMethod method= (IMethod)element;
testName= method.getElementName(); // Test-names can not be specified when launching a Java method.
- testName+= JUnitLaunchConfigurationTab.getParameterTypes(method, false);
+ testName+= JUnitStubUtility.getParameterTypes(method, false);
containerHandleId= EMPTY_STRING;
IType declaringType= method.getDeclaringType();
mainTypeQualifiedName= declaringType.getFullyQualifiedName('.');
@@ -409,7 +410,7 @@
case IJavaElement.METHOD:
IMethod method= (IMethod)element;
String methodName= method.getElementName();
- methodName+= JUnitLaunchConfigurationTab.getParameterTypes(method, true); // use simple names of parameter types
+ methodName+= JUnitStubUtility.getParameterTypes(method, true); // use simple names of parameter types
return method.getDeclaringType().getElementName() + '.' + methodName;
default:
throw new IllegalArgumentException("Invalid element type to create a launch configuration: " + element.getClass().getName()); //$NON-NLS-1$