cleanup [java]: no more checked exceptions in hierarchy test

GitOrigin-RevId: e6948abcf99e98ef4ca4a68138de875764cbda60
This commit is contained in:
Bas Leijdekkers
2025-11-15 09:19:05 +00:00
committed by intellij-monorepo-bot
parent 71ff6d86a3
commit b997e6c911
3 changed files with 81 additions and 103 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.ide.hierarchy;
import com.intellij.JavaTestUtil;
@@ -37,8 +37,13 @@ public class JavaCallHierarchyTest extends HierarchyViewTestBase {
protected String getBasePath() {
return "ide/hierarchy/call/" + getTestName(false);
}
@Override
protected Sdk getTestProjectJdk() {
return IdeaTestUtil.getMockJdk18();
}
private void doJavaCallerTypeHierarchyTest(@NotNull String classFqn, @NotNull String methodName, String @NotNull ... fileNames) throws Exception {
private void doCallerHierarchyTest(@NotNull String classFqn, @NotNull String methodName, String @NotNull ... fileNames) {
doHierarchyTest(() -> {
PsiClass psiClass = JavaPsiFacade.getInstance(getProject()).findClass(classFqn, ProjectScope.getProjectScope(getProject()));
assertNotNull("Class '" + classFqn + "' not found", psiClass);
@@ -48,7 +53,8 @@ public class JavaCallHierarchyTest extends HierarchyViewTestBase {
return new CallerMethodsTreeStructure(getProject(), method, HierarchyBrowserBaseEx.SCOPE_PROJECT);
}, JavaHierarchyUtil.getComparator(myProject), fileNames);
}
private void doJavaCalleeTypeHierarchyTest(@NotNull String classFqn, @NotNull String methodName, String @NotNull ... fileNames) throws Exception {
private void doCalleeHierarchyTest(@NotNull String classFqn, @NotNull String methodName, String @NotNull ... fileNames) {
doHierarchyTest(() -> {
PsiClass psiClass = JavaPsiFacade.getInstance(getProject()).findClass(classFqn, ProjectScope.getProjectScope(getProject()));
PsiMember method = psiClass.findMethodsByName(methodName, false) [0];
@@ -56,64 +62,64 @@ public class JavaCallHierarchyTest extends HierarchyViewTestBase {
}, JavaHierarchyUtil.getComparator(myProject),fileNames);
}
public void testDirectRecursion() throws Exception {
doJavaCallerTypeHierarchyTest("A", "recursive", "A.java");
public void testDirectRecursion() {
doCallerHierarchyTest("A", "recursive", "A.java");
}
public void testCalleeDirectRecursion() throws Exception {
doJavaCalleeTypeHierarchyTest("A", "recursive", "A.java");
public void testCalleeDirectRecursion() {
doCalleeHierarchyTest("A", "recursive", "A.java");
}
public void testIndirectRecursion() throws Exception {
doJavaCallerTypeHierarchyTest("A", "recursive2", "A.java");
public void testIndirectRecursion() {
doCallerHierarchyTest("A", "recursive2", "A.java");
}
public void testIdeaDev41005() throws Exception {
doJavaCallerTypeHierarchyTest("B", "xyzzy", "A.java");
public void testIdeaDev41005() {
doCallerHierarchyTest("B", "xyzzy", "A.java");
}
public void testIdeaDev41005_Inheritance() throws Exception {
doJavaCallerTypeHierarchyTest("D", "xyzzy", "A.java");
public void testIdeaDev41005_Inheritance() {
doCallerHierarchyTest("D", "xyzzy", "A.java");
}
public void testIdeaDev41005_Sibling() throws Exception {
doJavaCallerTypeHierarchyTest("D", "xyzzy", "A.java");
public void testIdeaDev41005_Sibling() {
doCallerHierarchyTest("D", "xyzzy", "A.java");
}
public void testIdeaDev41005_SiblingUnderInheritance() throws Exception {
doJavaCallerTypeHierarchyTest("D", "xyzzy", "A.java");
public void testIdeaDev41005_SiblingUnderInheritance() {
doCallerHierarchyTest("D", "xyzzy", "A.java");
}
public void testIdeaDev41232() throws Exception {
doJavaCallerTypeHierarchyTest("A", "main", "A.java");
public void testIdeaDev41232() {
doCallerHierarchyTest("A", "main", "A.java");
}
public void testDefaultConstructor() throws Exception {
doJavaCallerTypeHierarchyTest("A", "A", "A.java");
public void testDefaultConstructor() {
doCallerHierarchyTest("A", "A", "A.java");
}
public void testRecordCanonicalConstructor() throws Exception {
public void testRecordCanonicalConstructor() {
doHierarchyTest(() -> {
PsiClass aClass = JavaPsiFacade.getInstance(getProject()).findClass("Person", ProjectScope.getProjectScope(getProject()));
return new CallerMethodsTreeStructure(getProject(), aClass, HierarchyBrowserBaseEx.SCOPE_PROJECT);
}, JavaHierarchyUtil.getComparator(myProject), "Action.java");
}
public void testRecordCanonicalConstructorReverse() throws Exception {
public void testRecordCanonicalConstructorReverse() {
doHierarchyTest(() -> {
PsiClass aClass = JavaPsiFacade.getInstance(getProject()).findClass("Person", ProjectScope.getProjectScope(getProject()));
return new CalleeMethodsTreeStructure(getProject(), aClass, HierarchyBrowserBaseEx.SCOPE_PROJECT);
}, JavaHierarchyUtil.getComparator(myProject), "Action.java");
}
public void testRecordCanonicalConstructorReverse2() throws Exception {
public void testRecordCanonicalConstructorReverse2() {
doHierarchyTest(() -> {
PsiClass aClass = JavaPsiFacade.getInstance(getProject()).findClass("Value", ProjectScope.getProjectScope(getProject()));
return new CalleeMethodsTreeStructure(getProject(), aClass, HierarchyBrowserBaseEx.SCOPE_PROJECT);
}, JavaHierarchyUtil.getComparator(myProject), "Value.java");
}
public void testRecordComponent() throws Exception {
public void testRecordComponent() {
doHierarchyTest(() -> {
PsiClass aClass = JavaPsiFacade.getInstance(getProject()).findClass("Value", ProjectScope.getProjectScope(getProject()));
PsiRecordComponent component = aClass.getRecordComponents()[0];
@@ -121,11 +127,11 @@ public class JavaCallHierarchyTest extends HierarchyViewTestBase {
}, JavaHierarchyUtil.getComparator(myProject), "Value.java");
}
public void testMethodRef() throws Exception {
doJavaCalleeTypeHierarchyTest("A", "testMethod", "A.java");
public void testMethodRef() {
doCalleeHierarchyTest("A", "testMethod", "A.java");
}
public void testField() throws Exception {
public void testField() {
doHierarchyTest(() -> {
PsiClass psiClass = JavaPsiFacade.getInstance(getProject()).findClass("A", ProjectScope.getProjectScope(getProject()));
PsiField field = psiClass.findFieldByName("testField", false);
@@ -133,7 +139,7 @@ public class JavaCallHierarchyTest extends HierarchyViewTestBase {
}, JavaHierarchyUtil.getComparator(myProject),"A.java");
}
public void testStaticallyImportedField() throws Exception {
public void testStaticallyImportedField() {
doHierarchyTest(() -> {
PsiClass psiClass = JavaPsiFacade.getInstance(getProject()).findClass("java.util.Collections", ProjectScope.getAllScope(getProject()));
PsiMember field = psiClass.findFieldByName("EMPTY_LIST", false);
@@ -141,16 +147,16 @@ public class JavaCallHierarchyTest extends HierarchyViewTestBase {
}, JavaHierarchyUtil.getComparator(myProject), "A.java");
}
public void testAnonymous() throws Exception {
doJavaCallerTypeHierarchyTest("A", "A", "A.java"); // IDEA-56615
public void testAnonymous() {
doCallerHierarchyTest("A", "A", "A.java"); // IDEA-56615
}
public void testAnonymous2() throws Exception {
doJavaCallerTypeHierarchyTest("A", "doIt", "A.java");
public void testAnonymous2() {
doCallerHierarchyTest("A", "doIt", "A.java");
}
public void testAnonymous3() throws Exception {
doJavaCallerTypeHierarchyTest("B", "foo", "A.java"); // IDEA-140031
public void testAnonymous3() {
doCallerHierarchyTest("B", "foo", "A.java"); // IDEA-140031
}
public void testActionAvailableInXml() {
@@ -161,30 +167,25 @@ public class JavaCallHierarchyTest extends HierarchyViewTestBase {
assertTrue(e.getPresentation().isEnabledAndVisible());
}
@Override
protected Sdk getTestProjectJdk() {
return IdeaTestUtil.getMockJdk18();
public void testMustIgnoreJavadocReferences() {
doCallerHierarchyTest("p.X", "persist", "X.java");
}
public void testMustIgnoreJavadocReferences() throws Exception {
doJavaCallerTypeHierarchyTest("p.X", "persist", "X.java");
public void testCallersOfBaseMethod() {
doCallerHierarchyTest("p.BaseClass", "method", "X.java");
}
public void testCallersOfBaseMethod() throws Exception {
doJavaCallerTypeHierarchyTest("p.BaseClass", "method", "X.java");
public void testCallersOfSubMethod() {
doCallerHierarchyTest("p.BaseClass", "method", "X.java");
}
public void testCallersOfSubMethod() throws Exception {
doJavaCallerTypeHierarchyTest("p.BaseClass", "method", "X.java");
public void testEnclosingDeps() {
doCallerHierarchyTest("DummyImpl", "doSth", "A.java");
}
public void testEnclosingDeps() throws Exception {
doJavaCallerTypeHierarchyTest("DummyImpl", "doSth", "A.java");
public void testThroughAnonymous() {
doCallerHierarchyTest("com.hierarchytest.AcmClientImpl", "getUser", "X.java");
}
public void testThroughAnonymous() throws Exception {
doJavaCallerTypeHierarchyTest("com.hierarchytest.AcmClientImpl", "getUser", "X.java");
public void testThroughAnonymousCalledByOther() {
doCallerHierarchyTest("x.AcmClientImpl", "returnSomething", "X.java");
}
public void testThroughAnonymousCalledByOther() throws Exception {
doJavaCallerTypeHierarchyTest("x.AcmClientImpl", "returnSomething", "X.java");
}
public void testWildcards() throws Exception {
doJavaCallerTypeHierarchyTest("p.BoardImpl", "getCount", "A.java");
public void testWildcards() {
doCallerHierarchyTest("p.BoardImpl", "getCount", "A.java");
}
}
@@ -1,18 +1,4 @@
/*
* 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.
*/
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.ide.hierarchy;
import com.intellij.JavaTestUtil;
@@ -36,6 +22,11 @@ public class JavaMethodHierarchyTest extends HierarchyViewTestBase {
return LanguageLevel.JDK_1_8; // default methods are needed
}
@Override
protected Sdk getTestProjectJdk() {
return IdeaTestUtil.getMockJdk18();
}
@NotNull
@Override
protected String getTestDataPath() {
@@ -47,47 +38,47 @@ public class JavaMethodHierarchyTest extends HierarchyViewTestBase {
return "ide/hierarchy/method/" + getTestName(false);
}
public void testNoHierarchy() throws Exception {
public void testNoHierarchy() {
doTest("A", "foo", "A.java");
}
public void testOnlyUp() throws Exception {
public void testOnlyUp() {
doTest("Z", "m", "X.java");
}
public void testOnlyDown() throws Exception {
public void testOnlyDown() {
doTest("X", "m", "X.java");
}
public void testOnlyDownHide() throws Exception {
public void testOnlyDownHide() {
doTestHideIrrelevantClasses("foo.X", "m", "X.java");
}
public void testUpAndDown() throws Exception {
public void testUpAndDown() {
doTestHideIrrelevantClasses("Y", "foo", "X.java");
}
public void testObjectMethod() throws Exception {
public void testObjectMethod() {
doTest("Foo", "hashCode", "X.java");
}
public void testInterfaceInheritance() throws Exception {
public void testInterfaceInheritance() {
doTest("E", "bar", "X.java");
}
public void testCyclicInheritance() throws Exception {
public void testCyclicInheritance() {
doTest("D", "foo", "X.java");
}
public void testExtendsImplementsChain() throws Exception {
public void testExtendsImplementsChain() {
doTest("C", "foo", "X.java");
}
public void testTwoParentsPreferClass() throws Exception {
public void testTwoParentsPreferClass() {
doTest("C3", "m", "X.java");
}
private void doTest(final String classFqn, final String methodName, final String... fileNames) throws Exception {
private void doTest(final String classFqn, final String methodName, final String... fileNames) {
doHierarchyTest(() -> {
final PsiClass psiClass = JavaPsiFacade.getInstance(getProject()).findClass(classFqn, ProjectScope.getProjectScope(getProject()));
final PsiMethod method = psiClass.findMethodsByName(methodName, false) [0];
@@ -95,7 +86,7 @@ public class JavaMethodHierarchyTest extends HierarchyViewTestBase {
}, JavaHierarchyUtil.getComparator(myProject), fileNames);
}
private void doTestHideIrrelevantClasses(String classFqn, String methodName, String... fileNames) throws Exception {
private void doTestHideIrrelevantClasses(String classFqn, String methodName, String... fileNames) {
HierarchyBrowserManager.State state = HierarchyBrowserManager.getInstance(myProject).getState();
assertNotNull(state);
state.HIDE_CLASSES_WHERE_METHOD_NOT_IMPLEMENTED = true;
@@ -106,9 +97,4 @@ public class JavaMethodHierarchyTest extends HierarchyViewTestBase {
state.HIDE_CLASSES_WHERE_METHOD_NOT_IMPLEMENTED = false;
}
}
@Override
protected Sdk getTestProjectJdk() {
return IdeaTestUtil.getMockJdk18();
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 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.
*/
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.testFramework.codeInsight.hierarchy;
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase;
@@ -48,10 +34,15 @@ public abstract class HierarchyViewTestBase extends DaemonAnalyzerTestCase {
protected void doHierarchyTest(@NotNull Supplier<? extends HierarchyTreeStructure> treeStructure,
@Nullable Comparator<? super NodeDescriptor<?>> comparator,
String @NotNull ... fileNames) throws IOException {
String @NotNull ... fileNames) {
configure(fileNames);
String verificationFilePath = getTestDataPath() + "/" + getBasePath() + "/verification.xml";
HierarchyViewTestFixture.doHierarchyTest(treeStructure.get(), comparator, new File(verificationFilePath));
try {
HierarchyViewTestFixture.doHierarchyTest(treeStructure.get(), comparator, new File(verificationFilePath));
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
private void configure(String @NotNull [] fileNames) {