mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inspection view: fix the test + make it more stable
This commit is contained in:
+124
-115
@@ -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<String, Tools> 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" +
|
||||
" -<default>\n" +
|
||||
" -Test\n" +
|
||||
" -foo()\n" +
|
||||
" Variable <code>j</code> is never used.\n" +
|
||||
" -main(String[])\n" +
|
||||
" Variable <code>test</code> is never used.\n" +
|
||||
" -f()\n" +
|
||||
" -D\n" +
|
||||
" -b()\n" +
|
||||
" Variable <code>r</code> is never used.\n" +
|
||||
" -anonymous (Runnable)\n" +
|
||||
" -run()\n" +
|
||||
" Variable <code>i</code> is never used.\n" +
|
||||
" -ff()\n" +
|
||||
" Variable <code>a</code> is never used.\n" +
|
||||
" Variable <code>d</code> is never used.\n" +
|
||||
" -Probable bugs\n" +
|
||||
" -EqualsWithItself\n" +
|
||||
" -Module: 'testOfflineWithInvalid'\n" +
|
||||
" -<default>\n" +
|
||||
" -Test\n" +
|
||||
" -m()\n" +
|
||||
" 'equals()' called on itself\n" +
|
||||
" -null\n" +
|
||||
" Identical qualifier and argument to <code>equals()</code> call\n"
|
||||
" -Java\n" +
|
||||
" -Declaration redundancy\n" +
|
||||
" -unused\n" +
|
||||
" -Module: 'testOfflineWithInvalid'\n" +
|
||||
" -<default>\n" +
|
||||
" -Test\n" +
|
||||
" -foo()\n" +
|
||||
" Variable <code>j</code> is never used.\n" +
|
||||
" -main(String[])\n" +
|
||||
" Variable <code>test</code> is never used.\n" +
|
||||
" -f()\n" +
|
||||
" -D\n" +
|
||||
" -b()\n" +
|
||||
" Variable <code>r</code> is never used.\n" +
|
||||
" -anonymous (Runnable)\n" +
|
||||
" -run()\n" +
|
||||
" Variable <code>i</code> is never used.\n" +
|
||||
" -ff()\n" +
|
||||
" Variable <code>a</code> is never used.\n" +
|
||||
" Variable <code>d</code> is never used.\n" +
|
||||
" -Probable bugs\n" +
|
||||
" -EqualsWithItself\n" +
|
||||
" -Module: 'testOfflineWithInvalid'\n" +
|
||||
" -<default>\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" +
|
||||
" -<default>\n" +
|
||||
" -Test\n" +
|
||||
" -foo()\n" +
|
||||
" Variable <code>j</code> is never used.\n" +
|
||||
" -main(String[])\n" +
|
||||
" Variable <code>test</code> is never used.\n" +
|
||||
" -f()\n" +
|
||||
" -D\n" +
|
||||
" -b()\n" +
|
||||
" Variable <code>r</code> is never used.\n" +
|
||||
" -anonymous (Runnable)\n" +
|
||||
" -run()\n" +
|
||||
" Variable <code>i</code> is never used.\n" +
|
||||
" -ff()\n" +
|
||||
" Variable <code>a</code> is never used.\n" +
|
||||
" Variable <code>d</code> is never used.\n" +
|
||||
" -Probable bugs\n" +
|
||||
" -" + myDataFlowToolWrapper + "\n" +
|
||||
" -Module: 'testOfflineView'\n" +
|
||||
" -<default>\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" +
|
||||
" -<default>\n" +
|
||||
" -Test\n" +
|
||||
" -foo()\n" +
|
||||
" Variable <code>j</code> is never used.\n" +
|
||||
" -main(String[])\n" +
|
||||
" Variable <code>test</code> is never used.\n" +
|
||||
" -f()\n" +
|
||||
" -D\n" +
|
||||
" -b()\n" +
|
||||
" Variable <code>r</code> is never used.\n" +
|
||||
" -anonymous (Runnable)\n" +
|
||||
" -run()\n" +
|
||||
" Variable <code>i</code> is never used.\n" +
|
||||
" -ff()\n" +
|
||||
" Variable <code>a</code> is never used.\n" +
|
||||
" Variable <code>d</code> is never used.\n" +
|
||||
" -Probable bugs\n" +
|
||||
" -" + myDataFlowToolWrapper + "\n" +
|
||||
" -Module: 'testOfflineView'\n" +
|
||||
" -<default>\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 <code>j</code> is never used.\n" +
|
||||
" -main(String[])\n" +
|
||||
" Variable <code>test</code> is never used.\n" +
|
||||
" -f()\n" +
|
||||
" -D\n" +
|
||||
" -b()\n" +
|
||||
" Variable <code>r</code> is never used.\n" +
|
||||
" -anonymous (Runnable)\n" +
|
||||
" -run()\n" +
|
||||
" Variable <code>i</code> is never used.\n" +
|
||||
" -ff()\n" +
|
||||
" Variable <code>a</code> is never used.\n" +
|
||||
" Variable <code>d</code> 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 <code>j</code> is never used.\n" +
|
||||
" -main(String[])\n" +
|
||||
" Variable <code>test</code> is never used.\n" +
|
||||
" -f()\n" +
|
||||
" -D\n" +
|
||||
" -b()\n" +
|
||||
" Variable <code>r</code> is never used.\n" +
|
||||
" -anonymous (Runnable)\n" +
|
||||
" -run()\n" +
|
||||
" Variable <code>i</code> is never used.\n" +
|
||||
" -ff()\n" +
|
||||
" Variable <code>a</code> is never used.\n" +
|
||||
" Variable <code>d</code> 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 <code>j</code> is never used.\n" +
|
||||
" -main(String[])\n" +
|
||||
" Variable <code>test</code> is never used.\n" +
|
||||
" -f()\n" +
|
||||
" -D\n" +
|
||||
" -b()\n" +
|
||||
" Variable <code>r</code> is never used.\n" +
|
||||
" -anonymous (Runnable)\n" +
|
||||
" -run()\n" +
|
||||
" Variable <code>i</code> is never used.\n" +
|
||||
" -ff()\n" +
|
||||
" Variable <code>a</code> is never used.\n" +
|
||||
" Variable <code>d</code> 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 <code>j</code> is never used.\n" +
|
||||
" -main(String[])\n" +
|
||||
" Variable <code>test</code> is never used.\n" +
|
||||
" -f()\n" +
|
||||
" -D\n" +
|
||||
" -b()\n" +
|
||||
" Variable <code>r</code> is never used.\n" +
|
||||
" -anonymous (Runnable)\n" +
|
||||
" -run()\n" +
|
||||
" Variable <code>i</code> is never used.\n" +
|
||||
" -ff()\n" +
|
||||
" Variable <code>a</code> is never used.\n" +
|
||||
" Variable <code>d</code> is never used.\n" +
|
||||
" -Probable bugs\n" +
|
||||
" -EqualsWithItself\n" +
|
||||
" -Test2\n" +
|
||||
" 'equals()' called on itself\n" +
|
||||
" -Test\n" +
|
||||
" 'equals()' called on itself\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user