From ceec35bf382f9354ea2265b278e00814f8950430 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Wed, 10 Apr 2019 15:05:54 +0200 Subject: [PATCH] Up merge changes from UsefulTestCase into KtUsefulTestCase --- .../kotlin/test/testFramework/EdtTestUtil.kt | 55 -- .../testFramework/KtPlatformTestUtil.java | 71 -- .../test/testFramework/KtUsefulTestCase.java | 742 +++++++++++++++--- .../GradleMultiplatformHighlightingTest.kt | 2 +- .../gradle/ExternalSystemTestCase.java | 7 +- .../GradleConfiguratorPlatformSpecificTest.kt | 2 +- .../gradle/GradleConfiguratorTest.kt | 2 +- .../codeInsight/gradle/GradleMigrateTest.kt | 2 +- .../codeInsight/gradle/GradleQuickFixTest.kt | 2 +- .../GradleUpdateConfigurationQuickFixTest.kt | 2 +- .../kotlin/idea/maven/MavenMigrateTest.kt | 4 +- .../MavenUpdateConfigurationQuickFixTest.kt | 3 +- .../test/KotlinProjectDescriptorWithFacet.kt | 2 +- 13 files changed, 630 insertions(+), 266 deletions(-) delete mode 100644 compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/EdtTestUtil.kt delete mode 100644 compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtPlatformTestUtil.java diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/EdtTestUtil.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/EdtTestUtil.kt deleted file mode 100644 index cddbc4a41ce..00000000000 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/EdtTestUtil.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2010-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 org.jetbrains.kotlin.test.testFramework - -import com.intellij.mock.MockApplication -import com.intellij.openapi.application.ApplicationManager -import org.jetbrains.annotations.TestOnly -import java.lang.reflect.InvocationTargetException -import javax.swing.SwingUtilities - -class EdtTestUtil { - companion object { - @TestOnly @JvmStatic fun runInEdtAndWait(runnable: Runnable) { - org.jetbrains.kotlin.test.testFramework.runInEdtAndWait { runnable.run() } - } - } -} - - -// Test only because in production you must use Application.invokeAndWait(Runnable, ModalityState). -// The problem is - Application logs errors, but not throws. But in tests must be thrown. -// In any case name "runInEdtAndWait" is better than "invokeAndWait". -@TestOnly -fun runInEdtAndWait(runnable: () -> Unit) { - if (SwingUtilities.isEventDispatchThread()) { - runnable() - } - else { - try { - val application = ApplicationManager.getApplication() - .takeIf { it !is MockApplication } // because MockApplication do nothing instead of `invokeAndWait` - if (application != null) - application.invokeAndWait(runnable) - else - SwingUtilities.invokeAndWait(runnable) - } - catch (e: InvocationTargetException) { - throw e.cause ?: e - } - } -} \ No newline at end of file diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtPlatformTestUtil.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtPlatformTestUtil.java deleted file mode 100644 index eea7c47b0fb..00000000000 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtPlatformTestUtil.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2010-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 org.jetbrains.kotlin.test.testFramework; - -import com.intellij.ide.util.treeView.AbstractTreeNode; -import com.intellij.openapi.ui.Queryable; -import com.intellij.openapi.util.text.StringUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -// Based on com.intellij.testFramework.PlatformTestUtil -public class KtPlatformTestUtil { - @NotNull - public static String getTestName(@NotNull String name, boolean lowercaseFirstLetter) { - name = StringUtil.trimStart(name, "test"); - return StringUtil.isEmpty(name) ? "" : lowercaseFirstLetter(name, lowercaseFirstLetter); - } - - @NotNull - public static String lowercaseFirstLetter(@NotNull String name, boolean lowercaseFirstLetter) { - if (lowercaseFirstLetter && !isAllUppercaseName(name)) { - name = Character.toLowerCase(name.charAt(0)) + name.substring(1); - } - return name; - } - - public static boolean isAllUppercaseName(@NotNull String name) { - int uppercaseChars = 0; - for (int i = 0; i < name.length(); i++) { - if (Character.isLowerCase(name.charAt(i))) { - return false; - } - if (Character.isUpperCase(name.charAt(i))) { - uppercaseChars++; - } - } - return uppercaseChars >= 3; - } - - @Nullable - protected static String toString(@Nullable Object node, @Nullable Queryable.PrintInfo printInfo) { - if (node instanceof AbstractTreeNode) { - if (printInfo != null) { - return ((AbstractTreeNode) node).toTestString(printInfo); - } - else { - @SuppressWarnings({"deprecation", "UnnecessaryLocalVariable"}) String presentation = - ((AbstractTreeNode) node).getTestPresentation(); - return presentation; - } - } - if (node == null) { - return "NULL"; - } - return node.toString(); - } -} \ No newline at end of file diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtUsefulTestCase.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtUsefulTestCase.java index 629ef0f9fee..eb56a647f72 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtUsefulTestCase.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtUsefulTestCase.java @@ -16,33 +16,44 @@ package org.jetbrains.kotlin.test.testFramework; + +import com.intellij.codeInsight.CodeInsightSettings; +import com.intellij.concurrency.IdeaForkJoinWorkerThreadFactory; +import com.intellij.diagnostic.PerformanceWatcher; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.impl.ApplicationInfoImpl; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.io.FileSystemUtil; +import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.CharsetToolkit; +import com.intellij.openapi.vfs.*; +import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.rt.execution.junit.FileComparisonFailure; -import com.intellij.testFramework.TestLoggerFactory; -import com.intellij.testFramework.VfsTestUtil; +import com.intellij.testFramework.*; +import com.intellij.testFramework.exceptionCases.AbstractExceptionCase; +import com.intellij.testFramework.fixtures.IdeaTestExecutionPolicy; +import com.intellij.util.Consumer; import com.intellij.util.ReflectionUtil; import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.PeekableIterator; +import com.intellij.util.containers.PeekableIteratorWrapper; import com.intellij.util.containers.hash.HashMap; +import com.intellij.util.lang.CompoundRuntimeException; import com.intellij.util.ui.UIUtil; +import gnu.trove.Equality; import gnu.trove.THashSet; import junit.framework.AssertionFailedError; import junit.framework.TestCase; +import org.jdom.Element; import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.test.IdeaSystemPropertiesForParallelRunConfigurator; -import org.jetbrains.kotlin.test.KotlinTestUtils; import org.jetbrains.kotlin.testFramework.MockComponentManagerCreationTracer; import org.jetbrains.kotlin.types.FlexibleTypeImpl; import org.jetbrains.kotlin.utils.ExceptionUtilsKt; @@ -51,15 +62,20 @@ import org.junit.Assert; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Supplier; @SuppressWarnings("UseOfSystemOutOrSystemErr") public abstract class KtUsefulTestCase extends TestCase { + public static final boolean IS_UNDER_TEAMCITY = System.getenv("TEAMCITY_VERSION") != null; private static final String TEMP_DIR_MARKER = "unitTest_"; + public static final boolean OVERWRITE_TESTDATA = Boolean.getBoolean("idea.tests.overwrite.data"); private static final String ORIGINAL_TEMP_DIR = FileUtil.getTempDirectory(); @@ -70,6 +86,8 @@ public abstract class KtUsefulTestCase extends TestCase { static { IdeaSystemPropertiesForParallelRunConfigurator.setProperties(); + //TODO: investigate and enable + //IdeaForkJoinWorkerThreadFactory.setupPoisonFactory(); Logger.setFactory(TestLoggerFactory.class); } @@ -88,7 +106,9 @@ public abstract class KtUsefulTestCase extends TestCase { FlexibleTypeImpl.RUN_SLOW_ASSERTIONS = true; } - private boolean oldDisposerDebug; + protected boolean shouldContainTempFiles() { + return true; + } @Override protected void setUp() throws Exception { @@ -100,47 +120,64 @@ public abstract class KtUsefulTestCase extends TestCase { super.setUp(); - String testName = FileUtil.sanitizeFileName(getTestName(true)); - if (StringUtil.isEmptyOrSpaces(testName)) testName = ""; - testName = new File(testName).getName(); // in case the test name contains file separators - myTempDir = FileUtil.createTempDirectory(TEMP_DIR_MARKER, testName, false); - FileUtil.resetCanonicalTempPathCache(myTempDir.getPath()); + if (shouldContainTempFiles()) { + IdeaTestExecutionPolicy policy = IdeaTestExecutionPolicy.current(); + String testName = null; + if (policy != null) { + testName = policy.getPerTestTempDirName(); + } + if (testName == null) { + testName = FileUtil.sanitizeFileName(getTestName(true)); + } + testName = new File(testName).getName(); // in case the test name contains file separators + myTempDir = FileUtil.createTempDirectory(TEMP_DIR_MARKER, testName, false); + FileUtil.resetCanonicalTempPathCache(myTempDir.getPath()); + } boolean isStressTest = isStressTest(); ApplicationInfoImpl.setInStressTest(isStressTest); + if (isPerformanceTest()) { + Timings.getStatistics(); + } // turn off Disposer debugging for performance tests - oldDisposerDebug = Disposer.setDebugMode(Disposer.isDebugMode() && !isStressTest); + Disposer.setDebugMode(!isStressTest); } @Override protected void tearDown() throws Exception { try { - Disposer.dispose(myTestRootDisposable); - cleanupSwingDataStructures(); - cleanupDeleteOnExitHookList(); + // don't use method references here to make stack trace reading easier + //noinspection Convert2MethodRef + new RunAll( + () -> disposeRootDisposable(), + () -> cleanupSwingDataStructures(), + () -> cleanupDeleteOnExitHookList(), + () -> Disposer.setDebugMode(true), + () -> { + if (shouldContainTempFiles()) { + FileUtil.resetCanonicalTempPathCache(ORIGINAL_TEMP_DIR); + if (hasTmpFilesToKeep()) { + File[] files = myTempDir.listFiles(); + if (files != null) { + for (File file : files) { + if (!shouldKeepTmpFile(file)) { + FileUtil.delete(file); + } + } + } + } + else { + FileUtil.delete(myTempDir); + } + } + }, + () -> UIUtil.removeLeakingAppleListeners() + ).run(); } finally { - Disposer.setDebugMode(oldDisposerDebug); - FileUtil.resetCanonicalTempPathCache(ORIGINAL_TEMP_DIR); - if (hasTmpFilesToKeep()) { - File[] files = myTempDir.listFiles(); - if (files != null) { - for (File file : files) { - if (!shouldKeepTmpFile(file)) { - FileUtil.delete(file); - } - } - } - } else { - FileUtil.delete(myTempDir); - } + super.tearDown(); + resetApplicationToNull(application); + application = null; } - - UIUtil.removeLeakingAppleListeners(); - super.tearDown(); - - resetApplicationToNull(application); - - application = null; } public static void resetApplicationToNull(Application old) { @@ -159,11 +196,20 @@ public abstract class KtUsefulTestCase extends TestCase { } } - private boolean hasTmpFilesToKeep() { - return !myPathsToKeep.isEmpty(); + + protected final void disposeRootDisposable() { + Disposer.dispose(getTestRootDisposable()); } - private boolean shouldKeepTmpFile(File file) { + protected void addTmpFileToKeep(@NotNull File file) { + myPathsToKeep.add(file.getPath()); + } + + private boolean hasTmpFilesToKeep() { + return ourPathToKeep != null && FileUtil.isAncestor(myTempDir.getPath(), ourPathToKeep, false) || !myPathsToKeep.isEmpty(); + } + + private boolean shouldKeepTmpFile(@NotNull File file) { String path = file.getPath(); if (FileUtil.pathsEqual(path, ourPathToKeep)) return true; for (String pathToKeep : myPathsToKeep) { @@ -182,13 +228,13 @@ public abstract class KtUsefulTestCase extends TestCase { catch (Exception e) { throw new RuntimeException(e); } - @SuppressWarnings("unchecked") - Set files = ReflectionUtil.getStaticFieldValue(aClass, Set.class, "files"); + @SuppressWarnings("unchecked") Set files = ReflectionUtil.getStaticFieldValue(aClass, Set.class, "files"); DELETE_ON_EXIT_HOOK_CLASS = aClass; DELETE_ON_EXIT_HOOK_DOT_FILES = files; } - private static void cleanupDeleteOnExitHookList() throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException { + @SuppressWarnings("SynchronizeOnThis") + private static void cleanupDeleteOnExitHookList() { // try to reduce file set retained by java.io.DeleteOnExitHook List list; synchronized (DELETE_ON_EXIT_HOOK_CLASS) { @@ -197,7 +243,8 @@ public abstract class KtUsefulTestCase extends TestCase { } for (int i = list.size() - 1; i >= 0; i--) { String path = list.get(i); - if (FileSystemUtil.getAttributes(path) == null || new File(path).delete()) { + File file = new File(path); + if (file.delete() || !file.exists()) { synchronized (DELETE_ON_EXIT_HOOK_CLASS) { DELETE_ON_EXIT_HOOK_DOT_FILES.remove(path); } @@ -205,6 +252,7 @@ public abstract class KtUsefulTestCase extends TestCase { } } + @SuppressWarnings("ConstantConditions") private static void cleanupSwingDataStructures() throws Exception { Object manager = ReflectionUtil.getDeclaredMethod(Class.forName("javax.swing.KeyboardManager"), "getCurrentManager").invoke(null); Map componentKeyStrokeMap = ReflectionUtil.getField(manager.getClass(), manager, Hashtable.class, "componentKeyStrokeMap"); @@ -214,29 +262,34 @@ public abstract class KtUsefulTestCase extends TestCase { } @NotNull - public final Disposable getTestRootDisposable() { + public Disposable getTestRootDisposable() { return myTestRootDisposable; } @Override protected void runTest() throws Throwable { - Throwable[] throwables = new Throwable[1]; + final Throwable[] throwables = new Throwable[1]; AtomicBoolean completed = new AtomicBoolean(false); Runnable runnable = () -> { try { + TestLoggerFactory.onTestStarted(); super.runTest(); + TestLoggerFactory.onTestFinished(true); completed.set(true); } catch (InvocationTargetException e) { + TestLoggerFactory.onTestFinished(false); e.fillInStackTrace(); throwables[0] = e.getTargetException(); } catch (IllegalAccessException e) { + TestLoggerFactory.onTestFinished(false); e.fillInStackTrace(); throwables[0] = e; } catch (Throwable e) { + TestLoggerFactory.onTestFinished(false); throwables[0] = e; } }; @@ -251,8 +304,21 @@ public abstract class KtUsefulTestCase extends TestCase { } } - private static void invokeTestRunnable(@NotNull Runnable runnable) throws Exception { - EdtTestUtil.runInEdtAndWait(runnable); + protected boolean shouldRunTest() { + return TestFrameworkUtil.canRunTest(getClass()); + } + + protected void invokeTestRunnable(@NotNull Runnable runnable) throws Exception { + IdeaTestExecutionPolicy policy = IdeaTestExecutionPolicy.current(); + if (policy != null && !policy.runInDispatchThread()) { + runnable.run(); + } + else { + EdtTestUtilKt.runInEdtAndWait(() -> { + runnable.run(); + return null; + }); + } } private void defaultRunBare() throws Throwable { @@ -264,10 +330,8 @@ public abstract class KtUsefulTestCase extends TestCase { logPerClassCost(setupCost, TOTAL_SETUP_COST_MILLIS); runTest(); - TestLoggerFactory.onTestFinished(true); } catch (Throwable running) { - TestLoggerFactory.onTestFinished(false); exception = running; } finally { @@ -279,6 +343,7 @@ public abstract class KtUsefulTestCase extends TestCase { } catch (Throwable tearingDown) { if (exception == null) exception = tearingDown; + else exception = new CompoundRuntimeException(Arrays.asList(exception, tearingDown)); } } if (exception != null) throw exception; @@ -289,95 +354,235 @@ public abstract class KtUsefulTestCase extends TestCase { * * @param cost setup cost in milliseconds */ - private void logPerClassCost(long cost, Map costMap) { + private void logPerClassCost(long cost, @NotNull Map costMap) { Class superclass = getClass().getSuperclass(); Long oldCost = costMap.get(superclass.getName()); long newCost = oldCost == null ? cost : oldCost + cost; costMap.put(superclass.getName(), newCost); } - @Override - public void runBare() throws Throwable { - this.defaultRunBare(); + @SuppressWarnings("UseOfSystemOutOrSystemErr") + static void logSetupTeardownCosts() { + System.out.println("Setup costs"); + long totalSetup = 0; + for (Map.Entry entry : TOTAL_SETUP_COST_MILLIS.entrySet()) { + System.out.println(String.format(" %s: %d ms", entry.getKey(), entry.getValue())); + totalSetup += entry.getValue(); + } + System.out.println("Teardown costs"); + long totalTeardown = 0; + for (Map.Entry entry : TOTAL_TEARDOWN_COST_MILLIS.entrySet()) { + System.out.println(String.format(" %s: %d ms", entry.getKey(), entry.getValue())); + totalTeardown += entry.getValue(); + } + System.out.println(String.format("Total overhead: setup %d ms, teardown %d ms", totalSetup, totalTeardown)); + System.out.println(String.format("##teamcity[buildStatisticValue key='ideaTests.totalSetupMs' value='%d']", totalSetup)); + System.out.println(String.format("##teamcity[buildStatisticValue key='ideaTests.totalTeardownMs' value='%d']", totalTeardown)); } - @NonNls - public static String toString(Iterable collection) { + @Override + public void runBare() throws Throwable { + if (!shouldRunTest()) return; + + if (runInDispatchThread()) { + TestRunnerUtil.replaceIdeEventQueueSafely(); + com.intellij.testFramework.EdtTestUtil.runInEdtAndWait(this::defaultRunBare); + } + else { + defaultRunBare(); + } + } + + protected boolean runInDispatchThread() { + IdeaTestExecutionPolicy policy = IdeaTestExecutionPolicy.current(); + if (policy != null) { + return policy.runInDispatchThread(); + } + return true; + } + + @NotNull + public static String toString(@NotNull Iterable collection) { if (!collection.iterator().hasNext()) { return ""; } - StringBuilder builder = new StringBuilder(); - for (Object o : collection) { + final StringBuilder builder = new StringBuilder(); + for (final Object o : collection) { if (o instanceof THashSet) { - @SuppressWarnings("unchecked") - Set set = new TreeSet((THashSet) o); - builder.append(set); + builder.append(new TreeSet<>((THashSet)o)); } else { builder.append(o); } - builder.append("\n"); + builder.append('\n'); } return builder.toString(); } @SafeVarargs - private static void assertOrderedEquals(String errorMsg, @NotNull Iterable actual, @NotNull T... expected) { - Assert.assertNotNull(actual); - Assert.assertNotNull(expected); + public static void assertOrderedEquals(@NotNull T[] actual, @NotNull T... expected) { + assertOrderedEquals(Arrays.asList(actual), expected); + } + + @SafeVarargs + public static void assertOrderedEquals(@NotNull Iterable actual, @NotNull T... expected) { + assertOrderedEquals("", actual, expected); + } + + public static void assertOrderedEquals(@NotNull byte[] actual, @NotNull byte[] expected) { + assertEquals(expected.length, actual.length); + for (int i = 0; i < actual.length; i++) { + byte a = actual[i]; + byte e = expected[i]; + assertEquals("not equals at index: "+i, e, a); + } + } + + public static void assertOrderedEquals(@NotNull int[] actual, @NotNull int[] expected) { + if (actual.length != expected.length) { + fail("Expected size: "+expected.length+"; actual: "+actual.length+"\nexpected: "+Arrays.toString(expected)+"\nactual : "+Arrays.toString(actual)); + } + for (int i = 0; i < actual.length; i++) { + int a = actual[i]; + int e = expected[i]; + assertEquals("not equals at index: "+i, e, a); + } + } + + @SafeVarargs + public static void assertOrderedEquals(@NotNull String errorMsg, @NotNull Iterable actual, @NotNull T... expected) { assertOrderedEquals(errorMsg, actual, Arrays.asList(expected)); } - public static void assertOrderedEquals( - String erroMsg, - Iterable actual, - Collection expected) { - ArrayList list = new ArrayList<>(); - for (T t : actual) { - list.add(t); - } - if (!list.equals(new ArrayList(expected))) { + public static void assertOrderedEquals(@NotNull Iterable actual, @NotNull Iterable expected) { + assertOrderedEquals("", actual, expected); + } + + public static void assertOrderedEquals(@NotNull String errorMsg, + @NotNull Iterable actual, + @NotNull Iterable expected) { + //noinspection unchecked + assertOrderedEquals(errorMsg, actual, expected, Equality.CANONICAL); + } + + public static void assertOrderedEquals(@NotNull String errorMsg, + @NotNull Iterable actual, + @NotNull Iterable expected, + @NotNull Equality comparator) { + if (!equals(actual, expected, comparator)) { String expectedString = toString(expected); String actualString = toString(actual); - Assert.assertEquals(erroMsg, expectedString, actualString); + Assert.assertEquals(errorMsg, expectedString, actualString); Assert.fail("Warning! 'toString' does not reflect the difference.\nExpected: " + expectedString + "\nActual: " + actualString); } } - @SafeVarargs - public static void assertSameElements(T[] collection, T... expected) { - assertSameElements(Arrays.asList(collection), expected); + private static boolean equals(@NotNull Iterable a1, + @NotNull Iterable a2, + @NotNull Equality comparator) { + Iterator it1 = a1.iterator(); + Iterator it2 = a2.iterator(); + while (it1.hasNext() || it2.hasNext()) { + if (!it1.hasNext() || !it2.hasNext()) return false; + if (!comparator.equals(it1.next(), it2.next())) return false; + } + return true; } @SafeVarargs - public static void assertSameElements(Collection collection, T... expected) { - assertSameElements(collection, Arrays.asList(expected)); + public static void assertOrderedCollection(@NotNull T[] collection, @NotNull Consumer... checkers) { + assertOrderedCollection(Arrays.asList(collection), checkers); } - public static void assertSameElements(Collection collection, Collection expected) { - assertSameElements(null, collection, expected); + /** + * Checks {@code actual} contains same elements (in {@link #equals(Object)} meaning) as {@code expected} irrespective of their order + */ + @SafeVarargs + public static void assertSameElements(@NotNull T[] actual, @NotNull T... expected) { + assertSameElements(Arrays.asList(actual), expected); } - public static void assertSameElements(String message, Collection collection, Collection expected) { - assertNotNull(collection); - assertNotNull(expected); - if (collection.size() != expected.size() || !new HashSet<>(expected).equals(new HashSet(collection))) { - Assert.assertEquals(message, toString(expected, "\n"), toString(collection, "\n")); - Assert.assertEquals(message, new HashSet<>(expected), new HashSet(collection)); + /** + * Checks {@code actual} contains same elements (in {@link #equals(Object)} meaning) as {@code expected} irrespective of their order + */ + @SafeVarargs + public static void assertSameElements(@NotNull Collection actual, @NotNull T... expected) { + assertSameElements(actual, Arrays.asList(expected)); + } + + /** + * Checks {@code actual} contains same elements (in {@link #equals(Object)} meaning) as {@code expected} irrespective of their order + */ + public static void assertSameElements(@NotNull Collection actual, @NotNull Collection expected) { + assertSameElements("", actual, expected); + } + + /** + * Checks {@code actual} contains same elements (in {@link #equals(Object)} meaning) as {@code expected} irrespective of their order + */ + public static void assertSameElements(@NotNull String message, @NotNull Collection actual, @NotNull Collection expected) { + if (actual.size() != expected.size() || !new HashSet<>(expected).equals(new HashSet(actual))) { + Assert.assertEquals(message, new HashSet<>(expected), new HashSet(actual)); } } - public static String toString(Object[] collection, String separator) { + @SafeVarargs + public static void assertContainsOrdered(@NotNull Collection collection, @NotNull T... expected) { + assertContainsOrdered(collection, Arrays.asList(expected)); + } + + public static void assertContainsOrdered(@NotNull Collection collection, @NotNull Collection expected) { + PeekableIterator expectedIt = new PeekableIteratorWrapper<>(expected.iterator()); + PeekableIterator actualIt = new PeekableIteratorWrapper<>(collection.iterator()); + + while (actualIt.hasNext() && expectedIt.hasNext()) { + T expectedElem = expectedIt.peek(); + T actualElem = actualIt.peek(); + if (expectedElem.equals(actualElem)) { + expectedIt.next(); + } + actualIt.next(); + } + if (expectedIt.hasNext()) { + throw new ComparisonFailure("", toString(expected), toString(collection)); + } + } + + @SafeVarargs + public static void assertContainsElements(@NotNull Collection collection, @NotNull T... expected) { + assertContainsElements(collection, Arrays.asList(expected)); + } + + public static void assertContainsElements(@NotNull Collection collection, @NotNull Collection expected) { + ArrayList copy = new ArrayList<>(collection); + copy.retainAll(expected); + assertSameElements(toString(collection), copy, expected); + } + + @NotNull + public static String toString(@NotNull Object[] collection, @NotNull String separator) { return toString(Arrays.asList(collection), separator); } - public static String toString(Collection collection, String separator) { + @SafeVarargs + public static void assertDoesntContain(@NotNull Collection collection, @NotNull T... notExpected) { + assertDoesntContain(collection, Arrays.asList(notExpected)); + } + + public static void assertDoesntContain(@NotNull Collection collection, @NotNull Collection notExpected) { + ArrayList expected = new ArrayList<>(collection); + expected.removeAll(notExpected); + assertSameElements(collection, expected); + } + + @NotNull + public static String toString(@NotNull Collection collection, @NotNull String separator) { List list = ContainerUtil.map2List(collection, String::valueOf); Collections.sort(list); StringBuilder builder = new StringBuilder(); boolean flag = false; - for (String o : list) { + for (final String o : list) { if (flag) { builder.append(separator); } @@ -387,55 +592,210 @@ public abstract class KtUsefulTestCase extends TestCase { return builder.toString(); } + @SafeVarargs + public static void assertOrderedCollection(@NotNull Collection collection, @NotNull Consumer... checkers) { + if (collection.size() != checkers.length) { + Assert.fail(toString(collection)); + } + int i = 0; + for (final T actual : collection) { + try { + checkers[i].consume(actual); + } + catch (AssertionFailedError e) { + //noinspection UseOfSystemOutOrSystemErr + System.out.println(i + ": " + actual); + throw e; + } + i++; + } + } + + @SafeVarargs + public static void assertUnorderedCollection(@NotNull T[] collection, @NotNull Consumer... checkers) { + assertUnorderedCollection(Arrays.asList(collection), checkers); + } + + @SafeVarargs + public static void assertUnorderedCollection(@NotNull Collection collection, @NotNull Consumer... checkers) { + if (collection.size() != checkers.length) { + Assert.fail(toString(collection)); + } + Set> checkerSet = new HashSet<>(Arrays.asList(checkers)); + int i = 0; + Throwable lastError = null; + for (final T actual : collection) { + boolean flag = true; + for (final Consumer condition : checkerSet) { + Throwable error = accepts(condition, actual); + if (error == null) { + checkerSet.remove(condition); + flag = false; + break; + } + else { + lastError = error; + } + } + if (flag) { + //noinspection ConstantConditions,CallToPrintStackTrace + lastError.printStackTrace(); + Assert.fail("Incorrect element(" + i + "): " + actual); + } + i++; + } + } + + private static Throwable accepts(@NotNull Consumer condition, final T actual) { + try { + condition.consume(actual); + return null; + } + catch (Throwable e) { + return e; + } + } + @Contract("null, _ -> fail") - public static T assertInstanceOf(Object o, Class aClass) { + @NotNull + public static T assertInstanceOf(Object o, @NotNull Class aClass) { Assert.assertNotNull("Expected instance of: " + aClass.getName() + " actual: " + null, o); Assert.assertTrue("Expected instance of: " + aClass.getName() + " actual: " + o.getClass().getName(), aClass.isInstance(o)); @SuppressWarnings("unchecked") T t = (T)o; return t; } - protected static void assertEmpty(String errorMsg, Collection collection) { - assertOrderedEquals(errorMsg, collection); + public static T assertOneElement(@NotNull Collection collection) { + Iterator iterator = collection.iterator(); + String toString = toString(collection); + Assert.assertTrue(toString, iterator.hasNext()); + T t = iterator.next(); + Assert.assertFalse(toString, iterator.hasNext()); + return t; } - protected static void assertSize(int expectedSize, Object[] array) { - assertEquals(toString(Arrays.asList(array)), expectedSize, array.length); + public static T assertOneElement(@NotNull T[] ts) { + Assert.assertEquals(Arrays.asList(ts).toString(), 1, ts.length); + return ts[0]; } - public static void assertSameLines(String expected, String actual) { + @SafeVarargs + public static void assertOneOf(T value, @NotNull T... values) { + for (T v : values) { + if (Objects.equals(value, v)) { + return; + } + } + Assert.fail(value + " should be equal to one of " + Arrays.toString(values)); + } + + public static void printThreadDump() { + PerformanceWatcher.dumpThreadsToConsole("Thread dump:"); + } + + public static void assertEmpty(@NotNull Object[] array) { + assertOrderedEquals(array); + } + + public static void assertNotEmpty(final Collection collection) { + assertNotNull(collection); + assertFalse(collection.isEmpty()); + } + + public static void assertEmpty(@NotNull Collection collection) { + assertEmpty(collection.toString(), collection); + } + + public static void assertNullOrEmpty(@Nullable Collection collection) { + if (collection == null) return; + assertEmpty("", collection); + } + + public static void assertEmpty(final String s) { + assertTrue(s, StringUtil.isEmpty(s)); + } + + public static void assertEmpty(@NotNull String errorMsg, @NotNull Collection collection) { + assertOrderedEquals(errorMsg, collection, Collections.emptyList()); + } + + public static void assertSize(int expectedSize, @NotNull Object[] array) { + if (array.length != expectedSize) { + assertEquals(toString(Arrays.asList(array)), expectedSize, array.length); + } + } + + public static void assertSize(int expectedSize, @NotNull Collection c) { + if (c.size() != expectedSize) { + assertEquals(toString(c), expectedSize, c.size()); + } + } + + @NotNull + protected T disposeOnTearDown(@NotNull T disposable) { + Disposer.register(getTestRootDisposable(), disposable); + return disposable; + } + + public static void assertSameLines(@NotNull String expected, @NotNull String actual) { + assertSameLines(null, expected, actual); + } + + public static void assertSameLines(@Nullable String message, @NotNull String expected, @NotNull String actual) { String expectedText = StringUtil.convertLineSeparators(expected.trim()); String actualText = StringUtil.convertLineSeparators(actual.trim()); - Assert.assertEquals(expectedText, actualText); + Assert.assertEquals(message, expectedText, actualText); } + public static void assertExists(@NotNull File file){ + assertTrue("File should exist " + file, file.exists()); + } + + public static void assertDoesntExist(@NotNull File file){ + assertFalse("File should not exist " + file, file.exists()); + } + + @NotNull protected String getTestName(boolean lowercaseFirstLetter) { return getTestName(getName(), lowercaseFirstLetter); } - public static String getTestName(String name, boolean lowercaseFirstLetter) { - return name == null ? "" : KtPlatformTestUtil.getTestName(name, lowercaseFirstLetter); + @NotNull + public static String getTestName(@Nullable String name, boolean lowercaseFirstLetter) { + return name == null ? "" : PlatformTestUtil.getTestName(name, lowercaseFirstLetter); } - /** @deprecated use {@link KtPlatformTestUtil#lowercaseFirstLetter(String, boolean)} (to be removed in IDEA 17) */ - @SuppressWarnings("unused") - public static String lowercaseFirstLetter(String name, boolean lowercaseFirstLetter) { - return KtPlatformTestUtil.lowercaseFirstLetter(name, lowercaseFirstLetter); + @NotNull + protected String getTestDirectoryName() { + final String testName = getTestName(true); + return testName.replaceAll("_.*", ""); } - /** @deprecated use {@link KtPlatformTestUtil#isAllUppercaseName(String)} (to be removed in IDEA 17) */ - @SuppressWarnings("unused") - public static boolean isAllUppercaseName(String name) { - return KtPlatformTestUtil.isAllUppercaseName(name); - } - - public static void assertSameLinesWithFile(String filePath, String actualText) { + public static void assertSameLinesWithFile(@NotNull String filePath, @NotNull String actualText) { assertSameLinesWithFile(filePath, actualText, true); } - public static void assertSameLinesWithFile(String filePath, String actualText, boolean trimBeforeComparing) { + public static void assertSameLinesWithFile(@NotNull String filePath, + @NotNull String actualText, + @NotNull Supplier messageProducer) { + assertSameLinesWithFile(filePath, actualText, true, messageProducer); + } + + public static void assertSameLinesWithFile(@NotNull String filePath, @NotNull String actualText, boolean trimBeforeComparing) { + assertSameLinesWithFile(filePath, actualText, trimBeforeComparing, null); + } + + public static void assertSameLinesWithFile(@NotNull String filePath, + @NotNull String actualText, + boolean trimBeforeComparing, + @Nullable Supplier messageProducer) { String fileText; try { + if (OVERWRITE_TESTDATA) { + VfsTestUtil.overwriteTestData(filePath, actualText); + //noinspection UseOfSystemOutOrSystemErr + System.out.println("File " + filePath + " created."); + } fileText = FileUtil.loadFile(new File(filePath), CharsetToolkit.UTF8_CHARSET); } catch (FileNotFoundException e) { @@ -448,11 +808,11 @@ public abstract class KtUsefulTestCase extends TestCase { String expected = StringUtil.convertLineSeparators(trimBeforeComparing ? fileText.trim() : fileText); String actual = StringUtil.convertLineSeparators(trimBeforeComparing ? actualText.trim() : actualText); if (!Comparing.equal(expected, actual)) { - throw new FileComparisonFailure(null, expected, actual, filePath); + throw new FileComparisonFailure(messageProducer == null ? null : messageProducer.get(), expected, actual, filePath); } } - public static void clearFields(Object test) throws IllegalAccessException { + protected static void clearFields(@NotNull Object test) throws IllegalAccessException { Class aClass = test.getClass(); while (aClass != null) { clearDeclaredFields(test, aClass); @@ -460,12 +820,11 @@ public abstract class KtUsefulTestCase extends TestCase { } } - private static void clearDeclaredFields(Object test, Class aClass) throws IllegalAccessException { - if (aClass == null) return; - for (Field field : aClass.getDeclaredFields()) { - @NonNls String name = field.getDeclaringClass().getName(); + public static void clearDeclaredFields(@NotNull Object test, @NotNull Class aClass) throws IllegalAccessException { + for (final Field field : aClass.getDeclaredFields()) { + final String name = field.getDeclaringClass().getName(); if (!name.startsWith("junit.framework.") && !name.startsWith("com.intellij.testFramework.")) { - int modifiers = field.getModifiers(); + final int modifiers = field.getModifiers(); if ((modifiers & Modifier.FINAL) == 0 && (modifiers & Modifier.STATIC) == 0 && !field.getType().isPrimitive()) { field.setAccessible(true); field.set(test, null); @@ -474,9 +833,23 @@ public abstract class KtUsefulTestCase extends TestCase { } } - private static boolean isPerformanceTest(@Nullable String testName, @Nullable String className) { - return testName != null && testName.contains("Performance") || - className != null && className.contains("Performance"); + private static void checkCodeStyleSettingsEqual(@NotNull CodeStyleSettings expected, @NotNull CodeStyleSettings settings) { + if (!expected.equals(settings)) { + Element oldS = new Element("temp"); + expected.writeExternal(oldS); + Element newS = new Element("temp"); + settings.writeExternal(newS); + + String newString = JDOMUtil.writeElement(newS); + String oldString = JDOMUtil.writeElement(oldS); + Assert.assertEquals("Code style settings damaged", oldString, newString); + } + } + + public boolean isPerformanceTest() { + String testName = getName(); + String className = getClass().getSimpleName(); + return TestFrameworkUtil.isPerformanceTest(testName, className); } /** @@ -485,13 +858,12 @@ public abstract class KtUsefulTestCase extends TestCase { * If you want your test to be treated as "Stress", please mention one of these words in its name: "Stress", "Slow". * For example: {@code public void testStressPSIFromDifferentThreads()} */ - - private boolean isStressTest() { + public boolean isStressTest() { return isStressTest(getName(), getClass().getName()); } private static boolean isStressTest(String testName, String className) { - return isPerformanceTest(testName, className) || + return TestFrameworkUtil.isPerformanceTest(testName, className) || containsStressWords(testName) || containsStressWords(className); } @@ -501,9 +873,127 @@ public abstract class KtUsefulTestCase extends TestCase { } - public class TestDisposable implements Disposable { + /** + * Checks that code block throw corresponding exception with expected error msg. + * If expected error message is null it will not be checked. + * + * @param exceptionCase Block annotated with some exception type + * @param expectedErrorMsg expected error message + */ + protected void assertException(@NotNull AbstractExceptionCase exceptionCase, @Nullable String expectedErrorMsg) { + //noinspection unchecked + assertExceptionOccurred(true, exceptionCase, expectedErrorMsg); + } + + /** + * Checks that code block doesn't throw corresponding exception. + * + * @param exceptionCase Block annotated with some exception type + */ + protected void assertNoException(@NotNull AbstractExceptionCase exceptionCase) throws T { + assertExceptionOccurred(false, exceptionCase, null); + } + + protected void assertNoThrowable(@NotNull Runnable closure) { + String throwableName = null; + try { + closure.run(); + } + catch (Throwable thr) { + throwableName = thr.getClass().getName(); + } + assertNull(throwableName); + } + + private static void assertExceptionOccurred(boolean shouldOccur, + @NotNull AbstractExceptionCase exceptionCase, + String expectedErrorMsg) throws T { + boolean wasThrown = false; + try { + exceptionCase.tryClosure(); + } + catch (Throwable e) { + if (shouldOccur) { + wasThrown = true; + final String errorMessage = exceptionCase.getAssertionErrorMessage(); + assertEquals(errorMessage, exceptionCase.getExpectedExceptionClass(), e.getClass()); + if (expectedErrorMsg != null) { + assertEquals("Compare error messages", expectedErrorMsg, e.getMessage()); + } + } + else if (exceptionCase.getExpectedExceptionClass().equals(e.getClass())) { + wasThrown = true; + + //noinspection UseOfSystemOutOrSystemErr + System.out.println(); + //noinspection UseOfSystemOutOrSystemErr + e.printStackTrace(System.out); + + fail("Exception isn't expected here. Exception message: " + e.getMessage()); + } + else { + throw e; + } + } + finally { + if (shouldOccur && !wasThrown) { + fail(exceptionCase.getAssertionErrorMessage()); + } + } + } + + protected boolean annotatedWith(@NotNull Class annotationClass) { + Class aClass = getClass(); + String methodName = "test" + getTestName(false); + boolean methodChecked = false; + while (aClass != null && aClass != Object.class) { + if (aClass.getAnnotation(annotationClass) != null) return true; + if (!methodChecked) { + Method method = ReflectionUtil.getDeclaredMethod(aClass, methodName); + if (method != null) { + if (method.getAnnotation(annotationClass) != null) return true; + methodChecked = true; + } + } + aClass = aClass.getSuperclass(); + } + return false; + } + + @NotNull + protected String getHomePath() { + return PathManager.getHomePath().replace(File.separatorChar, '/'); + } + + public static void refreshRecursively(@NotNull VirtualFile file) { + VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() { + @Override + public boolean visitFile(@NotNull VirtualFile file) { + file.getChildren(); + return true; + } + }); + file.refresh(false, true); + } + + @Nullable + public static VirtualFile refreshAndFindFile(@NotNull final File file) { + return UIUtil.invokeAndWaitIfNeeded(() -> LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file)); + } + + protected class TestDisposable implements Disposable { + private volatile boolean myDisposed; + + public TestDisposable() { + } + @Override public void dispose() { + myDisposed = true; + } + + public boolean isDisposed() { + return myDisposed; } @Override diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/GradleMultiplatformHighlightingTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/GradleMultiplatformHighlightingTest.kt index 373401222ad..148bb29f242 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/GradleMultiplatformHighlightingTest.kt +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/GradleMultiplatformHighlightingTest.kt @@ -16,8 +16,8 @@ import com.intellij.openapi.fileEditor.OpenFileDescriptor import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiDocumentManager +import com.intellij.testFramework.runInEdtAndWait import org.jetbrains.kotlin.idea.codeInsight.gradle.GradleImportingTestCase -import org.jetbrains.kotlin.test.testFramework.runInEdtAndWait import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions import org.junit.Assert import org.junit.Test diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCase.java b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCase.java index c8d661bad35..9aca849b09a 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCase.java +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/ExternalSystemTestCase.java @@ -51,7 +51,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import static org.jetbrains.kotlin.test.testFramework.EdtTestUtil.runInEdtAndWait; +import static com.intellij.testFramework.EdtTestUtilKt.runInEdtAndWait; // part of com.intellij.openapi.externalSystem.test.ExternalSystemTestCase public abstract class ExternalSystemTestCase extends UsefulTestCase { @@ -204,7 +204,10 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase { @Override protected void invokeTestRunnable(@NotNull Runnable runnable) throws Exception { - runInEdtAndWait(runnable); + runInEdtAndWait(() -> { + runnable.run(); + return null; + }); } protected static String getRoot() { diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleConfiguratorPlatformSpecificTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleConfiguratorPlatformSpecificTest.kt index d25c5e28a46..f3dd19321e7 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleConfiguratorPlatformSpecificTest.kt +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleConfiguratorPlatformSpecificTest.kt @@ -5,10 +5,10 @@ package org.jetbrains.kotlin.idea.codeInsight.gradle +import com.intellij.testFramework.runInEdtAndWait import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.idea.configuration.KotlinWithGradleConfigurator import org.jetbrains.kotlin.idea.util.application.executeWriteCommand -import org.jetbrains.kotlin.test.testFramework.runInEdtAndWait import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions import org.junit.Test diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleConfiguratorTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleConfiguratorTest.kt index 1d8d77e265f..cdbdb3a75dd 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleConfiguratorTest.kt +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleConfiguratorTest.kt @@ -9,11 +9,11 @@ import com.intellij.openapi.extensions.Extensions import com.intellij.openapi.module.ModuleManager import com.intellij.openapi.roots.DependencyScope import com.intellij.openapi.roots.ExternalLibraryDescriptor +import com.intellij.testFramework.runInEdtAndWait import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.idea.configuration.* import org.jetbrains.kotlin.idea.util.application.executeWriteCommand import org.jetbrains.kotlin.idea.util.application.runReadAction -import org.jetbrains.kotlin.test.testFramework.runInEdtAndWait import org.jetbrains.kotlin.test.testFramework.runWriteAction import org.jetbrains.plugins.gradle.execution.test.runner.GradleTestRunConfigurationProducer import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleMigrateTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleMigrateTest.kt index 2731108d2df..e408595bcd4 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleMigrateTest.kt +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleMigrateTest.kt @@ -9,13 +9,13 @@ import com.intellij.openapi.application.runReadAction import com.intellij.openapi.application.runWriteAction import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiManager +import com.intellij.testFramework.runInEdtAndWait import com.intellij.util.concurrency.FutureResult import org.jetbrains.kotlin.config.ApiVersion import org.jetbrains.kotlin.config.LanguageVersion import org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent import org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent.MigrationTestState import org.jetbrains.kotlin.idea.configuration.MigrationInfo -import org.jetbrains.kotlin.test.testFramework.runInEdtAndWait import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions import org.junit.Assert import org.junit.Test diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleQuickFixTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleQuickFixTest.kt index 5b168ecd864..8aab79429d4 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleQuickFixTest.kt +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleQuickFixTest.kt @@ -13,11 +13,11 @@ import com.intellij.openapi.fileEditor.impl.LoadTextUtil import com.intellij.openapi.vfs.VirtualFile import com.intellij.testFramework.fixtures.CodeInsightTestFixture import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory +import com.intellij.testFramework.runInEdtAndWait import org.jetbrains.kotlin.idea.inspections.gradle.GradleKotlinxCoroutinesDeprecationInspection import org.jetbrains.kotlin.idea.inspections.runInspection import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.test.KotlinTestUtils -import org.jetbrains.kotlin.test.testFramework.runInEdtAndWait import org.junit.Test import java.io.File import kotlin.reflect.KMutableProperty0 diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleUpdateConfigurationQuickFixTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleUpdateConfigurationQuickFixTest.kt index a74854b18fa..e4da618272f 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleUpdateConfigurationQuickFixTest.kt +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleUpdateConfigurationQuickFixTest.kt @@ -23,8 +23,8 @@ import com.intellij.openapi.vfs.VirtualFile import com.intellij.rt.execution.junit.FileComparisonFailure import com.intellij.testFramework.fixtures.CodeInsightTestFixture import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory +import com.intellij.testFramework.runInEdtAndWait import org.jetbrains.kotlin.idea.test.PluginTestCaseBase -import org.jetbrains.kotlin.test.testFramework.runInEdtAndWait import org.junit.Test import java.io.File import kotlin.reflect.KMutableProperty0 diff --git a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenMigrateTest.kt b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenMigrateTest.kt index 00c50325bd7..ce9d1d8c169 100644 --- a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenMigrateTest.kt +++ b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenMigrateTest.kt @@ -9,15 +9,13 @@ import com.intellij.openapi.application.runReadAction import com.intellij.openapi.application.runWriteAction import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiManager -import com.intellij.testFramework.TestDataPath +import com.intellij.testFramework.runInEdtAndWait import com.intellij.util.concurrency.FutureResult import org.jetbrains.kotlin.config.ApiVersion import org.jetbrains.kotlin.config.LanguageVersion import org.jetbrains.kotlin.idea.configuration.KotlinMigrationProjectComponent import org.jetbrains.kotlin.idea.configuration.MigrationInfo -import org.jetbrains.kotlin.test.JUnit3RunnerWithInners import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner -import org.jetbrains.kotlin.test.testFramework.runInEdtAndWait import org.junit.Assert import org.junit.runner.RunWith import java.io.File diff --git a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenUpdateConfigurationQuickFixTest.kt b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenUpdateConfigurationQuickFixTest.kt index 62812190e2b..cdd2cf497dd 100644 --- a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenUpdateConfigurationQuickFixTest.kt +++ b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/MavenUpdateConfigurationQuickFixTest.kt @@ -24,10 +24,9 @@ import com.intellij.openapi.vfs.VirtualFile import com.intellij.rt.execution.junit.FileComparisonFailure import com.intellij.testFramework.fixtures.CodeInsightTestFixture import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory -import org.jetbrains.kotlin.test.JUnit3RunnerWithInners import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner +import com.intellij.testFramework.runInEdtAndWait import org.jetbrains.kotlin.test.KotlinTestUtils -import org.jetbrains.kotlin.test.testFramework.runInEdtAndWait import org.junit.Test import org.junit.runner.RunWith import java.io.File diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinProjectDescriptorWithFacet.kt b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinProjectDescriptorWithFacet.kt index ffc46d5f3c4..c7d83284686 100644 --- a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinProjectDescriptorWithFacet.kt +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinProjectDescriptorWithFacet.kt @@ -20,10 +20,10 @@ import com.intellij.facet.FacetManager import com.intellij.openapi.module.Module import com.intellij.openapi.roots.ContentEntry import com.intellij.openapi.roots.ModifiableRootModel +import com.intellij.testFramework.runInEdtAndWait import org.jetbrains.kotlin.config.CompilerSettings import org.jetbrains.kotlin.config.LanguageVersion import org.jetbrains.kotlin.idea.facet.* -import org.jetbrains.kotlin.test.testFramework.runInEdtAndWait import org.jetbrains.kotlin.test.testFramework.runWriteAction class KotlinProjectDescriptorWithFacet(