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 81ea03c48858..525df5c02fea 100644 --- a/java/testFramework/src/com/intellij/testFramework/fixtures/impl/JavaCodeInsightTestFixtureImpl.java +++ b/java/testFramework/src/com/intellij/testFramework/fixtures/impl/JavaCodeInsightTestFixtureImpl.java @@ -27,6 +27,7 @@ import com.intellij.testFramework.fixtures.IdeaProjectTestFixture; import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture; import com.intellij.testFramework.fixtures.TempDirTestFixture; import com.intellij.util.ui.UIUtil; +import junit.framework.Assert; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -75,7 +76,7 @@ public class JavaCodeInsightTestFixtureImpl extends CodeInsightTestFixtureImpl i @NotNull public PsiClass findClass(@NotNull @NonNls final String name) { final PsiClass aClass = getJavaFacade().findClass(name, ProjectScope.getProjectScope(getProject())); - assertNotNull("Class " + name + " not found", aClass); + Assert.assertNotNull("Class " + name + " not found", aClass); return aClass; } @@ -83,7 +84,7 @@ public class JavaCodeInsightTestFixtureImpl extends CodeInsightTestFixtureImpl i @NotNull public PsiPackage findPackage(@NotNull @NonNls final String name) { final PsiPackage aPackage = getJavaFacade().findPackage(name); - assertNotNull("Package " + name + " not found", aPackage); + Assert.assertNotNull("Package " + name + " not found", aPackage); return aPackage; } diff --git a/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java b/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java index 25ae84838a58..b5cb3c551c8b 100644 --- a/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java @@ -50,7 +50,7 @@ import java.util.List; public class DocumentImpl extends UserDataHolderBase implements DocumentEx { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.editor.impl.DocumentImpl"); - public static boolean CHECK_DOCUMENT_CONSISTENCY = ApplicationManager.getApplication().isUnitTestMode(); + public static boolean CHECK_DOCUMENT_CONSISTENCY = ApplicationManager.getApplication() != null && ApplicationManager.getApplication().isUnitTestMode(); private final List myDocumentListeners = ContainerUtil.createLockFreeCopyOnWriteList(); private final RangeMarkerTree myRangeMarkers = new RangeMarkerTree(this); diff --git a/platform/platform-tests/testSrc/com/intellij/ide/LocatorTest.java b/platform/platform-tests/testSrc/com/intellij/ide/LocatorTest.java index 8c9f04d9bd17..ecb0d2d05e42 100644 --- a/platform/platform-tests/testSrc/com/intellij/ide/LocatorTest.java +++ b/platform/platform-tests/testSrc/com/intellij/ide/LocatorTest.java @@ -15,6 +15,7 @@ */ package com.intellij.ide; +import com.intellij.idea.IdeaTestApplication; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.ex.ApplicationEx; import com.intellij.openapi.util.io.FileUtil; @@ -25,8 +26,10 @@ import java.io.File; public class LocatorTest extends PlatformLangTestCase { public void test() throws Exception { + IdeaTestApplication.getInstance(null); File locatorFile = new File(PathManager.getSystemPath() + "/" + ApplicationEx.LOCATOR_FILE_NAME); - assertTrue(locatorFile.getPath(), locatorFile.canRead()); + assertTrue("doesn't exist: " + locatorFile.getPath(), locatorFile.exists()); + assertTrue("can't read: " + locatorFile.getPath(), locatorFile.canRead()); String home = FileUtil.loadFile(locatorFile, "UTF-8"); assertTrue(home, StringUtil.isNotEmpty(home)); diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index 9e71f6885ef9..82dcc3bccc69 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -22,7 +22,10 @@ import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.codeInsight.hint.HintManager; import com.intellij.codeInsight.hint.HintManagerImpl; import com.intellij.codeInsight.lookup.LookupManager; -import com.intellij.codeInspection.*; +import com.intellij.codeInspection.InspectionEP; +import com.intellij.codeInspection.InspectionProfileEntry; +import com.intellij.codeInspection.LocalInspectionEP; +import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.ex.*; import com.intellij.ide.highlighter.ProjectFileType; import com.intellij.ide.startup.StartupManagerEx; @@ -40,7 +43,6 @@ import com.intellij.openapi.command.undo.UndoManager; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; -import com.intellij.openapi.editor.impl.DocumentImpl; import com.intellij.openapi.editor.impl.EditorFactoryImpl; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileEditor.FileDocumentManager; @@ -331,7 +333,6 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da storeSettings(); myThreadTracker = new ThreadTracker(); - DocumentImpl.CHECK_DOCUMENT_CONSISTENCY = !isPerformanceTest(); ModuleRootManager.getInstance(ourModule).orderEntries().getAllLibrariesAndSdkClassesRoots(); VirtualFilePointerManagerImpl filePointerManager = (VirtualFilePointerManagerImpl)VirtualFilePointerManager.getInstance(); filePointerManager.storePointers(); diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java index ee382fb58731..8bf0af5759e9 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java @@ -35,7 +35,6 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.event.DocumentListener; -import com.intellij.openapi.editor.impl.DocumentImpl; import com.intellij.openapi.module.EmptyModuleType; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; @@ -202,7 +201,6 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro } DocumentCommitThread.getInstance().clearQueue(); - DocumentImpl.CHECK_DOCUMENT_CONSISTENCY = !isPerformanceTest(); } public Project getProject() { diff --git a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java index ddb0c247dfbd..9cfade6d3e45 100644 --- a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java @@ -23,6 +23,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.command.impl.StartMarkAction; +import com.intellij.openapi.editor.impl.DocumentImpl; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.*; @@ -117,9 +118,11 @@ public abstract class UsefulTestCase extends TestCase { if (shouldContainTempFiles()) { String testName = getTestName(true); if (StringUtil.isEmptyOrSpaces(testName)) testName = ""; + testName = new File(testName).getName(); // in case the test name contains file separators myTempDir = ORIGINAL_TEMP_DIR + "/unitTest_" + testName + "_"+ PRNG.nextInt(1000); FileUtil.resetCanonicalTempPathCache(myTempDir); } + DocumentImpl.CHECK_DOCUMENT_CONSISTENCY = !isPerformanceTest(); } @Override @@ -170,6 +173,14 @@ public abstract class UsefulTestCase extends TestCase { if (isPerformanceTest() || ApplicationManager.getApplication() == null || ApplicationManager.getApplication() instanceof MockApplication) { return; } + CodeStyleSettings oldCodeStyleSettings = myOldCodeStyleSettings; + myOldCodeStyleSettings = null; + + doCheckForSettingsDamage(oldCodeStyleSettings, getCurrentCodeStyleSettings()); + } + + public static void doCheckForSettingsDamage(@NotNull CodeStyleSettings oldCodeStyleSettings, + @NotNull CodeStyleSettings currentCodeStyleSettings) throws Exception { CompositeException result = new CompositeException(); final CodeInsightSettings settings = CodeInsightSettings.getInstance(); try { @@ -185,18 +196,16 @@ public abstract class UsefulTestCase extends TestCase { result.add(error); } - CodeStyleSettings codeStyleSettings = getCurrentCodeStyleSettings(); - codeStyleSettings.getIndentOptions(StdFileTypes.JAVA); + currentCodeStyleSettings.getIndentOptions(StdFileTypes.JAVA); try { - checkSettingsEqual(myOldCodeStyleSettings, codeStyleSettings, "Code style settings damaged"); + checkSettingsEqual(oldCodeStyleSettings, currentCodeStyleSettings, "Code style settings damaged"); } catch (AssertionError e) { result.add(e); } finally { - codeStyleSettings.clearCodeStyleSettings(); + currentCodeStyleSettings.clearCodeStyleSettings(); } - myOldCodeStyleSettings = null; try { InplaceRefactoring.checkCleared(); @@ -382,7 +391,7 @@ public abstract class UsefulTestCase extends TestCase { public static void assertSameElements(Collection collection, Collection expected) { assertSameElements(null, collection, expected); } - + public static void assertSameElements(String message, Collection collection, Collection expected) { assertNotNull(collection); assertNotNull(expected); @@ -391,11 +400,11 @@ public abstract class UsefulTestCase extends TestCase { Assert.assertEquals(message, new HashSet(expected), new HashSet(collection)); } } - + public void assertContainsOrdered(Collection collection, T... expected) { assertContainsOrdered(collection, Arrays.asList(expected)); } - + public void assertContainsOrdered(Collection collection, Collection expected) { ArrayList copy = new ArrayList(collection); copy.retainAll(expected); @@ -405,7 +414,7 @@ public abstract class UsefulTestCase extends TestCase { public void assertContainsElements(Collection collection, T... expected) { assertContainsElements(collection, Arrays.asList(expected)); } - + public void assertContainsElements(Collection collection, Collection expected) { ArrayList copy = new ArrayList(collection); copy.retainAll(expected); @@ -829,7 +838,7 @@ public abstract class UsefulTestCase extends TestCase { return GraphicsEnvironment.isHeadless(); } - protected static void refreshRecursively(@NotNull VirtualFile file) { + public static void refreshRecursively(@NotNull VirtualFile file) { VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() { @Override public boolean visitFile(@NotNull VirtualFile file) { diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/LightPlatformCodeInsightFixtureTestCase.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/LightPlatformCodeInsightFixtureTestCase.java index ca4d688a3fdc..fb027f186bcf 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/LightPlatformCodeInsightFixtureTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/LightPlatformCodeInsightFixtureTestCase.java @@ -37,8 +37,7 @@ import java.io.File; /** * @author peter */ -public abstract class LightPlatformCodeInsightFixtureTestCase extends UsefulTestCase{ - +public abstract class LightPlatformCodeInsightFixtureTestCase extends UsefulTestCase { @SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors") public LightPlatformCodeInsightFixtureTestCase() { PlatformTestCase.autodetectPlatformPrefix(); 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 d3013ea32afc..7213b94402bd 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/BaseFixture.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/BaseFixture.java @@ -19,17 +19,18 @@ */ package com.intellij.testFramework.fixtures.impl; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.util.Disposer; import com.intellij.testFramework.UsefulTestCase; import com.intellij.testFramework.fixtures.IdeaTestFixture; import junit.framework.Assert; -public class BaseFixture extends UsefulTestCase implements IdeaTestFixture { +public class BaseFixture implements IdeaTestFixture { private boolean myDisposed; private boolean myInitialized; @Override public void setUp() throws Exception { - super.setUp(); Assert.assertFalse("setUp() already has been called", myInitialized); Assert.assertFalse("tearDown() already has been called", myDisposed); myInitialized = true; @@ -39,8 +40,8 @@ public class BaseFixture extends UsefulTestCase implements IdeaTestFixture { public void tearDown() throws Exception { Assert.assertTrue("setUp() has not been called", myInitialized); Assert.assertFalse("tearDown() already has been called", myDisposed); + Disposer.dispose(myTestRootDisposable); myDisposed = true; - super.tearDown(); resetClassFields(getClass()); } @@ -56,4 +57,12 @@ public class BaseFixture extends UsefulTestCase implements IdeaTestFixture { resetClassFields(aClass.getSuperclass()); } + protected final Disposable myTestRootDisposable = Disposer.newDisposable(); + public Disposable getTestRootDisposable() { + return myTestRootDisposable; + } + protected T disposeOnTearDown(final T disposable) { + Disposer.register(myTestRootDisposable, disposable); + return disposable; + } } \ No newline at end of file diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightIdeaTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightIdeaTestFixtureImpl.java index d2aef9bf1af8..84848f07da60 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightIdeaTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightIdeaTestFixtureImpl.java @@ -19,6 +19,7 @@ package com.intellij.testFramework.fixtures.impl; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.ex.InspectionToolWrapper; import com.intellij.idea.IdeaTestApplication; +import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.impl.DirectoryIndex; @@ -31,6 +32,7 @@ import com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl; import com.intellij.testFramework.LightPlatformTestCase; import com.intellij.testFramework.LightProjectDescriptor; import com.intellij.testFramework.TestDataProvider; +import com.intellij.testFramework.UsefulTestCase; import com.intellij.testFramework.fixtures.LightIdeaTestFixture; import gnu.trove.THashMap; @@ -39,6 +41,7 @@ import gnu.trove.THashMap; */ public class LightIdeaTestFixtureImpl extends BaseFixture implements LightIdeaTestFixture { private final LightProjectDescriptor myProjectDescriptor; + private CodeStyleSettings myOldCodeStyleSettings; public LightIdeaTestFixtureImpl(LightProjectDescriptor projectDescriptor) { myProjectDescriptor = projectDescriptor; @@ -51,7 +54,10 @@ public class LightIdeaTestFixtureImpl extends BaseFixture implements LightIdeaTe IdeaTestApplication application = LightPlatformTestCase.initApplication(); LightPlatformTestCase.doSetup(myProjectDescriptor, LocalInspectionTool.EMPTY_ARRAY, new THashMap()); InjectedLanguageManagerImpl.pushInjectors(getProject()); - storeSettings(); + + myOldCodeStyleSettings = getCurrentCodeStyleSettings().clone(); + myOldCodeStyleSettings.getIndentOptions(StdFileTypes.JAVA); + application.setDataProvider(new TestDataProvider(getProject())); } @@ -59,7 +65,9 @@ public class LightIdeaTestFixtureImpl extends BaseFixture implements LightIdeaTe public void tearDown() throws Exception { Project project = getProject(); CodeStyleSettingsManager.getInstance(project).dropTemporarySettings(); - checkForSettingsDamage(); + CodeStyleSettings oldCodeStyleSettings = myOldCodeStyleSettings; + myOldCodeStyleSettings = null; + UsefulTestCase.doCheckForSettingsDamage(oldCodeStyleSettings, getCurrentCodeStyleSettings()); LightPlatformTestCase.doTearDown(project, LightPlatformTestCase.getApplication(), true); super.tearDown(); @@ -74,7 +82,6 @@ public class LightIdeaTestFixtureImpl extends BaseFixture implements LightIdeaTe return LightPlatformTestCase.getProject(); } - @Override protected CodeStyleSettings getCurrentCodeStyleSettings() { if (CodeStyleSchemes.getInstance().getCurrentScheme() == null) return new CodeStyleSettings(); return CodeStyleSettingsManager.getSettings(getProject()); diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightTempDirTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightTempDirTestFixtureImpl.java index 8079c9e3275c..556a9881ee92 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightTempDirTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightTempDirTestFixtureImpl.java @@ -22,10 +22,12 @@ import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.*; import com.intellij.testFramework.LightPlatformTestCase; +import com.intellij.testFramework.UsefulTestCase; import com.intellij.testFramework.fixtures.TempDirTestFixture; import com.intellij.util.PathUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.junit.Assert; import java.io.IOException; import java.util.List; @@ -40,7 +42,7 @@ public class LightTempDirTestFixtureImpl extends BaseFixture implements TempDirT public LightTempDirTestFixtureImpl() { final VirtualFile fsRoot = VirtualFileManager.getInstance().findFileByUrl("temp:///"); - assertNotNull(fsRoot); + Assert.assertNotNull(fsRoot); mySourceRoot = new WriteAction() { @Override protected void run(final Result result) throws Throwable { @@ -118,7 +120,7 @@ public class LightTempDirTestFixtureImpl extends BaseFixture implements TempDirT final VirtualFile from = LocalFileSystem.getInstance().refreshAndFindFileByPath(dataDir); assert from != null: "Cannot find testdata directory " + dataDir; try { - refreshRecursively(from); + UsefulTestCase.refreshRecursively(from); VirtualFile tempDir = getSourceRoot(); if (targetDir.length() > 0) {