From e9cff3106cee0b1c0a84fe83228f98c65d10bd3f Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 18 Jul 2016 16:57:35 +0200 Subject: [PATCH] since we use Java8, ThrowableRunnable is enough --- .../completion/TemplatesCompletionTest.java | 23 +- .../intellij/compiler/CompilerTestUtil.java | 52 ++--- .../intellij/execution/ExecutionTestCase.java | 14 +- .../testFramework/CompilerTester.java | 38 ++- .../impl/JavaCodeInsightTestFixtureImpl.java | 9 +- .../test/ExternalSystemTestCase.java | 39 ++-- .../IndentingBackspaceHandlerTest.java | 6 +- .../ExternalChangesAndRefreshingTest.java | 6 +- .../actions/EditorMultiCaretActionTest.java | 9 +- .../editor/actions/MatchBraceTest.java | 18 +- .../com/intellij/testFramework/EdtTestUtil.kt | 8 +- .../testFramework/LightPlatformTestCase.java | 6 +- .../intellij/testFramework/PsiTestUtil.java | 3 +- .../testFramework/UsefulTestCase.java | 18 +- .../fixtures/CompletionAutoPopupTester.groovy | 7 +- .../fixtures/impl/BaseFixture.java | 9 +- .../impl/CodeInsightTestFixtureImpl.java | 117 +++++----- .../impl/HeavyIdeaTestFixtureImpl.java | 34 +-- .../intellij/usages/impl/UsageViewImpl.java | 2 +- .../vcs/AbstractVcsTestCase.java | 9 +- .../intellij/vcs/VcsDirtyScopeManagerTest.kt | 9 +- .../push/GitPushResultNotificationTest.java | 27 +-- .../repo/GitRepositoryReaderTest.java | 25 +- .../groovy/compiler/DebuggerMethods.groovy | 6 +- .../groovy/compiler/GroovyDebuggerTest.groovy | 12 +- .../test/merge/HgMergeProviderTest.java | 5 +- .../idea/svn/SvnAuthenticationTest.java | 221 +++++++++--------- .../idea/svn16/SvnAuthenticationTest.java | 20 +- .../actions/RerunFailedActionsTestTools.java | 23 +- .../env/PyAbstractTestProcessRunner.java | 17 +- .../env/python/PyDynamicTypesTest.java | 5 +- .../env/python/PythonSkeletonsTest.java | 30 ++- .../python/testing/PythonUnitTestingTest.java | 20 +- .../python/sdkTools/PyTestSdkTools.java | 35 ++- 34 files changed, 427 insertions(+), 455 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/completion/TemplatesCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/completion/TemplatesCompletionTest.java index 09fd1f965be4..2873d7149ba1 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/completion/TemplatesCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/completion/TemplatesCompletionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -24,12 +24,11 @@ import com.intellij.codeInsight.template.impl.LiveTemplateCompletionContributor; import com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesSettings; import com.intellij.codeInsight.template.postfix.templates.*; import com.intellij.lang.java.JavaLanguage; +import com.intellij.testFramework.EdtTestUtil; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Set; - public class TemplatesCompletionTest extends CompletionAutoPopupTestCase { @Override public void setUp() { @@ -39,12 +38,16 @@ public class TemplatesCompletionTest extends CompletionAutoPopupTestCase { @Override public void tearDown() throws Exception { - PostfixTemplatesSettings settings = PostfixTemplatesSettings.getInstance(); - assertNotNull(settings); - settings.setLangDisabledTemplates(ContainerUtil.>newHashMap()); - settings.setPostfixTemplatesEnabled(true); - settings.setTemplatesCompletionEnabled(true); - super.tearDown(); + try { + PostfixTemplatesSettings settings = PostfixTemplatesSettings.getInstance(); + assertNotNull(settings); + settings.setLangDisabledTemplates(ContainerUtil.newHashMap()); + settings.setPostfixTemplatesEnabled(true); + settings.setTemplatesCompletionEnabled(true); + } + finally { + super.tearDown(); + } } public void testSimpleCompletionList() { @@ -237,7 +240,7 @@ public class TemplatesCompletionTest extends CompletionAutoPopupTestCase { } private void configureByFile() { - edt(() -> myFixture.configureByFile(getTestName(true) + ".java")); + EdtTestUtil.runInEdtAndWait(() -> myFixture.configureByFile(getTestName(true) + ".java")); } private void checkResultByFile() { diff --git a/java/testFramework/src/com/intellij/compiler/CompilerTestUtil.java b/java/testFramework/src/com/intellij/compiler/CompilerTestUtil.java index ae877d313a88..7f6e34084a89 100644 --- a/java/testFramework/src/com/intellij/compiler/CompilerTestUtil.java +++ b/java/testFramework/src/com/intellij/compiler/CompilerTestUtil.java @@ -31,7 +31,6 @@ import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.roots.ModuleRootModificationUtil; import com.intellij.testFramework.EdtTestUtil; import com.intellij.util.SmartList; -import com.intellij.util.ThrowableRunnable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.TestOnly; @@ -52,23 +51,15 @@ public class CompilerTestUtil { @TestOnly public static void saveApplicationSettings() { - EdtTestUtil.runInEdtAndWait(new Runnable() { - @Override - public void run() { - doSaveComponent(ProjectJdkTable.getInstance()); - doSaveComponent(FileTypeManager.getInstance()); - } + EdtTestUtil.runInEdtAndWait(() -> { + doSaveComponent(ProjectJdkTable.getInstance()); + doSaveComponent(FileTypeManager.getInstance()); }); } @TestOnly public static void saveApplicationComponent(final Object appComponent) { - EdtTestUtil.runInEdtAndWait(new Runnable() { - @Override - public void run() { - doSaveComponent(appComponent); - } - }); + EdtTestUtil.runInEdtAndWait(() -> doSaveComponent(appComponent)); } private static void doSaveComponent(Object appComponent) { @@ -89,26 +80,23 @@ public class CompilerTestUtil { @TestOnly public static void disableExternalCompiler(@NotNull final Project project) { - EdtTestUtil.runInEdtAndWait(new ThrowableRunnable() { - @Override - public void run() throws Throwable { - final JavaAwareProjectJdkTableImpl table = JavaAwareProjectJdkTableImpl.getInstanceEx(); - ApplicationManager.getApplication().runWriteAction(() -> { - Sdk internalJdk = table.getInternalJdk(); - List modulesToRestore = new SmartList(); - for (Module module : ModuleManager.getInstance(project).getModules()) { - Sdk sdk = ModuleRootManager.getInstance(module).getSdk(); - if (sdk != null && sdk.equals(internalJdk)) { - modulesToRestore.add(module); - } + EdtTestUtil.runInEdtAndWait(() -> { + final JavaAwareProjectJdkTableImpl table = JavaAwareProjectJdkTableImpl.getInstanceEx(); + ApplicationManager.getApplication().runWriteAction(() -> { + Sdk internalJdk = table.getInternalJdk(); + List modulesToRestore = new SmartList<>(); + for (Module module : ModuleManager.getInstance(project).getModules()) { + Sdk sdk = ModuleRootManager.getInstance(module).getSdk(); + if (sdk != null && sdk.equals(internalJdk)) { + modulesToRestore.add(module); } - table.removeJdk(internalJdk); - for (Module module : modulesToRestore) { - ModuleRootModificationUtil.setModuleSdk(module, internalJdk); - } - BuildManager.getInstance().clearState(project); - }); - } + } + table.removeJdk(internalJdk); + for (Module module : modulesToRestore) { + ModuleRootModificationUtil.setModuleSdk(module, internalJdk); + } + BuildManager.getInstance().clearState(project); + }); }); } } diff --git a/java/testFramework/src/com/intellij/execution/ExecutionTestCase.java b/java/testFramework/src/com/intellij/execution/ExecutionTestCase.java index 9d1dcffb4425..5284c0edeb01 100644 --- a/java/testFramework/src/com/intellij/execution/ExecutionTestCase.java +++ b/java/testFramework/src/com/intellij/execution/ExecutionTestCase.java @@ -69,12 +69,7 @@ public abstract class ExecutionTestCase extends IdeaTestCase { } myModuleOutputDir = new File(ourOutputRoot, PathUtil.getFileName(getTestAppPath())); myChecker = initOutputChecker(); - EdtTestUtil.runInEdtAndWait(new ThrowableRunnable() { - @Override - public void run() throws Throwable { - ExecutionTestCase.super.setUp(); - } - }); + EdtTestUtil.runInEdtAndWait(() -> super.setUp()); if (!myModuleOutputDir.exists()) { VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ourOutputRoot); assertNotNull(ourOutputRoot.getAbsolutePath(), vDir); @@ -138,12 +133,7 @@ public abstract class ExecutionTestCase extends IdeaTestCase { if (myCompilerTester != null) { myCompilerTester.tearDown(); } - EdtTestUtil.runInEdtAndWait(new ThrowableRunnable() { - @Override - public void run() throws Throwable { - ExecutionTestCase.super.tearDown(); - } - }); + EdtTestUtil.runInEdtAndWait(() -> super.tearDown()); //myChecker.checkValid(getTestProjectJdk()); //probably some thread is destroyed right now because of log exception //wait a little bit diff --git a/java/testFramework/src/com/intellij/testFramework/CompilerTester.java b/java/testFramework/src/com/intellij/testFramework/CompilerTester.java index 7cb72cd2f9c1..fcf806ad4df4 100644 --- a/java/testFramework/src/com/intellij/testFramework/CompilerTester.java +++ b/java/testFramework/src/com/intellij/testFramework/CompilerTester.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -39,7 +39,6 @@ import com.intellij.testFramework.fixtures.TempDirTestFixture; import com.intellij.testFramework.fixtures.impl.TempDirTestFixtureImpl; import com.intellij.util.Consumer; import com.intellij.util.ObjectUtils; -import com.intellij.util.ThrowableRunnable; import com.intellij.util.concurrency.Semaphore; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; @@ -180,25 +179,22 @@ public class CompilerTester { semaphore.down(); final ErrorReportingCallback callback = new ErrorReportingCallback(semaphore); - EdtTestUtil.runInEdtAndWait(new ThrowableRunnable() { - @Override - public void run() throws Throwable { - refreshVfs(getProject().getProjectFilePath()); - for (Module module : myModules) { - refreshVfs(module.getModuleFilePath()); - } - - PlatformTestUtil.saveProject(getProject()); - CompilerTestUtil.saveApplicationSettings(); - for (Module module : myModules) { - File ioFile = new File(module.getModuleFilePath()); - if (!ioFile.exists()) { - getProject().save(); - assert ioFile.exists() : "File does not exist: " + ioFile.getPath(); - } - } - runnable.consume(callback); + EdtTestUtil.runInEdtAndWait(() -> { + refreshVfs(getProject().getProjectFilePath()); + for (Module module : myModules) { + refreshVfs(module.getModuleFilePath()); } + + PlatformTestUtil.saveProject(getProject()); + CompilerTestUtil.saveApplicationSettings(); + for (Module module : myModules) { + File ioFile = new File(module.getModuleFilePath()); + if (!ioFile.exists()) { + getProject().save(); + assert ioFile.exists() : "File does not exist: " + ioFile.getPath(); + } + } + runnable.consume(callback); }); //tests run in awt @@ -223,7 +219,7 @@ public class CompilerTester { private static class ErrorReportingCallback implements CompileStatusNotification { private final Semaphore mySemaphore; private Throwable myError; - private final List myMessages = new ArrayList(); + private final List myMessages = new ArrayList<>(); public ErrorReportingCallback(Semaphore semaphore) { mySemaphore = semaphore; diff --git a/java/testFramework/src/com/intellij/testFramework/fixtures/impl/JavaCodeInsightTestFixtureImpl.java b/java/testFramework/src/com/intellij/testFramework/fixtures/impl/JavaCodeInsightTestFixtureImpl.java index 165b1c41d769..e4db88a35db4 100644 --- a/java/testFramework/src/com/intellij/testFramework/fixtures/impl/JavaCodeInsightTestFixtureImpl.java +++ b/java/testFramework/src/com/intellij/testFramework/fixtures/impl/JavaCodeInsightTestFixtureImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -92,11 +92,8 @@ public class JavaCodeInsightTestFixtureImpl extends CodeInsightTestFixtureImpl i @Override public void tearDown() throws Exception { try { - EdtTestUtil.runInEdtAndWait(new Runnable() { - @Override - public void run() { - ((PsiModificationTrackerImpl)getPsiManager().getModificationTracker()).incCounter();// drop all caches - } + EdtTestUtil.runInEdtAndWait(() -> { + ((PsiModificationTrackerImpl)getPsiManager().getModificationTracker()).incCounter();// drop all caches }); } finally { diff --git a/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/test/ExternalSystemTestCase.java b/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/test/ExternalSystemTestCase.java index a350ed139d67..31d282afc691 100644 --- a/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/test/ExternalSystemTestCase.java +++ b/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/test/ExternalSystemTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -46,8 +46,6 @@ import com.intellij.testFramework.*; import com.intellij.testFramework.fixtures.IdeaProjectTestFixture; import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory; import com.intellij.util.ArrayUtil; -import com.intellij.util.Processor; -import com.intellij.util.ThrowableRunnable; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.io.TestFileSystemItem; import gnu.trove.THashSet; @@ -83,9 +81,9 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase { protected File myTestDir; protected VirtualFile myProjectRoot; protected VirtualFile myProjectConfig; - protected List myAllConfigs = new ArrayList(); + protected List myAllConfigs = new ArrayList<>(); - private List myAllowedRoots = new ArrayList(); + private List myAllowedRoots = new ArrayList<>(); @Before @Override @@ -99,7 +97,7 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase { setUpFixtures(); myProject = myTestFixture.getProject(); - edt(() -> ApplicationManager.getApplication().runWriteAction(() -> { + EdtTestUtil.runInEdtAndWait(() -> ApplicationManager.getApplication().runWriteAction(() -> { try { setUpInWriteAction(); } @@ -114,7 +112,7 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase { } })); - List allowedRoots = new ArrayList(); + List allowedRoots = new ArrayList<>(); collectAllowedRoots(allowedRoots); if (!allowedRoots.isEmpty()) { VfsRootAccess.allowRootAccess(getTestRootDisposable(), ArrayUtil.toStringArray(allowedRoots)); @@ -169,12 +167,9 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase { @Override public void tearDown() throws Exception { try { - EdtTestUtil.runInEdtAndWait(new ThrowableRunnable() { - @Override - public void run() throws Throwable { - CompilerTestUtil.disableExternalCompiler(myProject); - tearDownFixtures(); - } + EdtTestUtil.runInEdtAndWait(() -> { + CompilerTestUtil.disableExternalCompiler(myProject); + tearDownFixtures(); }); myProject = null; if (!FileUtil.delete(myTestDir) && myTestDir.exists()) { @@ -242,7 +237,7 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase { }.executeSilently().throwException(); } else { - ExternalSystemTestCase.super.runTest(); + super.runTest(); } } catch (Exception throwable) { @@ -442,7 +437,7 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase { private CompileScope createModulesCompileScope(final String[] moduleNames) { - final List modules = new ArrayList(); + final List modules = new ArrayList<>(); for (String name : moduleNames) { modules.add(getModule(name)); } @@ -450,7 +445,7 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase { } private CompileScope createArtifactsScope(String[] artifactNames) { - List artifacts = new ArrayList(); + List artifacts = new ArrayList<>(); for (String name : artifactNames) { artifacts.add(ArtifactsTestUtil.findArtifact(myProject, name)); } @@ -522,11 +517,11 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase { } protected static void assertUnorderedElementsAreEqual(Collection actual, Collection expected) { - assertEquals(new HashSet(expected), new HashSet(actual)); + assertEquals(new HashSet<>(expected), new HashSet<>(actual)); } protected static void assertUnorderedPathsAreEqual(Collection actual, Collection expected) { - assertEquals(new SetWithToString(new THashSet(expected, FileUtil.PATH_HASHING_STRATEGY)), - new SetWithToString(new THashSet(actual, FileUtil.PATH_HASHING_STRATEGY))); + assertEquals(new SetWithToString<>(new THashSet<>(expected, FileUtil.PATH_HASHING_STRATEGY)), + new SetWithToString<>(new THashSet<>(actual, FileUtil.PATH_HASHING_STRATEGY))); } protected static void assertUnorderedElementsAreEqual(T[] actual, T... expected) { @@ -538,10 +533,10 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase { } protected static void assertOrderedElementsAreEqual(Collection actual, T... expected) { - String s = "\nexpected: " + Arrays.asList(expected) + "\nactual: " + new ArrayList(actual); + String s = "\nexpected: " + Arrays.asList(expected) + "\nactual: " + new ArrayList<>(actual); assertEquals(s, expected.length, actual.size()); - java.util.List actualList = new ArrayList(actual); + java.util.List actualList = new ArrayList<>(actual); for (int i = 0; i < expected.length; i++) { T expectedElement = expected[i]; U actualElement = actualList.get(i); @@ -555,7 +550,7 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase { } protected static void assertDoNotContain(java.util.List actual, T... expected) { - java.util.List actualCopy = new ArrayList(actual); + java.util.List actualCopy = new ArrayList<>(actual); actualCopy.removeAll(Arrays.asList(expected)); assertEquals(actual.toString(), actualCopy.size(), actual.size()); } diff --git a/platform/lang-impl/testSources/com/intellij/codeInsight/editorActions/IndentingBackspaceHandlerTest.java b/platform/lang-impl/testSources/com/intellij/codeInsight/editorActions/IndentingBackspaceHandlerTest.java index 79f648f0d4c2..65080bc9222e 100644 --- a/platform/lang-impl/testSources/com/intellij/codeInsight/editorActions/IndentingBackspaceHandlerTest.java +++ b/platform/lang-impl/testSources/com/intellij/codeInsight/editorActions/IndentingBackspaceHandlerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -22,13 +22,15 @@ import org.jetbrains.annotations.Nullable; import org.junit.Test; import org.junit.runner.RunWith; +import static com.intellij.testFramework.EdtTestUtil.runInEdtAndWait; + @SuppressWarnings("JUnit4AnnotatedMethodInJUnit3TestCase") @RunWith(com.intellij.testFramework.Parameterized.class) @TestDataPath("/testData/../../../platform/lang-impl/testData/editor/indentingBackspace/") public class IndentingBackspaceHandlerTest extends LightPlatformCodeInsightTestCase implements FileBasedTestCaseHelper { @Test public void testAction() { - edt(() -> { + runInEdtAndWait(() -> { configureByFile(myFileSuffix); backspace(); checkResultByFile(myFileSuffix.replace(".", "-after.")); diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/ExternalChangesAndRefreshingTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/ExternalChangesAndRefreshingTest.java index 006ef34a0660..05a11753328d 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/ExternalChangesAndRefreshingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/ExternalChangesAndRefreshingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -44,7 +44,7 @@ public class ExternalChangesAndRefreshingTest extends IntegrationTestCase { // this methods waits for another thread to finish, that leads // to deadlock in swing-thread. Therefore we have to run this test // outside of swing-thread - EdtTestUtil.runInEdtAndWait((ThrowableRunnable)ExternalChangesAndRefreshingTest.super::setUp); + EdtTestUtil.runInEdtAndWait(ExternalChangesAndRefreshingTest.super::setUp); } else { super.setUp(); @@ -57,7 +57,7 @@ public class ExternalChangesAndRefreshingTest extends IntegrationTestCase { // this methods waits for another thread to finish, that leads // to deadlock in swing-thread. Therefore we have to run this test // outside of swing-thread - EdtTestUtil.runInEdtAndWait((ThrowableRunnable)ExternalChangesAndRefreshingTest.super::tearDown); + EdtTestUtil.runInEdtAndWait(ExternalChangesAndRefreshingTest.super::tearDown); } else { //noinspection SuperTearDownInFinally diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/EditorMultiCaretActionTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/EditorMultiCaretActionTest.java index 6ee9d7faefd8..21f42d761aab 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/EditorMultiCaretActionTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/EditorMultiCaretActionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -15,10 +15,7 @@ */ package com.intellij.openapi.editor.actions; -import com.intellij.testFramework.EditorTestUtil; -import com.intellij.testFramework.FileBasedTestCaseHelper; -import com.intellij.testFramework.LightPlatformCodeInsightTestCase; -import com.intellij.testFramework.TestDataPath; +import com.intellij.testFramework.*; import org.jetbrains.annotations.Nullable; import org.junit.Test; import org.junit.runner.RunWith; @@ -29,7 +26,7 @@ import org.junit.runner.RunWith; public class EditorMultiCaretActionTest extends LightPlatformCodeInsightTestCase implements FileBasedTestCaseHelper { @Test public void testAction() { - edt(() -> { + EdtTestUtil.runInEdtAndWait(() -> { configureByFile(getBeforeFileName()); EditorTestUtil.setEditorVisibleSize(myEditor, 120, 20); // some actions require visible area to be defined, like EditorPageUp executeAction(getActionName()); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/MatchBraceTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/MatchBraceTest.java index 0a377cb31c23..fdb49a9db000 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/MatchBraceTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/MatchBraceTest.java @@ -1,5 +1,21 @@ +/* + * 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. + */ package com.intellij.openapi.editor.actions; +import com.intellij.testFramework.EdtTestUtil; import com.intellij.testFramework.FileBasedTestCaseHelper; import com.intellij.testFramework.LightPlatformCodeInsightTestCase; import com.intellij.testFramework.TestDataPath; @@ -16,7 +32,7 @@ import org.junit.runner.RunWith; public class MatchBraceTest extends LightPlatformCodeInsightTestCase implements FileBasedTestCaseHelper { @Test public void testAction() { - edt(() -> { + EdtTestUtil.runInEdtAndWait(() -> { configureByFile(getBeforeFileName()); //EditorTestUtil.setEditorVisibleSize(myEditor, 120, 20); // some actions require visible area to be defined, like EditorPageUp executeAction("EditorMatchBrace"); diff --git a/platform/testFramework/src/com/intellij/testFramework/EdtTestUtil.kt b/platform/testFramework/src/com/intellij/testFramework/EdtTestUtil.kt index 6944559a04a5..f310be64142b 100644 --- a/platform/testFramework/src/com/intellij/testFramework/EdtTestUtil.kt +++ b/platform/testFramework/src/com/intellij/testFramework/EdtTestUtil.kt @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -25,11 +25,7 @@ import javax.swing.SwingUtilities class EdtTestUtil { companion object { - @TestOnly @JvmStatic fun runInEdtAndWait(runnable: ThrowableRunnable) { - runInEdtAndWait { runnable.run() } - } - - @TestOnly @JvmStatic fun runInEdtAndWait(runnable: Runnable) { + @JvmStatic fun runInEdtAndWait(runnable: ThrowableRunnable) { runInEdtAndWait { runnable.run() } } } diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index 3ca59f8a8ac1..7e08e27fd97a 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -269,7 +269,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da @Override protected void setUp() throws Exception { - EdtTestUtil.runInEdtAndWait((ThrowableRunnable)() -> { + EdtTestUtil.runInEdtAndWait(() -> { super.setUp(); initApplication(); ApplicationInfoImpl.setInPerformanceTest(isPerformanceTest()); @@ -478,7 +478,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da ((HintManagerImpl)HintManager.getInstance()).cleanup(); DocumentCommitThread.getInstance().clearQueue(); - EdtTestUtil.runInEdtAndWait((Runnable)() -> { + EdtTestUtil.runInEdtAndWait(() -> { ((UndoManagerImpl)UndoManager.getGlobalInstance()).dropHistoryInTests(); ((UndoManagerImpl)UndoManager.getInstance(project)).dropHistoryInTests(); @@ -554,7 +554,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da } TestRunnerUtil.replaceIdeEventQueueSafely(); - EdtTestUtil.runInEdtAndWait((ThrowableRunnable)() -> { + EdtTestUtil.runInEdtAndWait(() -> { try { ourTestThread = Thread.currentThread(); startRunAndTear(); diff --git a/platform/testFramework/src/com/intellij/testFramework/PsiTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PsiTestUtil.java index e7635a6d6765..459521380692 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PsiTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PsiTestUtil.java @@ -38,7 +38,6 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFileFactory; import com.intellij.psi.impl.DebugUtil; import com.intellij.util.IncorrectOperationException; -import com.intellij.util.ThrowableRunnable; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -92,7 +91,7 @@ public class PsiTestUtil { assert vDir != null && vDir.isDirectory() : dir; PlatformTestCase.synchronizeTempDirVfs(vDir); - EdtTestUtil.runInEdtAndWait((ThrowableRunnable)() -> { + EdtTestUtil.runInEdtAndWait(() -> { AccessToken token = WriteAction.start(); try { if (rootPath != null) { diff --git a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java index 273b0ce1f9b4..77e27365c04d 100644 --- a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java @@ -347,12 +347,11 @@ public abstract class UsefulTestCase extends TestCase { return PlatformTestUtil.canRunTest(getClass()); } - public static void edt(@NotNull Runnable r) { - EdtTestUtil.runInEdtAndWait(r); - } - protected void invokeTestRunnable(@NotNull Runnable runnable) throws Exception { - EdtTestUtil.runInEdtAndWait(runnable); + EdtTestUtilKt.runInEdtAndWait(() -> { + runnable.run(); + return null; + }); } protected void defaultRunBare() throws Throwable { @@ -418,7 +417,7 @@ public abstract class UsefulTestCase extends TestCase { if (runInDispatchThread()) { TestRunnerUtil.replaceIdeEventQueueSafely(); - EdtTestUtil.runInEdtAndWait((ThrowableRunnable)this::defaultRunBare); + EdtTestUtil.runInEdtAndWait(this::defaultRunBare); } else { defaultRunBare(); @@ -568,12 +567,7 @@ public abstract class UsefulTestCase extends TestCase { @NotNull public static String toString(@NotNull Collection collection, @NotNull String separator) { - List list = ContainerUtil.map2List(collection, new Function() { - @Override - public String fun(final Object o) { - return String.valueOf(o); - } - }); + List list = ContainerUtil.map2List(collection, String::valueOf); Collections.sort(list); StringBuilder builder = new StringBuilder(); boolean flag = false; diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/CompletionAutoPopupTester.groovy b/platform/testFramework/src/com/intellij/testFramework/fixtures/CompletionAutoPopupTester.groovy index 2eec6c3603ff..df4fd165fc35 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/CompletionAutoPopupTester.groovy +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/CompletionAutoPopupTester.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * 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. @@ -24,6 +24,7 @@ import com.intellij.openapi.editor.ex.DocumentEx import com.intellij.openapi.util.SystemInfo import com.intellij.openapi.util.io.FileUtil import com.intellij.psi.PsiDocumentManager +import com.intellij.testFramework.EdtTestUtil import com.intellij.testFramework.UsefulTestCase import com.intellij.util.ui.UIUtil import groovy.transform.CompileStatic @@ -63,7 +64,7 @@ class CompletionAutoPopupTester { private static void waitPhase(Closure condition) { for (j in 1..1000) { def phase = null - UsefulTestCase.edt { phase = CompletionServiceImpl.completionPhase } + EdtTestUtil.runInEdtAndWait { phase = CompletionServiceImpl.completionPhase } if (condition(phase)) { return } @@ -108,7 +109,7 @@ class CompletionAutoPopupTester { return "Closure "+closureSeq; } }; - UsefulTestCase.edt { + EdtTestUtil.runInEdtAndWait { executed = PsiDocumentManager.getInstance(myFixture.project).performWhenAllCommitted(r); } assert !ApplicationManager.getApplication().isWriteAccessAllowed() diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/BaseFixture.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/BaseFixture.java index 92be1317eb3a..dad0cd85dd51 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/BaseFixture.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/BaseFixture.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -41,12 +41,7 @@ public class BaseFixture implements IdeaTestFixture { public void tearDown() throws Exception { Assert.assertTrue("setUp() has not been called", myInitialized); Assert.assertFalse("tearDown() already has been called", myDisposed); - EdtTestUtil.runInEdtAndWait(new Runnable() { - @Override - public void run() { - Disposer.dispose(myTestRootDisposable); - } - }); + EdtTestUtil.runInEdtAndWait(() -> Disposer.dispose(myTestRootDisposable)); myDisposed = true; resetClassFields(getClass()); } diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index 4423c4b3bdc8..3d44d496a39c 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -1264,54 +1264,48 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig super.setUp(); TestRunnerUtil.replaceIdeEventQueueSafely(); - EdtTestUtil.runInEdtAndWait(new ThrowableRunnable() { - @Override - public void run() throws Throwable { - myProjectFixture.setUp(); - myTempDirFixture.setUp(); + EdtTestUtil.runInEdtAndWait(() -> { + myProjectFixture.setUp(); + myTempDirFixture.setUp(); - VirtualFile tempDir = myTempDirFixture.getFile(""); - PlatformTestCase.synchronizeTempDirVfs(tempDir); + VirtualFile tempDir = myTempDirFixture.getFile(""); + PlatformTestCase.synchronizeTempDirVfs(tempDir); - myPsiManager = (PsiManagerImpl)PsiManager.getInstance(getProject()); - configureInspections(LocalInspectionTool.EMPTY_ARRAY, getProject(), Collections.emptyList(), getTestRootDisposable()); + myPsiManager = (PsiManagerImpl)PsiManager.getInstance(getProject()); + configureInspections(LocalInspectionTool.EMPTY_ARRAY, getProject(), Collections.emptyList(), getTestRootDisposable()); - DaemonCodeAnalyzerImpl daemonCodeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject()); - daemonCodeAnalyzer.prepareForTest(); + DaemonCodeAnalyzerImpl daemonCodeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject()); + daemonCodeAnalyzer.prepareForTest(); - DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false); - ensureIndexesUpToDate(getProject()); - ((StartupManagerImpl)StartupManagerEx.getInstanceEx(getProject())).runPostStartupActivities(); - } + DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false); + ensureIndexesUpToDate(getProject()); + ((StartupManagerImpl)StartupManagerEx.getInstanceEx(getProject())).runPostStartupActivities(); }); } @Override public void tearDown() throws Exception { try { - EdtTestUtil.runInEdtAndWait(new ThrowableRunnable() { - @Override - public void run() throws Throwable { + EdtTestUtil.runInEdtAndWait(() -> { + try { + DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true); // return default value to avoid unnecessary save + FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); + PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); + VirtualFile[] openFiles = editorManager.getOpenFiles(); + for (VirtualFile openFile : openFiles) { + editorManager.closeFile(openFile); + } + } + finally { + myEditor = null; + myFile = null; + myPsiManager = null; + try { - DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true); // return default value to avoid unnecessary save - FileEditorManager editorManager = FileEditorManager.getInstance(getProject()); - PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); - VirtualFile[] openFiles = editorManager.getOpenFiles(); - for (VirtualFile openFile : openFiles) { - editorManager.closeFile(openFile); - } + myProjectFixture.tearDown(); } finally { - myEditor = null; - myFile = null; - myPsiManager = null; - - try { - myProjectFixture.tearDown(); - } - finally { - myTempDirFixture.tearDown(); - } + myTempDirFixture.tearDown(); } } }); @@ -1433,40 +1427,37 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig private PsiFile configureInner(@NotNull final VirtualFile copy, @NotNull final SelectionAndCaretMarkupLoader loader) { assertInitialized(); - EdtTestUtil.runInEdtAndWait(new ThrowableRunnable() { - @Override - public void run() { - if (!copy.getFileType().isBinary()) { - AccessToken token = WriteAction.start(); - try { - copy.setBinaryContent(loader.newFileText.getBytes(copy.getCharset())); - } - catch (IOException e) { - throw new RuntimeException(e); - } - finally { - token.finish(); - } + EdtTestUtil.runInEdtAndWait(() -> { + if (!copy.getFileType().isBinary()) { + AccessToken token = WriteAction.start(); + try { + copy.setBinaryContent(loader.newFileText.getBytes(copy.getCharset())); } - myFile = copy; - myEditor = createEditor(copy); - if (myEditor == null) { - Assert.fail("editor couldn't be created for: " + copy.getPath() + ", use copyFileToProject() instead of configureByFile()"); + catch (IOException e) { + throw new RuntimeException(e); } + finally { + token.finish(); + } + } + myFile = copy; + myEditor = createEditor(copy); + if (myEditor == null) { + Assert.fail("editor couldn't be created for: " + copy.getPath() + ", use copyFileToProject() instead of configureByFile()"); + } - EditorTestUtil.setCaretsAndSelection(myEditor, loader.caretState); + EditorTestUtil.setCaretsAndSelection(myEditor, loader.caretState); - Module module = getModule(); - if (module != null) { - for (Facet facet : FacetManager.getInstance(module).getAllFacets()) { - module.getMessageBus().syncPublisher(FacetManager.FACETS_TOPIC).facetConfigurationChanged(facet); - } + Module module = getModule(); + if (module != null) { + for (Facet facet : FacetManager.getInstance(module).getAllFacets()) { + module.getMessageBus().syncPublisher(FacetManager.FACETS_TOPIC).facetConfigurationChanged(facet); } - PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); + } + PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); - if (myCaresAboutInjection) { - setupEditorForInjectedLanguage(); - } + if (myCaresAboutInjection) { + setupEditorForInjectedLanguage(); } }); diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/HeavyIdeaTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/HeavyIdeaTestFixtureImpl.java index cfd56708a0d3..9ac857d7bb76 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/HeavyIdeaTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/HeavyIdeaTestFixtureImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -49,7 +49,6 @@ import com.intellij.testFramework.builders.ModuleFixtureBuilder; import com.intellij.testFramework.fixtures.HeavyIdeaTestFixture; import com.intellij.util.PathUtil; import com.intellij.util.SmartList; -import com.intellij.util.ThrowableRunnable; import com.intellij.util.lang.CompoundRuntimeException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -72,9 +71,9 @@ import java.util.Set; @SuppressWarnings("TestOnlyProblems") class HeavyIdeaTestFixtureImpl extends BaseFixture implements HeavyIdeaTestFixture { private Project myProject; - private final Set myFilesToDelete = new HashSet(); + private final Set myFilesToDelete = new HashSet<>(); private IdeaTestApplication myApplication; - private final Set myModuleFixtureBuilders = new LinkedHashSet(); + private final Set myModuleFixtureBuilders = new LinkedHashSet<>(); private EditorListenerTracker myEditorListenerTracker; private ThreadTracker myThreadTracker; private final String myName; @@ -103,7 +102,7 @@ class HeavyIdeaTestFixtureImpl extends BaseFixture implements HeavyIdeaTestFixtu @Override public void tearDown() throws Exception { final Project project = getProject(); - final List exceptions = new SmartList(); + final List exceptions = new SmartList<>(); try { LightPlatformTestCase.doTearDown(project, myApplication, false, exceptions); @@ -111,12 +110,7 @@ class HeavyIdeaTestFixtureImpl extends BaseFixture implements HeavyIdeaTestFixtu moduleFixtureBuilder.getFixture().tearDown(); } - EdtTestUtil.runInEdtAndWait(new ThrowableRunnable() { - @Override - public void run() throws Throwable { - PlatformTestCase.closeAndDisposeProjectAndCheckThatNoOpenProjects(project, exceptions); - } - }); + EdtTestUtil.runInEdtAndWait(() -> PlatformTestCase.closeAndDisposeProjectAndCheckThatNoOpenProjects(project, exceptions)); myProject = null; for (File fileToDelete : myFilesToDelete) { @@ -158,19 +152,15 @@ class HeavyIdeaTestFixtureImpl extends BaseFixture implements HeavyIdeaTestFixtu new Throwable(projectPath).printStackTrace(new PrintStream(buffer)); myProject = PlatformTestCase.createProject(projectPath, buffer.toString()); - EdtTestUtil.runInEdtAndWait(new ThrowableRunnable() { - @SuppressWarnings("TestOnlyProblems") - @Override - public void run() throws Throwable { - ProjectManagerEx.getInstanceEx().openTestProject(myProject); + EdtTestUtil.runInEdtAndWait(() -> { + ProjectManagerEx.getInstanceEx().openTestProject(myProject); - for (ModuleFixtureBuilder moduleFixtureBuilder : myModuleFixtureBuilders) { - moduleFixtureBuilder.getFixture().setUp(); - } - - LightPlatformTestCase.clearUncommittedDocuments(myProject); - ((FileTypeManagerImpl)FileTypeManager.getInstance()).drainReDetectQueue(); + for (ModuleFixtureBuilder moduleFixtureBuilder : myModuleFixtureBuilders) { + moduleFixtureBuilder.getFixture().setUp(); } + + LightPlatformTestCase.clearUncommittedDocuments(myProject); + ((FileTypeManagerImpl)FileTypeManager.getInstance()).drainReDetectQueue(); }); } diff --git a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java index fd580538a454..64f0286a6290 100644 --- a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java +++ b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java @@ -1710,7 +1710,7 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra close(); CommandProcessor.getInstance().executeCommand( - myProject, myProcessRunnable::run, + myProject, myProcessRunnable, myCommandName, null ); diff --git a/platform/vcs-tests/src/com/intellij/testFramework/vcs/AbstractVcsTestCase.java b/platform/vcs-tests/src/com/intellij/testFramework/vcs/AbstractVcsTestCase.java index 0345045e82d7..e2a4fa3fb943 100644 --- a/platform/vcs-tests/src/com/intellij/testFramework/vcs/AbstractVcsTestCase.java +++ b/platform/vcs-tests/src/com/intellij/testFramework/vcs/AbstractVcsTestCase.java @@ -31,8 +31,8 @@ import com.intellij.openapi.vcs.changes.committed.CommittedChangesCache; import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.testFramework.EdtTestUtil; import com.intellij.testFramework.PlatformTestCase; -import com.intellij.testFramework.UsefulTestCase; import com.intellij.testFramework.builders.EmptyModuleFixtureBuilder; import com.intellij.testFramework.fixtures.IdeaProjectTestFixture; import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory; @@ -44,7 +44,10 @@ import org.junit.Assert; import java.io.File; import java.io.IOException; -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; import java.util.concurrent.atomic.AtomicReference; /** @@ -79,7 +82,7 @@ public abstract class AbstractVcsTestCase { } protected void refreshVfs() { - UsefulTestCase.edt(() -> myWorkingCopyDir.refresh(false, true)); + EdtTestUtil.runInEdtAndWait(() -> myWorkingCopyDir.refresh(false, true)); } protected void initProject(final File clientRoot, String testName) throws Exception { diff --git a/platform/vcs-tests/testSrc/com/intellij/vcs/VcsDirtyScopeManagerTest.kt b/platform/vcs-tests/testSrc/com/intellij/vcs/VcsDirtyScopeManagerTest.kt index 93931a9c4b35..d9eeb8bd9b0c 100644 --- a/platform/vcs-tests/testSrc/com/intellij/vcs/VcsDirtyScopeManagerTest.kt +++ b/platform/vcs-tests/testSrc/com/intellij/vcs/VcsDirtyScopeManagerTest.kt @@ -24,6 +24,7 @@ import com.intellij.openapi.vcs.changes.* import com.intellij.openapi.vcs.changes.committed.MockAbstractVcs import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl import com.intellij.openapi.vfs.VirtualFile +import com.intellij.testFramework.runInEdtAndWait import com.intellij.util.continuation.SemaphoreContinuationContext import com.intellij.vcs.test.VcsPlatformTest import com.intellij.vcsUtil.VcsUtil.getFilePath @@ -181,9 +182,11 @@ class VcsDirtyScopeManagerTest : VcsPlatformTest() { private fun createFile(parentDir: VirtualFile, name: String, dir: Boolean): FilePath { var file: VirtualFile? = null - edt { ApplicationManager.getApplication().runWriteAction { - file = if (dir) parentDir.createChildDirectory(this, name) else parentDir.createChildData(this, name) - }} + runInEdtAndWait { + ApplicationManager.getApplication().runWriteAction { + file = if (dir) parentDir.createChildDirectory(this, name) else parentDir.createChildData(this, name) + } + } return getFilePath(file!!) } diff --git a/plugins/git4idea/tests/git4idea/push/GitPushResultNotificationTest.java b/plugins/git4idea/tests/git4idea/push/GitPushResultNotificationTest.java index 5a4737ec6c91..db20a8eabfe0 100644 --- a/plugins/git4idea/tests/git4idea/push/GitPushResultNotificationTest.java +++ b/plugins/git4idea/tests/git4idea/push/GitPushResultNotificationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -17,7 +17,6 @@ package git4idea.push; import com.intellij.notification.NotificationType; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Ref; import com.intellij.openapi.vcs.update.UpdatedFiles; import com.intellij.openapi.vfs.VirtualFile; @@ -127,7 +126,7 @@ public class GitPushResultNotificationTest extends GitPlatformTest { public void test_nothing() { GitPushNativeResult branchResult = new GitPushNativeResult(UP_TO_DATE, "refs/heads/master"); - GitPushResultNotification notification = notification(convertFromNative(branchResult, Collections.emptyList(), + GitPushResultNotification notification = notification(convertFromNative(branchResult, Collections.emptyList(), 0, from("master"), to("origin/master"))); assertNotification(NotificationType.INFORMATION, "Push successful", "Everything is up-to-date", notification); } @@ -185,7 +184,7 @@ public class GitPushResultNotificationTest extends GitPlatformTest { String reason = nativeType == REJECTED ? GitPushNativeResult.FETCH_FIRST_REASON : null; GitPushNativeResult nr = new GitPushNativeResult(nativeType, from, reason, null); return GitPushRepoResult.addUpdateResult( - convertFromNative(nr, Collections.emptyList(), commits, from(from), to(to)), + convertFromNative(nr, Collections.emptyList(), commits, from(from), to(to)), updateResult); } @@ -207,22 +206,17 @@ public class GitPushResultNotificationTest extends GitPlatformTest { private static GitRemoteBranch to(String to) { int firstSlash = to.indexOf('/'); - GitRemote remote = new GitRemote(to.substring(0, firstSlash), Collections.emptyList(), Collections.emptyList(), - Collections.emptyList(), Collections.emptyList()); + GitRemote remote = new GitRemote(to.substring(0, firstSlash), Collections.emptyList(), Collections.emptyList(), + Collections.emptyList(), Collections.emptyList()); return new GitStandardRemoteBranch(remote, to.substring(firstSlash + 1)); } private GitPushResultNotification notification(GitPushRepoResult singleResult) { - return notification(Collections.singletonMap(repo("community"), singleResult)); + return notification(Collections.singletonMap(repo("community"), singleResult)); } private GitPushResultNotification notification(Map map) { - boolean wasUpdatePerformed = ContainerUtil.exists(map.values(), new Condition() { - @Override - public boolean value(GitPushRepoResult aNew) { - return aNew.getUpdateResult() != null; - } - }); + boolean wasUpdatePerformed = ContainerUtil.exists(map.values(), aNew -> aNew.getUpdateResult() != null); UpdatedFiles updatedFiles = UpdatedFiles.create(); if (wasUpdatePerformed) { updatedFiles.getTopLevelGroups().get(0).add("file.txt", "Git", null); @@ -232,12 +226,7 @@ public class GitPushResultNotificationTest extends GitPlatformTest { private static MockGitRepository repo(final String name) { final Ref root = Ref.create(); - EdtTestUtil.runInEdtAndWait(new Runnable() { - @Override - public void run() { - root.set(createChildData(ourProject.getBaseDir(), name)); - } - }); + EdtTestUtil.runInEdtAndWait(() -> root.set(createChildData(ourProject.getBaseDir(), name))); return new MockGitRepository(ourProject, root.get()); } } \ No newline at end of file diff --git a/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderTest.java b/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderTest.java index 09f3977d7f7e..4df7dfd35778 100644 --- a/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderTest.java +++ b/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -23,8 +23,6 @@ import com.intellij.openapi.vcs.VcsTestUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.EdtTestUtil; -import com.intellij.util.Function; -import com.intellij.util.ThrowableRunnable; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.io.ZipUtil; import com.intellij.vcs.log.Hash; @@ -60,12 +58,7 @@ public class GitRepositoryReaderTest extends GitPlatformTest { File pluginRoot = new File(PluginPathManager.getPluginHomePath("git4idea")); File dataDir = new File(new File(pluginRoot, "testData"), "repo"); File[] testCases = dataDir.listFiles(FileUtilRt.ALL_DIRECTORIES); - return ContainerUtil.map(testCases, new Function() { - @Override - public Object[] fun(File file) { - return new Object[] { file.getName(), file }; - } - }); + return ContainerUtil.map(testCases, file -> new Object[] { file.getName(), file }); } @SuppressWarnings({"UnusedParameters", "JUnitTestCaseWithNonTrivialConstructors"}) @@ -76,12 +69,7 @@ public class GitRepositoryReaderTest extends GitPlatformTest { @Override @Before public void setUp() throws Exception { - EdtTestUtil.runInEdtAndWait(new ThrowableRunnable() { - @Override - public void run() throws Exception { - GitRepositoryReaderTest.super.setUp(); - } - }); + EdtTestUtil.runInEdtAndWait(() -> super.setUp()); myTempDir = new File(myProjectRoot.getPath(), "test"); prepareTest(myTestCaseDir); } @@ -95,12 +83,7 @@ public class GitRepositoryReaderTest extends GitPlatformTest { } } finally { - EdtTestUtil.runInEdtAndWait(new ThrowableRunnable() { - @Override - public void run() throws Throwable { - GitRepositoryReaderTest.super.tearDown(); - } - }); + EdtTestUtil.runInEdtAndWait(() -> super.tearDown()); } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/DebuggerMethods.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/DebuggerMethods.groovy index 06dcb4d65834..80bceeca7fa9 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/DebuggerMethods.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/DebuggerMethods.groovy @@ -47,7 +47,7 @@ import com.intellij.util.concurrency.Semaphore import groovy.transform.CompileStatic import org.jetbrains.annotations.NotNull -import static com.intellij.testFramework.UsefulTestCase.edt +import static com.intellij.testFramework.EdtTestUtil.runInEdtAndWait @CompileStatic trait DebuggerMethods extends CompilerMethods { @@ -65,7 +65,7 @@ trait DebuggerMethods extends CompilerMethods { } void runDebugger(RunProfile configuration, Closure cl) { - edt { + runInEdtAndWait { def listener = [onTextAvailable: { ProcessEvent evt, type -> if (type == ProcessOutputTypes.STDERR) { println evt.text @@ -97,7 +97,7 @@ trait DebuggerMethods extends CompilerMethods { } void addBreakpoint(VirtualFile file, int line) { - edt { + runInEdtAndWait { DebuggerManagerImpl.getInstanceEx(project).breakpointManager.addLineBreakpoint(FileDocumentManager.instance.getDocument(file), line) } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyDebuggerTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyDebuggerTest.groovy index f493a3eb57c6..0836bd0d6047 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyDebuggerTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyDebuggerTest.groovy @@ -32,6 +32,8 @@ import com.intellij.util.SystemProperties import groovy.transform.CompileStatic import org.jetbrains.plugins.groovy.GroovyFileType +import static com.intellij.testFramework.EdtTestUtil.runInEdtAndWait + /** * @author peter */ @@ -232,7 +234,7 @@ def getFoo() { 13 } public void testClassOutOfSourceRoots() { def tempDir = new TempDirTestFixtureImpl() - edt { + runInEdtAndWait { tempDir.setUp() disposeOnTearDown({ tempDir.tearDown() } as Disposable) PsiTestUtil.addContentRoot(myModule, tempDir.getFile('')) @@ -251,7 +253,7 @@ static def foo(def a) { """ - edt { + runInEdtAndWait { myClass = tempDir.createFile("MyClass.groovy", mcText) } @@ -271,7 +273,7 @@ cl.parseClass('''$mcText''', 'MyClass.groovy').foo(2) public void "test groovy source named java in lib source"() { def tempDir = new TempDirTestFixtureImpl() - edt { + runInEdtAndWait { tempDir.setUp() disposeOnTearDown({ tempDir.tearDown() } as Disposable) tempDir.createFile("pkg/java.groovy", "class java {}") @@ -345,7 +347,7 @@ println "hello" def module2 = addModule("module2", true) addGroovyLibrary(module1) addGroovyLibrary(module2) - edt { + runInEdtAndWait { ModuleRootModificationUtil.addDependency(myModule, module1) } @@ -515,7 +517,7 @@ public class Main { void addBreakpoint(String fileName, int line) { VirtualFile file = null - edt { + runInEdtAndWait { file = myFixture.tempDirFixture.getFile(fileName) } addBreakpoint(file, line) diff --git a/plugins/hg4idea/testSrc/hg4idea/test/merge/HgMergeProviderTest.java b/plugins/hg4idea/testSrc/hg4idea/test/merge/HgMergeProviderTest.java index 7ea17cd01f97..ed7896a12211 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/merge/HgMergeProviderTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/merge/HgMergeProviderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -21,7 +21,6 @@ import com.intellij.openapi.vcs.merge.MergeData; import com.intellij.openapi.vcs.merge.MergeProvider; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.EdtTestUtil; -import com.intellij.util.ThrowableRunnable; import hg4idea.test.HgPlatformTest; import hg4idea.test.HgTestUtil; import org.testng.Assert; @@ -185,7 +184,7 @@ public class HgMergeProviderTest extends HgPlatformTest { private void verifyMergeData(final VirtualFile file, String expectedBase, String expectedLocal, String expectedServer) throws VcsException { - EdtTestUtil.runInEdtAndWait((ThrowableRunnable)() -> { + EdtTestUtil.runInEdtAndWait(() -> { MergeData mergeData = myMergeProvider.loadRevisions(file); assertEquals(expectedBase, mergeData.ORIGINAL); assertEquals(expectedServer, mergeData.LAST); diff --git a/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnAuthenticationTest.java b/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnAuthenticationTest.java index 24aea3a633fa..a6a3476b9461 100644 --- a/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnAuthenticationTest.java +++ b/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnAuthenticationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -54,15 +54,7 @@ public class SvnAuthenticationTest extends PlatformTestCase { @Override protected void setUp() throws Exception { - EdtTestUtil.runInEdtAndWait((Runnable)() -> { - try { - SvnAuthenticationTest.super.setUp(); - } - catch (Exception e) { - throw new RuntimeException(e); - } - }); - + EdtTestUtil.runInEdtAndWait(() -> super.setUp()); myConfiguration = SvnConfiguration.getInstance(myProject); final String configPath = myProject.getBaseDir().getPath() + File.separator + "Subversion"; @@ -112,42 +104,39 @@ public class SvnAuthenticationTest extends PlatformTestCase { final SVNException[] exception = new SVNException[1]; final boolean[] result = {false}; - synchronousBackground(new Runnable() { - @Override - public void run() { - try { + synchronousBackground(() -> { + try { - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - if (SystemInfo.isWindows) { - listener.addStep(new Trinity(ProviderType.persistent, url, Type.save)); - } else { - listener.addStep(new Trinity(ProviderType.persistent, url, Type.without_pasword_save)); - } - - commonScheme(url, false, null); - Assert.assertEquals(3, listener.getCnt()); - //long start = System.currentTimeMillis(); - //waitListenerStep(start, listener, 3); - - listener.reset(); - if (!SystemInfo.isWindows) savedOnceListener.reset(); - SvnConfiguration.RUNTIME_AUTH_CACHE.clear(); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - if (! SystemInfo.isWindows) { - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.without_pasword_save)); - } - commonScheme(url, false, null); - //start = System.currentTimeMillis(); - //waitListenerStep(start, listener, 4); - Assert.assertEquals(SystemInfo.isWindows ? 1 : 3, listener.getCnt()); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + if (SystemInfo.isWindows) { + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.save)); + } else { + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save)); } - catch (SVNException e) { - exception[0] = e; + + commonScheme(url, false, null); + Assert.assertEquals(3, listener.getCnt()); + //long start = System.currentTimeMillis(); + //waitListenerStep(start, listener, 3); + + listener.reset(); + if (!SystemInfo.isWindows) savedOnceListener.reset(); + SvnConfiguration.RUNTIME_AUTH_CACHE.clear(); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + if (! SystemInfo.isWindows) { + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save)); } - result[0] = true; + commonScheme(url, false, null); + //start = System.currentTimeMillis(); + //waitListenerStep(start, listener, 4); + Assert.assertEquals(SystemInfo.isWindows ? 1 : 3, listener.getCnt()); } + catch (SVNException e) { + exception[0] = e; + } + result[0] = true; }); Assert.assertTrue(result[0]); @@ -190,9 +179,9 @@ public class SvnAuthenticationTest extends PlatformTestCase { @Override public void run() { try { - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.save)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.save)); commonScheme(url, false, null); Assert.assertEquals(3, listener.getCnt()); @@ -200,7 +189,7 @@ public class SvnAuthenticationTest extends PlatformTestCase { //waitListenerStep(start, listener, 3); SvnConfiguration.RUNTIME_AUTH_CACHE.clear(); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); commonScheme(url, false, null); //start = System.currentTimeMillis(); //waitListenerStep(start, listener, 4); @@ -260,8 +249,8 @@ public class SvnAuthenticationTest extends PlatformTestCase { @Override public void run() { try { - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); commonScheme(url, false, null); //long start = System.currentTimeMillis(); @@ -273,8 +262,8 @@ public class SvnAuthenticationTest extends PlatformTestCase { savedOnceListener.reset(); SvnConfiguration.RUNTIME_AUTH_CACHE.clear(); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); commonScheme(url, false, null); Assert.assertEquals(4, listener.getCnt()); //start = System.currentTimeMillis(); @@ -326,8 +315,8 @@ public class SvnAuthenticationTest extends PlatformTestCase { @Override public void run() { try { - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); commonScheme(url, false, null); Assert.assertEquals(2, listener.getCnt()); @@ -337,8 +326,8 @@ public class SvnAuthenticationTest extends PlatformTestCase { savedOnceListener.reset(); SvnConfiguration.RUNTIME_AUTH_CACHE.clear(); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); commonScheme(url, false, null); Assert.assertEquals(4, listener.getCnt()); Assert.assertEquals(1, myTestInteraction.getNumAuthWarn()); @@ -387,8 +376,8 @@ public class SvnAuthenticationTest extends PlatformTestCase { @Override public void run() { try { - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); commonScheme(url, false, null); Assert.assertEquals(2, listener.getCnt()); @@ -398,8 +387,8 @@ public class SvnAuthenticationTest extends PlatformTestCase { savedOnceListener.reset(); SvnConfiguration.RUNTIME_AUTH_CACHE.clear(); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); commonScheme(url, false, null); Assert.assertEquals(4, listener.getCnt()); Assert.assertEquals(1, myTestInteraction.getNumAuthWarn()); @@ -454,9 +443,9 @@ public class SvnAuthenticationTest extends PlatformTestCase { @Override public void run() { try { - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.without_pasword_save)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save)); commonScheme(url, false, null); Assert.assertEquals(3, listener.getCnt()); @@ -466,9 +455,9 @@ public class SvnAuthenticationTest extends PlatformTestCase { savedOnceListener.reset(); SvnConfiguration.RUNTIME_AUTH_CACHE.clear(); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.without_pasword_save)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save)); commonScheme(url, false, null); Assert.assertEquals(6, listener.getCnt()); Assert.assertEquals(1, myTestInteraction.getNumPasswordsWarn()); @@ -517,9 +506,9 @@ public class SvnAuthenticationTest extends PlatformTestCase { @Override public void run() { try { - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.without_pasword_save)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save)); commonScheme(url, false, null); Assert.assertEquals(3, listener.getCnt()); @@ -529,9 +518,9 @@ public class SvnAuthenticationTest extends PlatformTestCase { savedOnceListener.reset(); SvnConfiguration.RUNTIME_AUTH_CACHE.clear(); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.without_pasword_save)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save)); commonScheme(url, false, null); Assert.assertEquals(6, listener.getCnt()); Assert.assertEquals(1, myTestInteraction.getNumPasswordsWarn()); @@ -587,9 +576,9 @@ public class SvnAuthenticationTest extends PlatformTestCase { @Override public void run() { try { - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.without_pasword_save)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save)); commonScheme(url, false, null); Assert.assertEquals(3, listener.getCnt()); @@ -599,9 +588,9 @@ public class SvnAuthenticationTest extends PlatformTestCase { savedOnceListener.reset(); SvnConfiguration.RUNTIME_AUTH_CACHE.clear(); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.without_pasword_save)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save)); commonScheme(url, false, null); Assert.assertEquals(6, listener.getCnt()); Assert.assertEquals(1, myTestInteraction.getNumPasswordsWarn()); @@ -650,9 +639,9 @@ public class SvnAuthenticationTest extends PlatformTestCase { @Override public void run() { try { - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.without_pasword_save)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save)); commonScheme(url, false, null); Assert.assertEquals(3, listener.getCnt()); @@ -662,9 +651,9 @@ public class SvnAuthenticationTest extends PlatformTestCase { savedOnceListener.reset(); SvnConfiguration.RUNTIME_AUTH_CACHE.clear(); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.without_pasword_save)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save)); commonScheme(url, false, null); Assert.assertEquals(6, listener.getCnt()); Assert.assertEquals(1, myTestInteraction.getNumSSLWarn()); @@ -710,9 +699,9 @@ public class SvnAuthenticationTest extends PlatformTestCase { @Override public void run() { try { - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.save)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.save)); commonScheme(url, false, null); long start = System.currentTimeMillis(); @@ -737,9 +726,9 @@ public class SvnAuthenticationTest extends PlatformTestCase { myTestInteraction.setPlaintextAnswer(false); SvnConfiguration.RUNTIME_AUTH_CACHE.clear(); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.without_pasword_save)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save)); commonScheme(url, false, null); start = System.currentTimeMillis(); waitListenerStep(start, listener, 6); @@ -748,9 +737,9 @@ public class SvnAuthenticationTest extends PlatformTestCase { savedOnceListener.reset(); myTestInteraction.reset(); SvnConfiguration.RUNTIME_AUTH_CACHE.clear(); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.without_pasword_save)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save)); commonScheme(url, false, null); start = System.currentTimeMillis(); waitListenerStep(start, listener, 9); @@ -799,9 +788,9 @@ public class SvnAuthenticationTest extends PlatformTestCase { @Override public void run() { try { - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.without_pasword_save)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save)); commonScheme(url, false, null); long start = System.currentTimeMillis(); @@ -812,9 +801,9 @@ public class SvnAuthenticationTest extends PlatformTestCase { savedOnceListener.reset(); myTestInteraction.reset(); - listener.addStep(new Trinity(ProviderType.persistent, url2, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url2, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url2, Type.without_pasword_save)); + listener.addStep(new Trinity<>(ProviderType.persistent, url2, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url2, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url2, Type.without_pasword_save)); commonScheme(url2, false, "anotherRealm"); start = System.currentTimeMillis(); waitListenerStep(start, listener, 6); @@ -859,9 +848,9 @@ public class SvnAuthenticationTest extends PlatformTestCase { @Override public void run() { try { - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.save)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.save)); commonScheme(url, false, null); long start = System.currentTimeMillis(); @@ -886,9 +875,9 @@ public class SvnAuthenticationTest extends PlatformTestCase { myTestInteraction.setSSLPlaintextAnswer(false); SvnConfiguration.RUNTIME_AUTH_CACHE.clear(); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.without_pasword_save)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save)); commonScheme(url, false, null); start = System.currentTimeMillis(); waitListenerStep(start, listener, 6); @@ -898,9 +887,9 @@ public class SvnAuthenticationTest extends PlatformTestCase { myTestInteraction.reset(); savedOnceListener.reset(); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.request)); - listener.addStep(new Trinity(ProviderType.interactive, url, Type.request)); - listener.addStep(new Trinity(ProviderType.persistent, url, Type.without_pasword_save)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.interactive, url, Type.request)); + listener.addStep(new Trinity<>(ProviderType.persistent, url, Type.without_pasword_save)); commonScheme(url, false, null); start = System.currentTimeMillis(); waitListenerStep(start, listener, 9); @@ -998,7 +987,7 @@ public class SvnAuthenticationTest extends PlatformTestCase { private TestListener(final Object synchObject) { mySynchObject = synchObject; - myExpectedSequence = new ArrayList>(); + myExpectedSequence = new ArrayList<>(); myCnt = 0; mySuccess = true; } @@ -1036,7 +1025,7 @@ public class SvnAuthenticationTest extends PlatformTestCase { } private void saveRegistration(ProviderType type, SVNURL url, boolean withCredentials) { - mySuccess = myExpectedSequence.get(myCnt).equals(new Trinity(type, url, withCredentials ? Type.save : Type.without_pasword_save)); + mySuccess = myExpectedSequence.get(myCnt).equals(new Trinity<>(type, url, withCredentials ? Type.save : Type.without_pasword_save)); if (mySuccess) { ++ myCnt; } @@ -1055,7 +1044,7 @@ public class SvnAuthenticationTest extends PlatformTestCase { public void requested(ProviderType type, SVNURL url, String realm, String kind, boolean canceled) { if (! mySuccess) return; - mySuccess = myExpectedSequence.get(myCnt).equals(new Trinity(type, url, Type.request)); + mySuccess = myExpectedSequence.get(myCnt).equals(new Trinity<>(type, url, Type.request)); if (mySuccess) { ++ myCnt; } @@ -1076,8 +1065,8 @@ public class SvnAuthenticationTest extends PlatformTestCase { private boolean mySaveCalled; private SavedOnceListener() { - myClientRequested = new HashSet>(); - mySaved = new HashSet>(); + myClientRequested = new HashSet<>(); + mySaved = new HashSet<>(); } @Override @@ -1108,7 +1097,7 @@ public class SvnAuthenticationTest extends PlatformTestCase { } private void saveRegistration(SVNURL url, String kind) { - final Pair pair = new Pair(url, kind); + final Pair pair = new Pair<>(url, kind); if (mySaved.contains(pair)) { myCause = "saved twice"; } @@ -1116,13 +1105,13 @@ public class SvnAuthenticationTest extends PlatformTestCase { } public boolean isSaved(final SVNURL url, final String kind) { - return mySaved.contains(new Pair(url, kind)); + return mySaved.contains(new Pair<>(url, kind)); } @Override public void requested(ProviderType type, SVNURL url, String realm, String kind, boolean canceled) { if (ProviderType.interactive.equals(type)) { - final Pair pair = new Pair(url, kind); + final Pair pair = new Pair<>(url, kind); if (myClientRequested.contains(pair)) { myCause = "client requested twice"; } @@ -1135,11 +1124,11 @@ public class SvnAuthenticationTest extends PlatformTestCase { } public void assertSaved(final SVNURL url, final String kind) { - Assert.assertTrue("not saved", mySaved.contains(new Pair(url, kind))); + Assert.assertTrue("not saved", mySaved.contains(new Pair<>(url, kind))); } public void assertNotSaved(final SVNURL url, final String kind) { - Assert.assertTrue("saved", ! mySaved.contains(new Pair(url, kind))); + Assert.assertTrue("saved", ! mySaved.contains(new Pair<>(url, kind))); } } diff --git a/plugins/svn4idea/testSource/org/jetbrains/idea/svn16/SvnAuthenticationTest.java b/plugins/svn4idea/testSource/org/jetbrains/idea/svn16/SvnAuthenticationTest.java index 3842e0ae125e..9995081672a5 100644 --- a/plugins/svn4idea/testSource/org/jetbrains/idea/svn16/SvnAuthenticationTest.java +++ b/plugins/svn4idea/testSource/org/jetbrains/idea/svn16/SvnAuthenticationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * 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. @@ -56,14 +56,7 @@ public class SvnAuthenticationTest extends PlatformTestCase { @Override protected void setUp() throws Exception { - EdtTestUtil.runInEdtAndWait((Runnable)() -> { - try { - SvnAuthenticationTest.super.setUp(); - } - catch (Exception e) { - throw new RuntimeException(e); - } - }); + EdtTestUtil.runInEdtAndWait(() -> super.setUp()); myConfiguration = SvnConfiguration.getInstance(myProject); @@ -89,14 +82,7 @@ public class SvnAuthenticationTest extends PlatformTestCase { @Override protected void tearDown() throws Exception { - EdtTestUtil.runInEdtAndWait((Runnable)() -> { - try { - SvnAuthenticationTest.super.tearDown(); - } - catch (Exception e) { - throw new RuntimeException(e); - } - }); + EdtTestUtil.runInEdtAndWait(() -> super.tearDown()); FileUtil.delete(new File(myConfiguration.getConfigurationDirectory())); } diff --git a/python/testSrc/com/intellij/execution/testframework/actions/RerunFailedActionsTestTools.java b/python/testSrc/com/intellij/execution/testframework/actions/RerunFailedActionsTestTools.java index 1d0f231ea1e1..ea36a6cf19ef 100644 --- a/python/testSrc/com/intellij/execution/testframework/actions/RerunFailedActionsTestTools.java +++ b/python/testSrc/com/intellij/execution/testframework/actions/RerunFailedActionsTestTools.java @@ -1,3 +1,18 @@ +/* + * 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. + */ package com.intellij.execution.testframework.actions; import com.intellij.execution.ExecutionException; @@ -11,7 +26,7 @@ import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.util.Ref; -import com.intellij.testFramework.UsefulTestCase; +import com.intellij.testFramework.EdtTestUtil; import com.jetbrains.python.testing.PyRerunFailedTestsAction; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -37,8 +52,8 @@ public final class RerunFailedActionsTestTools { if (profile == null) { return null; } - final Ref stateRef = new Ref(); - UsefulTestCase.edt(() -> stateRef.set(ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), profile).build())); + final Ref stateRef = new Ref<>(); + EdtTestUtil.runInEdtAndWait((() -> stateRef.set(ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), profile).build()))); return stateRef.get(); } @@ -55,7 +70,7 @@ public final class RerunFailedActionsTestTools { if (action == null) { return null; } - final Ref stateRef = new Ref(); + final Ref stateRef = new Ref<>(); ApplicationManager.getApplication().invokeAndWait(() -> { try { stateRef.set(action.getState()); diff --git a/python/testSrc/com/jetbrains/env/PyAbstractTestProcessRunner.java b/python/testSrc/com/jetbrains/env/PyAbstractTestProcessRunner.java index 30ba37517b35..a820c5c3adb4 100644 --- a/python/testSrc/com/jetbrains/env/PyAbstractTestProcessRunner.java +++ b/python/testSrc/com/jetbrains/env/PyAbstractTestProcessRunner.java @@ -1,3 +1,18 @@ +/* + * 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. + */ package com.jetbrains.env; import com.intellij.execution.ExecutionException; @@ -216,7 +231,7 @@ public class PyAbstractTestProcessRunner allTests = getTestProxy().getAllTests(); assert !allTests.isEmpty() : "No tests at all."; final GlobalSearchScope scope = GlobalSearchScope.allScope(project); - EdtTestUtil.runInEdtAndWait((Runnable)() -> allTests.subList(1, allTests.size()) + EdtTestUtil.runInEdtAndWait(() -> allTests.subList(1, allTests.size()) .forEach(t -> Assert.assertNotNull("No location " + t, t.getLocation(project, scope)))); } } diff --git a/python/testSrc/com/jetbrains/env/python/PyDynamicTypesTest.java b/python/testSrc/com/jetbrains/env/python/PyDynamicTypesTest.java index bca39132a17b..dc7200855510 100644 --- a/python/testSrc/com/jetbrains/env/python/PyDynamicTypesTest.java +++ b/python/testSrc/com/jetbrains/env/python/PyDynamicTypesTest.java @@ -21,6 +21,7 @@ import com.intellij.openapi.editor.LogicalPosition; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.EditorTestUtil; +import com.intellij.testFramework.EdtTestUtil; import com.jetbrains.env.PyEnvTestCase; import com.jetbrains.env.Staging; import com.jetbrains.env.python.debug.PyDebuggerTask; @@ -32,8 +33,6 @@ import org.junit.Test; import java.io.IOException; -import static com.intellij.testFramework.UsefulTestCase.edt; - /** * @author traff */ @@ -76,7 +75,7 @@ public class PyDynamicTypesTest extends PyEnvTestCase { public void testing() throws Exception { waitForTerminate(); - edt(() -> { + EdtTestUtil.runInEdtAndWait(() -> { myFixture.configureByFile("dynamicTypes/" + scriptName); try { diff --git a/python/testSrc/com/jetbrains/env/python/PythonSkeletonsTest.java b/python/testSrc/com/jetbrains/env/python/PythonSkeletonsTest.java index d224efb99b37..3c10c25f05f4 100644 --- a/python/testSrc/com/jetbrains/env/python/PythonSkeletonsTest.java +++ b/python/testSrc/com/jetbrains/env/python/PythonSkeletonsTest.java @@ -1,3 +1,18 @@ +/* + * 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. + */ package com.jetbrains.env.python; import com.google.common.collect.ImmutableSet; @@ -9,11 +24,11 @@ import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; +import com.intellij.testFramework.EdtTestUtil; import com.jetbrains.env.PyEnvTestCase; import com.jetbrains.env.PyExecutionFixtureTestTask; import com.jetbrains.env.PyTestTask; import com.jetbrains.python.PythonFileType; -import com.jetbrains.python.PythonTestUtil; import com.jetbrains.python.documentation.PythonDocumentationProvider; import com.jetbrains.python.inspections.unresolvedReference.PyUnresolvedReferencesInspection; import com.jetbrains.python.psi.*; @@ -32,7 +47,6 @@ import org.junit.Test; import java.io.File; import java.util.Set; -import static com.intellij.testFramework.UsefulTestCase.edt; import static org.junit.Assert.*; /** @@ -66,7 +80,7 @@ public class PythonSkeletonsTest extends PyEnvTestCase { assertEquals(SkeletonVersionChecker.BUILTIN_NAME, header.getBinaryFile()); // Run inspections on a file that uses builtins - edt(() -> myFixture.configureByFile(getTestName(false) + ".py")); + EdtTestUtil.runInEdtAndWait((() -> myFixture.configureByFile(getTestName(false) + ".py"))); PsiFile expr = myFixture.getFile(); @@ -86,7 +100,7 @@ public class PythonSkeletonsTest extends PyEnvTestCase { assertEquals(builtins, builtinsFromPsi); myFixture.enableInspections(PyUnresolvedReferencesInspection.class); - edt(() -> myFixture.checkHighlighting(true, false, false)); + EdtTestUtil.runInEdtAndWait((() -> myFixture.checkHighlighting(true, false, false))); } }); } @@ -107,10 +121,10 @@ public class PythonSkeletonsTest extends PyEnvTestCase { LocalFileSystem.getInstance().refresh(false); // Run inspections on code that uses named tuples - edt(() -> myFixture.configureByFile(getTestName(false) + ".py")); + EdtTestUtil.runInEdtAndWait(() -> myFixture.configureByFile(getTestName(false) + ".py")); myFixture.enableInspections(PyUnresolvedReferencesInspection.class); - edt(() -> myFixture.checkHighlighting(true, false, false)); + EdtTestUtil.runInEdtAndWait(() -> myFixture.checkHighlighting(true, false, false)); } }); } @@ -173,10 +187,10 @@ public class PythonSkeletonsTest extends PyEnvTestCase { runTest(new SkeletonsTask() { @Override protected void runTestOn(@NotNull Sdk sdk) { - edt(() -> myFixture.configureByFile(getTestName(false) + ".py")); + EdtTestUtil.runInEdtAndWait((() -> myFixture.configureByFile(getTestName(false) + ".py"))); myFixture.enableInspections(PyUnresolvedReferencesInspection.class); - edt(() -> myFixture.checkHighlighting(true, false, false)); + EdtTestUtil.runInEdtAndWait((() -> myFixture.checkHighlighting(true, false, false))); } }); } diff --git a/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java b/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java index 33392a3e0e65..1ee2aa5e2edd 100644 --- a/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java +++ b/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java @@ -1,3 +1,18 @@ +/* + * 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. + */ package com.jetbrains.env.python.testing; import com.intellij.execution.ExecutionException; @@ -13,7 +28,6 @@ import com.jetbrains.python.PyBundle; import com.jetbrains.python.psi.LanguageLevel; import com.jetbrains.python.testing.PythonTestConfigurationsModel; import com.jetbrains.python.testing.unittest.PythonUnitTestConfigurationProducer; -import org.hamcrest.Matchers; import org.jetbrains.annotations.NotNull; import org.junit.Assert; import org.junit.Test; @@ -95,7 +109,7 @@ public final class PythonUnitTestingTest extends PyEnvTestCase { startMessagesCapture(); - EdtTestUtil.runInEdtAndWait((Runnable)() -> { + EdtTestUtil.runInEdtAndWait(() -> { deleteAllTestFiles(myFixture); runner.rerunFailedTests(); }); @@ -257,7 +271,7 @@ public final class PythonUnitTestingTest extends PyEnvTestCase { runner.getAllConsoleText()), fileNames.size() >= 3); // UnitTest highlights file name - Assert.assertThat("Bad line highlighted", fileNames, Matchers.everyItem(Matchers.endsWith(fileName))); + Assert.assertThat("Bad line highlighted", fileNames, everyItem(endsWith(fileName))); } }); } diff --git a/python/testSrc/com/jetbrains/python/sdkTools/PyTestSdkTools.java b/python/testSrc/com/jetbrains/python/sdkTools/PyTestSdkTools.java index 74bf5e4bb95e..17f89c0800dc 100644 --- a/python/testSrc/com/jetbrains/python/sdkTools/PyTestSdkTools.java +++ b/python/testSrc/com/jetbrains/python/sdkTools/PyTestSdkTools.java @@ -1,3 +1,18 @@ +/* + * 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. + */ package com.jetbrains.python.sdkTools; import com.intellij.openapi.application.ApplicationManager; @@ -11,24 +26,19 @@ import com.intellij.openapi.roots.ModuleRootModificationUtil; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.Ref; -import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.testFramework.UsefulTestCase; +import com.intellij.testFramework.EdtTestUtil; import com.jetbrains.python.sdk.InvalidSdkException; import com.jetbrains.python.sdk.PythonSdkAdditionalData; import com.jetbrains.python.sdk.PythonSdkType; import com.jetbrains.python.sdk.flavors.PythonSdkFlavor; import com.jetbrains.python.sdk.skeletons.PySkeletonRefresher; -import com.jetbrains.python.sdk.skeletons.SkeletonVersionChecker; -import org.hamcrest.Matchers; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.junit.Assert; -import java.io.File; import java.io.IOException; -import java.util.List; /** * Engine to create SDK for tests. @@ -58,7 +68,7 @@ public final class PyTestSdkTools { ) throws InvalidSdkException, IOException { final Ref ref = Ref.create(); - UsefulTestCase.edt(() -> { + EdtTestUtil.runInEdtAndWait(() -> { final Sdk sdk = SdkConfigurationUtil.setupSdk(NO_SDK, sdkHome, PythonSdkType.getInstance(), true, null, null); Assert.assertNotNull("Failed to create SDK on " + sdkHome, sdk); ref.set(sdk); @@ -67,13 +77,13 @@ public final class PyTestSdkTools { if (sdkCreationType != SdkCreationType.EMPTY_SDK) { generateTempSkeletonsOrPackages(sdk, sdkCreationType == SdkCreationType.SDK_PACKAGES_AND_SKELETONS, module); } - UsefulTestCase.edt(() -> SdkConfigurationUtil.addSdk(sdk)); + EdtTestUtil.runInEdtAndWait(() -> SdkConfigurationUtil.addSdk(sdk)); return sdk; } /** - * Adds installed eggs to SDK, generates skeletons (optionally) and associates it with modle. + * Adds installed eggs to SDK, generates skeletons (optionally) and associates it with module. * * @param sdk sdk to process * @param addSkeletons add skeletons or only packages @@ -93,7 +103,8 @@ public final class PyTestSdkTools { // Associate with module ModuleRootModificationUtil.setModuleSdk(module, sdk); - UsefulTestCase.edt(() -> ApplicationManager.getApplication().runWriteAction(() -> ProjectRootManager.getInstance(finalProject).setProjectSdk(sdk))); + EdtTestUtil.runInEdtAndWait(() -> ApplicationManager.getApplication() + .runWriteAction(() -> ProjectRootManager.getInstance(finalProject).setProjectSdk(sdk))); } @@ -106,14 +117,14 @@ public final class PyTestSdkTools { addTestSdkRoot(modificator, path); } if (!addSkeletons) { - UsefulTestCase.edt(() -> modificator.commitChanges()); + EdtTestUtil.runInEdtAndWait(modificator::commitChanges); return; } final String skeletonsPath = PythonSdkType.getSkeletonsPath(PathManager.getSystemPath(), sdk.getHomePath()); addTestSdkRoot(modificator, skeletonsPath); - UsefulTestCase.edt(() -> modificator.commitChanges()); + EdtTestUtil.runInEdtAndWait(modificator::commitChanges); PySkeletonRefresher .refreshSkeletonsOfSdk(project, null, skeletonsPath, sdk);