From 33a50d905b6f5362133f11f5f476e797528e36d8 Mon Sep 17 00:00:00 2001 From: Sergey Ignatov Date: Fri, 28 Dec 2018 17:59:04 +0300 Subject: [PATCH] cleanup tests in com.intellij.usages --- .../usages/impl/UsageViewManagerTest.java | 5 +-- .../intellij/usages/impl/UsageViewTest.java | 40 ++++++++++--------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewManagerTest.java b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewManagerTest.java index 51e9f5784457..05f1c830a155 100644 --- a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewManagerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewManagerTest.java @@ -20,12 +20,11 @@ import com.intellij.find.impl.FindInProjectUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.search.GlobalSearchScopesCore; import com.intellij.psi.search.SearchScope; -import com.intellij.testFramework.PlatformTestCase; +import com.intellij.testFramework.LightPlatformTestCase; import com.intellij.usages.UsageTarget; import com.intellij.usages.UsageViewManager; -public class UsageViewManagerTest extends PlatformTestCase { - +public class UsageViewManagerTest extends LightPlatformTestCase { public void testScopeCreatedForFindInDirectory() { VirtualFile dir = getProject().getBaseDir(); FindModel findModel = new FindModel(); diff --git a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTest.java b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTest.java index 2b7956418320..ad05e957b980 100644 --- a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTest.java +++ b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTest.java @@ -60,7 +60,7 @@ public class UsageViewTest extends LightPlatformCodeInsightFixtureTestCase { PsiFile psiFile = myFixture.addFileToProject("X.java", text); Usage[] usages = new Usage[100]; for (int i = 0; i < usages.length; i++) { - usages[i] = createUsage(psiFile,i); + usages[i] = createUsage(psiFile, i); } UsageView usageView = createUsageView(usages); @@ -79,8 +79,6 @@ public class UsageViewTest extends LightPlatformCodeInsightFixtureTestCase { PsiFile psiFile = myFixture.addFileToProject("X.java", text); Usage usage = createUsage(psiFile, psiFile.getText().indexOf("xxx")); - UsageView usageView = createUsageView(usage); - PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject()); Document document = documentManager.getDocument(psiFile); WriteCommandAction.runWriteCommandAction(getProject(), () -> document.insertString(0, "/* sdfsdfsd */")); @@ -88,13 +86,13 @@ public class UsageViewTest extends LightPlatformCodeInsightFixtureTestCase { int navigationOffset = ((UsageInfo2UsageAdapter)usage).getUsageInfo().getNavigationOffset(); assertEquals(psiFile.getText().indexOf("xxx"), navigationOffset); } + public void testTextUsageInfoHandlesDocumentChange() { @Language("JAVA") String text = "public class X{ int xxx; } //comment"; PsiFile psiFile = myFixture.addFileToProject("X.java", text); - UsageInfo2UsageAdapter usage = new UsageInfo2UsageAdapter(new UsageInfo(psiFile, psiFile.getText().indexOf("xxx"), StringUtil.indexOfSubstringEnd(psiFile.getText(), "xxx"))); - - UsageView usageView = createUsageView(usage); + UsageInfo2UsageAdapter usage = new UsageInfo2UsageAdapter( + new UsageInfo(psiFile, psiFile.getText().indexOf("xxx"), StringUtil.indexOfSubstringEnd(psiFile.getText(), "xxx"))); PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject()); Document document = documentManager.getDocument(psiFile); @@ -113,14 +111,13 @@ public class UsageViewTest extends LightPlatformCodeInsightFixtureTestCase { public void testUsageViewCanRerunAfterTargetWasInvalidatedAndRestored() { @Language("JAVA") String fileText = "public class X{" + - " void foo() {\n" + - " bar();\n" + - " bar();\n" + - " }" + - " void bar() {}\n" + - "}"; + " void foo() {\n" + + " bar();\n" + + " bar();\n" + + " }" + + " void bar() {}\n" + + "}"; PsiFile psiFile = myFixture.addFileToProject("X.java", fileText); - Usage usage = createUsage(psiFile, psiFile.getText().indexOf("bar();")); PsiElement[] members = psiFile.getChildren()[psiFile.getChildren().length - 1].getChildren(); PsiNamedElement bar = (PsiNamedElement)members[members.length - 3]; @@ -129,7 +126,8 @@ public class UsageViewTest extends LightPlatformCodeInsightFixtureTestCase { FindUsagesManager usagesManager = ((FindManagerImpl)FindManager.getInstance(getProject())).getFindUsagesManager(); FindUsagesHandler handler = usagesManager.getNewFindUsagesHandler(bar, false); UsageViewImpl usageView = - (UsageViewImpl)usagesManager.doFindUsages(new PsiElement[]{bar}, PsiElement.EMPTY_ARRAY, handler, handler.getFindUsagesOptions(), false); + (UsageViewImpl)usagesManager + .doFindUsages(new PsiElement[]{bar}, PsiElement.EMPTY_ARRAY, handler, handler.getFindUsagesOptions(), false); waitForUsages(usageView); Disposer.register(myFixture.getTestRootDisposable(), usageView); @@ -161,7 +159,7 @@ public class UsageViewTest extends LightPlatformCodeInsightFixtureTestCase { } private void waitForUsages(UsageViewImpl usageView) { - ProgressManager.getInstance().run(new Task.Modal(getProject(), "waiting", false) { + ProgressManager.getInstance().run(new Task.Modal(getProject(), "Waiting", false) { @Override public void run(@NotNull ProgressIndicator indicator) { usageView.waitForUpdateRequestsCompletion(); @@ -174,7 +172,8 @@ public class UsageViewTest extends LightPlatformCodeInsightFixtureTestCase { @Language("JAVA") String fileText = "public class X{ int xxx; } //comment"; PsiFile psiFile = myFixture.addFileToProject("X.java", fileText); - Usage usage = new UsageInfo2UsageAdapter(new UsageInfo(psiFile, psiFile.getText().indexOf("xxx"), StringUtil.indexOfSubstringEnd(psiFile.getText(),"xxx"))); + Usage usage = new UsageInfo2UsageAdapter( + new UsageInfo(psiFile, psiFile.getText().indexOf("xxx"), StringUtil.indexOfSubstringEnd(psiFile.getText(), "xxx"))); UsageViewImpl usageView = createUsageView(usage); @@ -225,7 +224,8 @@ public class UsageViewTest extends LightPlatformCodeInsightFixtureTestCase { @NotNull private UsageViewImpl createUsageView(@NotNull Usage... usages) { UsageViewImpl usageView = - (UsageViewImpl)UsageViewManager.getInstance(getProject()).createUsageView(UsageTarget.EMPTY_ARRAY, usages, new UsageViewPresentation(), null); + (UsageViewImpl)UsageViewManager.getInstance(getProject()) + .createUsageView(UsageTarget.EMPTY_ARRAY, usages, new UsageViewPresentation(), null); Disposer.register(myFixture.getTestRootDisposable(), usageView); waitForUsages(usageView); UIUtil.dispatchAllInvocationEvents(); @@ -237,7 +237,8 @@ public class UsageViewTest extends LightPlatformCodeInsightFixtureTestCase { @Language("JAVA") String text = "public class X{ int xxx; } //comment"; PsiFile psiFile = myFixture.addFileToProject("X.java", text); - Usage usage = new UsageInfo2UsageAdapter(new UsageInfo(psiFile, psiFile.getText().indexOf("xxx"), StringUtil.indexOfSubstringEnd(psiFile.getText(),"xxx"))); + Usage usage = new UsageInfo2UsageAdapter( + new UsageInfo(psiFile, psiFile.getText().indexOf("xxx"), StringUtil.indexOfSubstringEnd(psiFile.getText(), "xxx"))); UsageViewImpl usageView = createUsageView(usage); @@ -290,7 +291,8 @@ public class UsageViewTest extends LightPlatformCodeInsightFixtureTestCase { throw new IllegalStateException("oh no"); }; BinaryFileTypeDecompilers.INSTANCE.addExplicitExtension(ArchiveFileType.INSTANCE, decompiler); - Disposer.register(getTestRootDisposable(), ()-> BinaryFileTypeDecompilers.INSTANCE.removeExplicitExtension(ArchiveFileType.INSTANCE, decompiler)); + Disposer.register(getTestRootDisposable(), + () -> BinaryFileTypeDecompilers.INSTANCE.removeExplicitExtension(ArchiveFileType.INSTANCE, decompiler)); PsiFile psiFile = myFixture.addFileToProject("X.jar", "xxx"); assertEquals(ArchiveFileType.INSTANCE, psiFile.getFileType());