From d27bf93258a2ac0b750ab33453ef32f0f6b49580 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Fri, 23 Sep 2016 17:11:58 +0300 Subject: [PATCH] junit: navigate to test 'constructor' for ignored tests (IDEA-159038) --- .../testframework/JavaTestLocator.java | 23 +++++++++++++------ .../junit/JUnitRerunFailedTestsTest.java | 16 +++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/java/execution/impl/src/com/intellij/execution/testframework/JavaTestLocator.java b/java/execution/impl/src/com/intellij/execution/testframework/JavaTestLocator.java index 775a5e6cf40e..3159a8ac56bb 100644 --- a/java/execution/impl/src/com/intellij/execution/testframework/JavaTestLocator.java +++ b/java/execution/impl/src/com/intellij/execution/testframework/JavaTestLocator.java @@ -56,8 +56,7 @@ public class JavaTestLocator implements SMTestLocator { PsiClass aClass = ClassUtil.findPsiClass(PsiManager.getInstance(project), path, null, true, scope); if (aClass != null) { results = ContainerUtil.newSmartList(); - results.add(paramName != null ? PsiMemberParameterizedLocation.getParameterizedLocation(aClass, paramName) - : new PsiLocation<>(project, aClass)); + results.add(createClassNavigatable(paramName, aClass)); } } else if (TEST_PROTOCOL.equals(protocol)) { @@ -67,11 +66,16 @@ public class JavaTestLocator implements SMTestLocator { PsiClass aClass = ClassUtil.findPsiClass(PsiManager.getInstance(project), className, null, true, scope); if (aClass != null) { results = ContainerUtil.newSmartList(); - PsiMethod[] methods = aClass.findMethodsByName(methodName.trim(), true); - if (methods.length > 0) { - for (PsiMethod method : methods) { - results.add(paramName != null ? new PsiMemberParameterizedLocation(project, method, aClass, paramName) - : MethodLocation.elementInClass(method, aClass)); + if (methodName.trim().equals(aClass.getName())) { + results.add(createClassNavigatable(paramName, aClass)); + } + else { + PsiMethod[] methods = aClass.findMethodsByName(methodName.trim(), true); + if (methods.length > 0) { + for (PsiMethod method : methods) { + results.add(paramName != null ? new PsiMemberParameterizedLocation(project, method, aClass, paramName) + : MethodLocation.elementInClass(method, aClass)); + } } } } @@ -80,4 +84,9 @@ public class JavaTestLocator implements SMTestLocator { return results; } + + private Location createClassNavigatable(String paramName, @NotNull PsiClass aClass) { + return paramName != null ? PsiMemberParameterizedLocation.getParameterizedLocation(aClass, paramName) + : new PsiLocation<>(aClass.getProject(), aClass); + } } diff --git a/plugins/junit/test/com/intellij/execution/junit/JUnitRerunFailedTestsTest.java b/plugins/junit/test/com/intellij/execution/junit/JUnitRerunFailedTestsTest.java index 60470ab6c0b3..98a8f3bd5c65 100644 --- a/plugins/junit/test/com/intellij/execution/junit/JUnitRerunFailedTestsTest.java +++ b/plugins/junit/test/com/intellij/execution/junit/JUnitRerunFailedTestsTest.java @@ -150,4 +150,20 @@ public class JUnitRerunFailedTestsTest extends LightCodeInsightFixtureTestCase String name = ((PsiMethod)element).getName(); assertEquals("testFoo", name); } + + public void testLocatorForIgnoredClass() throws Exception { + PsiClass aClass = myFixture.addClass("@org.junit.Ignore" + + "public class TestClass {\n" + + " @org.junit.Test" + + " public void testFoo() throws Exception {}\n" + + "}"); + final SMTestProxy testProxy = new SMTestProxy("TestClass", false, "java:test://TestClass.TestClass"); + final Project project = getProject(); + final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project); + testProxy.setLocator(JavaTestLocator.INSTANCE); + Location location = testProxy.getLocation(project, searchScope); + assertNotNull(location); + PsiElement element = location.getPsiElement(); + assertEquals(aClass, element); + } }