From e7f0e93efcd85d6ba8ff1914c1ce5a6cfa758c8f Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Mon, 30 Oct 2017 11:21:03 +0100 Subject: [PATCH] inspection view: fix the test + make it more stable --- .../OfflineInspectionResultViewTest.java | 239 +++++++++--------- 1 file changed, 124 insertions(+), 115 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/OfflineInspectionResultViewTest.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/OfflineInspectionResultViewTest.java index 38739a505cca..0b2b6314dfb3 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/OfflineInspectionResultViewTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/OfflineInspectionResultViewTest.java @@ -36,6 +36,7 @@ import com.intellij.psi.PsiElement; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.TestSourceBasedTestCase; import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.tree.TreeUtil; import com.siyeh.ig.bugs.EqualsWithItselfInspection; import gnu.trove.THashMap; @@ -50,12 +51,13 @@ import java.util.Set; public class OfflineInspectionResultViewTest extends TestSourceBasedTestCase { private InspectionResultsView myView; - private GlobalInspectionToolWrapper myUnusedToolWrapper; - private LocalInspectionToolWrapper myDataFlowToolWrapper; + private InspectionToolWrapper myUnusedToolWrapper; + private InspectionToolWrapper myDataFlowToolWrapper; @Override protected void setUp() throws Exception { super.setUp(); + InspectionProfileImpl.INIT_INSPECTIONS = true; HighlightDisplayKey key = HighlightDisplayKey.find(UnusedDeclarationInspectionBase.SHORT_NAME); if (key == null) { @@ -93,13 +95,11 @@ public class OfflineInspectionResultViewTest extends TestSourceBasedTestCase { }; myView = ViewOfflineResultsAction.showOfflineView(getProject(), parse(), profile, ""); - myUnusedToolWrapper = new GlobalInspectionToolWrapper(new UnusedDeclarationInspection()); - myDataFlowToolWrapper = new LocalInspectionToolWrapper(new EqualsWithItselfInspection()); + profile.initInspectionTools(myProject); + myUnusedToolWrapper = profile.getInspectionTool("unused", myProject); + myDataFlowToolWrapper = profile.getInspectionTool("EqualsWithItself", myProject); - final Map tools = myView.getGlobalInspectionContext().getTools(); for (InspectionToolWrapper tool : ContainerUtil.ar(myUnusedToolWrapper, myDataFlowToolWrapper)) { - profile.addTool(getProject(), tool, new THashMap<>()); - tools.put(tool.getShortName(), new ToolsImpl(tool, tool.getDefaultLevel(), true)); tool.initialize(myView.getGlobalInspectionContext()); } } @@ -108,8 +108,10 @@ public class OfflineInspectionResultViewTest extends TestSourceBasedTestCase { protected void tearDown() throws Exception { try { Disposer.dispose(myView); + } finally { + InspectionProfileImpl.INIT_INSPECTIONS = false; myView = null; myUnusedToolWrapper = null; myDataFlowToolWrapper = null; @@ -137,108 +139,114 @@ public class OfflineInspectionResultViewTest extends TestSourceBasedTestCase { return map; } - public void testOfflineWithInvalid() { + public void testOfflineWithInvalid() throws InterruptedException { ApplicationManager.getApplication().runWriteAction(() -> getJavaFacade().findClass("Test2").getContainingFile().delete()); myView.getGlobalInspectionContext().getUIOptions().SHOW_STRUCTURE = true; InspectionTree tree = updateTree(); + PlatformTestUtil.dispatchAllEventsInIdeEventQueue(); TreeUtil.expandAll(tree); PlatformTestUtil.assertTreeEqual(tree, "-" + getProject() + "\n" + - " -Declaration redundancy\n" + - " -unused\n" + - " -Module: 'testOfflineWithInvalid'\n" + - " -\n" + - " -Test\n" + - " -foo()\n" + - " Variable j is never used.\n" + - " -main(String[])\n" + - " Variable test is never used.\n" + - " -f()\n" + - " -D\n" + - " -b()\n" + - " Variable r is never used.\n" + - " -anonymous (Runnable)\n" + - " -run()\n" + - " Variable i is never used.\n" + - " -ff()\n" + - " Variable a is never used.\n" + - " Variable d is never used.\n" + - " -Probable bugs\n" + - " -EqualsWithItself\n" + - " -Module: 'testOfflineWithInvalid'\n" + - " -\n" + - " -Test\n" + - " -m()\n" + - " 'equals()' called on itself\n" + - " -null\n" + - " Identical qualifier and argument to equals() call\n" + " -Java\n" + + " -Declaration redundancy\n" + + " -unused\n" + + " -Module: 'testOfflineWithInvalid'\n" + + " -\n" + + " -Test\n" + + " -foo()\n" + + " Variable j is never used.\n" + + " -main(String[])\n" + + " Variable test is never used.\n" + + " -f()\n" + + " -D\n" + + " -b()\n" + + " Variable r is never used.\n" + + " -anonymous (Runnable)\n" + + " -run()\n" + + " Variable i is never used.\n" + + " -ff()\n" + + " Variable a is never used.\n" + + " Variable d is never used.\n" + + " -Probable bugs\n" + + " -EqualsWithItself\n" + + " -Module: 'testOfflineWithInvalid'\n" + + " -\n" + + " -Test\n" + + " -m()\n" + + " 'equals()' called on itself\n" + + " -null\n" + + " '()' called on itself\n" ); - tree.setSelectionRow(27); - final OfflineProblemDescriptorNode node = - (OfflineProblemDescriptorNode)tree.getSelectionModel().getSelectionPath().getLastPathComponent(); + tree.setSelectionRow(28); + final OfflineProblemDescriptorNode node = (OfflineProblemDescriptorNode)tree.getSelectionModel().getSelectionPath().getLastPathComponent(); assertFalse(node.isValid()); } - public void testOfflineView() { + public void testOfflineView() throws InterruptedException { myView.getGlobalInspectionContext().getUIOptions().SHOW_STRUCTURE = true; InspectionTree tree = updateTree(); + PlatformTestUtil.dispatchAllEventsInIdeEventQueue(); TreeUtil.expandAll(tree); PlatformTestUtil.assertTreeEqual(tree, "-" + getProject() + "\n" + - " -Declaration redundancy\n" + - " -unused\n" + - " -Module: 'testOfflineView'\n" + - " -\n" + - " -Test\n" + - " -foo()\n" + - " Variable j is never used.\n" + - " -main(String[])\n" + - " Variable test is never used.\n" + - " -f()\n" + - " -D\n" + - " -b()\n" + - " Variable r is never used.\n" + - " -anonymous (Runnable)\n" + - " -run()\n" + - " Variable i is never used.\n" + - " -ff()\n" + - " Variable a is never used.\n" + - " Variable d is never used.\n" + - " -Probable bugs\n" + - " -" + myDataFlowToolWrapper + "\n" + - " -Module: 'testOfflineView'\n" + - " -\n" + - " -Test\n" + - " -m()\n" + - " 'equals()' called on itself\n" + - " -Test2\n" + - " -m123()\n" + - " 'equals()' called on itself\n" + " -Java\n" + + " -Declaration redundancy\n" + + " -unused\n" + + " -Module: 'testOfflineView'\n" + + " -\n" + + " -Test\n" + + " -foo()\n" + + " Variable j is never used.\n" + + " -main(String[])\n" + + " Variable test is never used.\n" + + " -f()\n" + + " -D\n" + + " -b()\n" + + " Variable r is never used.\n" + + " -anonymous (Runnable)\n" + + " -run()\n" + + " Variable i is never used.\n" + + " -ff()\n" + + " Variable a is never used.\n" + + " Variable d is never used.\n" + + " -Probable bugs\n" + + " -" + myDataFlowToolWrapper + "\n" + + " -Module: 'testOfflineView'\n" + + " -\n" + + " -Test2\n" + + " -m123()\n" + + " 'equals()' called on itself\n" + + " -Test\n" + + " -m()\n" + + " 'equals()' called on itself\n" ); myView.getGlobalInspectionContext().getUIOptions().SHOW_STRUCTURE = false; tree = updateTree(); + PlatformTestUtil.dispatchAllEventsInIdeEventQueue(); + TreeUtil.expandAll(tree); PlatformTestUtil.assertTreeEqual(tree, "-" + getProject() + "\n" + - " -Declaration redundancy\n" + - " -unused\n" + - " -Test\n" + - " -foo()\n" + - " Variable j is never used.\n" + - " -main(String[])\n" + - " Variable test is never used.\n" + - " -f()\n" + - " -D\n" + - " -b()\n" + - " Variable r is never used.\n" + - " -anonymous (Runnable)\n" + - " -run()\n" + - " Variable i is never used.\n" + - " -ff()\n" + - " Variable a is never used.\n" + - " Variable d is never used.\n" + - " -Probable bugs\n" + - " -" + myDataFlowToolWrapper + "\n" + - " -Test\n" + - " 'equals()' called on itself\n" + - " -Test2\n" + - " 'equals()' called on itself\n" + " -Java\n" + + " -Declaration redundancy\n" + + " -unused\n" + + " -Test\n" + + " -foo()\n" + + " Variable j is never used.\n" + + " -main(String[])\n" + + " Variable test is never used.\n" + + " -f()\n" + + " -D\n" + + " -b()\n" + + " Variable r is never used.\n" + + " -anonymous (Runnable)\n" + + " -run()\n" + + " Variable i is never used.\n" + + " -ff()\n" + + " Variable a is never used.\n" + + " Variable d is never used.\n" + + " -Probable bugs\n" + + " -EqualsWithItself\n" + + " -Test2\n" + + " 'equals()' called on itself\n" + + " -Test\n" + + " 'equals()' called on itself\n" ); TreeUtil.selectNode(tree, tree.getRoot()); final InspectionTreeNode root = tree.getRoot(); @@ -253,29 +261,30 @@ public class OfflineInspectionResultViewTest extends TestSourceBasedTestCase { myView.getGlobalInspectionContext().getUIOptions().FILTER_RESOLVED_ITEMS = false; tree = updateTree(); PlatformTestUtil.assertTreeEqual(tree, "-" + getProject() + "\n" - + " -Declaration redundancy\n" - + " -unused\n" - + " -Test\n" + - " -foo()\n" + - " Variable j is never used.\n" + - " -main(String[])\n" + - " Variable test is never used.\n" + - " -f()\n" + - " -D\n" + - " -b()\n" + - " Variable r is never used.\n" + - " -anonymous (Runnable)\n" + - " -run()\n" + - " Variable i is never used.\n" + - " -ff()\n" + - " Variable a is never used.\n" + - " Variable d is never used.\n" + - " -Probable bugs\n" + - " -" + myDataFlowToolWrapper + "\n" + - " -Test\n" + - " 'equals()' called on itself\n" + - " -Test2\n" + - " 'equals()' called on itself\n" + + " -Java\n" + + " -Declaration redundancy\n" + + " -unused\n" + + " -Test\n" + + " -foo()\n" + + " Variable j is never used.\n" + + " -main(String[])\n" + + " Variable test is never used.\n" + + " -f()\n" + + " -D\n" + + " -b()\n" + + " Variable r is never used.\n" + + " -anonymous (Runnable)\n" + + " -run()\n" + + " Variable i is never used.\n" + + " -ff()\n" + + " Variable a is never used.\n" + + " Variable d is never used.\n" + + " -Probable bugs\n" + + " -EqualsWithItself\n" + + " -Test2\n" + + " 'equals()' called on itself\n" + + " -Test\n" + + " 'equals()' called on itself\n" ); }