junit 5: erasure type parameters for test signatures

This commit is contained in:
Anna.Kozlova
2017-07-20 18:56:14 +02:00
parent 87f6b96f83
commit 8ba947593d
2 changed files with 9 additions and 4 deletions
@@ -44,6 +44,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.ClassUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.refactoring.listeners.RefactoringElementListener;
import com.intellij.rt.execution.junit.JUnitStarter;
import com.intellij.rt.execution.junit.RepeatCount;
@@ -660,8 +661,11 @@ public class JUnitConfiguration extends JavaTestConfigurationBase {
public static String getMethodPresentation(PsiMethod method) {
if (method.getParameterList().getParametersCount() > 0 && MetaAnnotationUtil.isMetaAnnotated(method, JUnitUtil.TEST5_ANNOTATIONS)) {
return method.getName() + "(" + StringUtil.join(method.getParameterList().getParameters(),
param -> param.getType().accept(createSignatureVisitor()),
return method.getName() + "(" + StringUtil.join(method.getParameterList().getParameters(),
param -> {
PsiType type = TypeConversionUtil.erasure(param.getType());
return type != null ? type.accept(createSignatureVisitor()) : "";
},
",") + ")";
}
else {
@@ -78,15 +78,16 @@ class JUnit5AcceptanceTest extends JUnit5CodeInsightTest {
void methodPresentations() {
doTest(() -> {
myFixture.addClass("package a; public class TestInfo {}");
PsiClass aClass = myFixture.addClass("class MyTest {" +
PsiClass aClass = myFixture.addClass("class MyTest<T extends a.TestInfo> {" +
" @org.junit.jupiter.api.Test void method() {}" +
" @org.junit.jupiter.api.Test void method(a.TestInfo info) {}" +
" @org.junit.jupiter.api.Test void method(T info) {}" +
" @org.junit.Test void method1() {}" +
" @org.junit.Test void method1(a.TestInfo info) {}" +
"}");
assertNotNull(aClass);
Stream<String> expectedData = Arrays.stream(new String[]{"method", "method(a.TestInfo)", "method1", "method1"});
Stream<String> expectedData = Arrays.stream(new String[]{"method", "method(a.TestInfo)", "method(a.TestInfo)", "method1", "method1"});
StreamEx.of(aClass.getMethods())
.zipWith(expectedData)
.forEach(e -> assertEquals(e.getValue(), JUnitConfiguration.Data.getMethodPresentation(e.getKey())));