[junit 5] ensure long method presentation if method has braces in the name (IDEA-280519)

GitOrigin-RevId: cc7291bd3663483649cab9baae4d30b2e9439477
This commit is contained in:
Anna Kozlova
2021-12-09 15:18:10 +00:00
committed by intellij-monorepo-bot
parent baf9b751bf
commit d3bec9d0e8
2 changed files with 19 additions and 5 deletions
@@ -1,6 +1,7 @@
package com.intellij.codeInspection.tests.kotlin
import com.intellij.codeInsight.TestFrameworks
import com.intellij.execution.junit.JUnitConfiguration
import com.intellij.execution.junit.codeInsight.JUnit5TestFrameworkSetupUtil
import com.intellij.psi.PsiClassOwner
import com.intellij.testFramework.RunsInEdt
@@ -29,4 +30,17 @@ annotation class CombinedKotlinAnnotation""")
Assertions.assertNotNull(TestFrameworks.detectFramework ((file as PsiClassOwner).classes[0]))
}
@Test
fun bracesInMethodName() {
val file = fixture.configureByText("tests.kt", """
class Tests {
@org.junit.jupiter.api.Test
fun `test wi<caret>th (in name)`() {}
}
""".trimIndent())
Assertions.assertInstanceOf(PsiClassOwner::class.java, file)
val testMethod = (file as PsiClassOwner).classes[0].methods[0]
Assertions.assertEquals("test with (in name)()", JUnitConfiguration.Data.getMethodPresentation(testMethod))
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2020 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.
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.execution.junit;
@@ -19,7 +19,6 @@ import com.intellij.execution.runners.ExecutionEnvironmentBuilder;
import com.intellij.execution.target.LanguageRuntimeType;
import com.intellij.execution.target.TargetEnvironmentAwareRunProfile;
import com.intellij.execution.target.TargetEnvironmentConfiguration;
import com.intellij.execution.target.TargetEnvironmentConfigurations;
import com.intellij.execution.target.java.JavaLanguageRuntimeConfiguration;
import com.intellij.execution.target.java.JavaLanguageRuntimeType;
import com.intellij.execution.testframework.TestRunnerBundle;
@@ -784,11 +783,12 @@ public class JUnitConfiguration extends JavaTestConfigurationWithDiscoverySuppor
}
public static @NlsSafe String getMethodPresentation(PsiMethod method) {
if (!method.getParameterList().isEmpty() && MetaAnnotationUtil.isMetaAnnotated(method, JUnitUtil.TEST5_ANNOTATIONS)) {
return method.getName() + "(" + ClassUtil.getVMParametersMethodSignature(method) + ")";
String methodName = method.getName();
if ((!method.getParameterList().isEmpty() || methodName.contains("(") || methodName.contains(")")) && MetaAnnotationUtil.isMetaAnnotated(method, JUnitUtil.TEST5_ANNOTATIONS)) {
return methodName + "(" + ClassUtil.getVMParametersMethodSignature(method) + ")";
}
else {
return method.getName();
return methodName;
}
}