mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
start junit 5 test with array/inner class parameters (IDEA-172103)
This commit is contained in:
@@ -42,8 +42,7 @@ import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiFormatUtil;
|
||||
import com.intellij.psi.util.PsiFormatUtilBase;
|
||||
import com.intellij.psi.util.ClassUtil;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListener;
|
||||
import com.intellij.rt.execution.junit.RepeatCount;
|
||||
import org.jdom.Element;
|
||||
@@ -625,11 +624,37 @@ public class JUnitConfiguration extends JavaTestConfigurationBase {
|
||||
}
|
||||
|
||||
public static String getMethodPresentation(PsiMethod method) {
|
||||
return method.getParameterList().getParametersCount() > 0 && MetaAnnotationUtil.isMetaAnnotated(method, JUnitUtil.TEST5_ANNOTATIONS)
|
||||
? PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY,
|
||||
PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS,
|
||||
PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_FQ_CLASS_NAMES)
|
||||
: method.getName();
|
||||
if (method.getParameterList().getParametersCount() > 0 && MetaAnnotationUtil.isMetaAnnotated(method, JUnitUtil.TEST5_ANNOTATIONS)) {
|
||||
return method.getName() + "(" + StringUtil.join(method.getParameterList().getParameters(),
|
||||
param -> param.getType().accept(createSignatureVisitor()),
|
||||
",") + ")";
|
||||
}
|
||||
else {
|
||||
return method.getName();
|
||||
}
|
||||
}
|
||||
|
||||
private static PsiTypeVisitor<String> createSignatureVisitor() {
|
||||
return new PsiTypeVisitor<String>() {
|
||||
@Override
|
||||
public String visitPrimitiveType(PsiPrimitiveType primitiveType) {
|
||||
return primitiveType.getCanonicalText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitClassType(PsiClassType classType) {
|
||||
PsiClass aClass = classType.resolve();
|
||||
if (aClass == null) {
|
||||
return "";
|
||||
}
|
||||
return "L" + ClassUtil.getJVMClassName(aClass) + ";";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitArrayType(PsiArrayType arrayType) {
|
||||
return "[" + arrayType.getComponentType().accept(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public String getGeneratedName(final JavaRunConfigurationModule configurationModule) {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.junit5;
|
||||
|
||||
import com.intellij.execution.junit.JUnitConfiguration;
|
||||
import com.intellij.psi.PsiJavaFile;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class JUnit5NamingTest extends JUnit5CodeInsightTest {
|
||||
@Test
|
||||
void arrayParameters() {
|
||||
doTest(() -> {
|
||||
PsiJavaFile file = (PsiJavaFile)myFixture.configureByText("MyTest.java", "import org.junit.jupiter.api.*;" +
|
||||
"class MyTest {" +
|
||||
" @Test void foo(int[] i); \n" +
|
||||
" @Test void foo(String[] i); \n" +
|
||||
" @Test void foo(Foo[] i); \n" +
|
||||
" static class Foo {}" +
|
||||
"}");
|
||||
String[] methodPresentations =
|
||||
Arrays.stream(file.getClasses()[0].getMethods())
|
||||
.map(method -> JUnitConfiguration.Data.getMethodPresentation(method))
|
||||
.toArray(String[]::new);
|
||||
Assertions.assertArrayEquals(new String[] {"foo([int)", "foo([Ljava.lang.String;)", "foo([LMyTest$Foo;)"},
|
||||
methodPresentations,
|
||||
Arrays.toString(methodPresentations));
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user