mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
BaseFixture is TestCase no more
This commit is contained in:
+3
-2
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<DocumentListener> myDocumentListeners = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
private final RangeMarkerTree<RangeMarkerEx> myRangeMarkers = new RangeMarkerTree<RangeMarkerEx>(this);
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 <T> void assertSameElements(Collection<? extends T> collection, Collection<T> expected) {
|
||||
assertSameElements(null, collection, expected);
|
||||
}
|
||||
|
||||
|
||||
public static <T> void assertSameElements(String message, Collection<? extends T> collection, Collection<T> expected) {
|
||||
assertNotNull(collection);
|
||||
assertNotNull(expected);
|
||||
@@ -391,11 +400,11 @@ public abstract class UsefulTestCase extends TestCase {
|
||||
Assert.assertEquals(message, new HashSet<T>(expected), new HashSet<T>(collection));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public <T> void assertContainsOrdered(Collection<? extends T> collection, T... expected) {
|
||||
assertContainsOrdered(collection, Arrays.asList(expected));
|
||||
}
|
||||
|
||||
|
||||
public <T> void assertContainsOrdered(Collection<? extends T> collection, Collection<T> expected) {
|
||||
ArrayList<T> copy = new ArrayList<T>(collection);
|
||||
copy.retainAll(expected);
|
||||
@@ -405,7 +414,7 @@ public abstract class UsefulTestCase extends TestCase {
|
||||
public <T> void assertContainsElements(Collection<? extends T> collection, T... expected) {
|
||||
assertContainsElements(collection, Arrays.asList(expected));
|
||||
}
|
||||
|
||||
|
||||
public <T> void assertContainsElements(Collection<? extends T> collection, Collection<T> expected) {
|
||||
ArrayList<T> copy = new ArrayList<T>(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) {
|
||||
|
||||
+1
-2
@@ -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();
|
||||
|
||||
+12
-3
@@ -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 extends Disposable> T disposeOnTearDown(final T disposable) {
|
||||
Disposer.register(myTestRootDisposable, disposable);
|
||||
return disposable;
|
||||
}
|
||||
}
|
||||
+10
-3
@@ -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<String, InspectionToolWrapper>());
|
||||
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());
|
||||
|
||||
+4
-2
@@ -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<VirtualFile>() {
|
||||
@Override
|
||||
protected void run(final Result<VirtualFile> 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) {
|
||||
|
||||
Reference in New Issue
Block a user