mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
dispose project components along with the project in tests (testRootDisposable is disposed later than the project, so all objects registered on it are still alive when the project disposed which was treated as leaks)
This commit is contained in:
+15
-12
@@ -52,16 +52,15 @@ import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class NonProjectFileAccessTest extends HeavyFileEditorManagerTestCase {
|
||||
|
||||
private Set<VirtualFile> myOpenedFiles = new THashSet<>();
|
||||
private Set<VirtualFile> myCreatedFiles = new THashSet<>();
|
||||
private final Set<VirtualFile> myOpenedFiles = new THashSet<>();
|
||||
private final Set<VirtualFile> myCreatedFiles = new THashSet<>();
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
EditorNotifications notifications = new EditorNotificationsImpl(getProject());
|
||||
((ComponentManagerImpl)getProject()).registerComponentInstance(EditorNotifications.class, notifications);
|
||||
NonProjectFileWritingAccessProvider.enableChecksInTests(getTestRootDisposable());
|
||||
NonProjectFileWritingAccessProvider.enableChecksInTests(getProject());
|
||||
ProjectManagerEx.getInstanceEx().blockReloadingProjectOnExternalChanges();
|
||||
}
|
||||
|
||||
@@ -69,10 +68,7 @@ public class NonProjectFileAccessTest extends HeavyFileEditorManagerTestCase {
|
||||
protected void tearDown() throws Exception {
|
||||
try {
|
||||
NonProjectFileWritingAccessProvider.setCustomUnlocker(null);
|
||||
FileEditorManager editorManager = FileEditorManager.getInstance(getProject());
|
||||
for (VirtualFile file : myOpenedFiles) {
|
||||
editorManager.closeFile(file);
|
||||
}
|
||||
closeOpenFiles();
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
for (VirtualFile each : myCreatedFiles) {
|
||||
try {
|
||||
@@ -90,6 +86,13 @@ public class NonProjectFileAccessTest extends HeavyFileEditorManagerTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private void closeOpenFiles() {
|
||||
FileEditorManager editorManager = FileEditorManager.getInstance(getProject());
|
||||
for (VirtualFile file : myOpenedFiles) {
|
||||
editorManager.closeFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
public void testBasicAccessCheck() throws Exception {
|
||||
VirtualFile projectFile = createProjectFile();
|
||||
typeAndCheck(projectFile, true);
|
||||
@@ -323,7 +326,7 @@ public class NonProjectFileAccessTest extends HeavyFileEditorManagerTestCase {
|
||||
public boolean isPotentiallyWritable(@NotNull VirtualFile file) {
|
||||
return true;
|
||||
}
|
||||
}, getTestRootDisposable());
|
||||
}, getProject());
|
||||
return requested;
|
||||
}
|
||||
|
||||
@@ -340,7 +343,7 @@ public class NonProjectFileAccessTest extends HeavyFileEditorManagerTestCase {
|
||||
return filesToDeny.contains(file);
|
||||
}
|
||||
},
|
||||
getTestRootDisposable());
|
||||
getProject());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -359,7 +362,7 @@ public class NonProjectFileAccessTest extends HeavyFileEditorManagerTestCase {
|
||||
@Override
|
||||
protected void run(@NotNull Result<VirtualFile> result) throws Throwable {
|
||||
// create externally, since files created via VFS are marked for editing automatically
|
||||
File file = new File(dir, FileUtil.createSequentFileName(dir, "file", "txt"));
|
||||
File file = new File(dir, FileUtil.createSequentFileName(dir, "extfile", "txt"));
|
||||
file.createNewFile();
|
||||
result.setResult(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file));
|
||||
}
|
||||
@@ -399,7 +402,7 @@ public class NonProjectFileAccessTest extends HeavyFileEditorManagerTestCase {
|
||||
return editor;
|
||||
}
|
||||
|
||||
protected void typeInChar(Editor e, char c) {
|
||||
private void typeInChar(Editor e, char c) {
|
||||
getActionManager().getTypedAction().actionPerformed(e, c, createDataContextFor(e));
|
||||
}
|
||||
|
||||
|
||||
+13
-9
@@ -347,7 +347,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
@Override
|
||||
public void enableInspections(@NotNull InspectionProfileEntry... inspections) {
|
||||
assertInitialized();
|
||||
InspectionsKt.enableInspectionTools(getProject(), getTestRootDisposable(), inspections);
|
||||
InspectionsKt.enableInspectionTools(getProject(), getProject(), inspections);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
@@ -446,7 +446,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
@NotNull
|
||||
@Override
|
||||
public HighlightTestInfo testFile(@NotNull String... filePath) {
|
||||
return new HighlightTestInfo(getTestRootDisposable(), filePath) {
|
||||
return new HighlightTestInfo(getProject(), filePath) {
|
||||
@Override
|
||||
public HighlightTestInfo doTest() {
|
||||
configureByFiles(filePaths);
|
||||
@@ -985,7 +985,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
assertInitialized();
|
||||
final ExtensionPoint<T> extensionPoint = area.getExtensionPoint(epName);
|
||||
extensionPoint.registerExtension(extension);
|
||||
Disposer.register(getTestRootDisposable(), new Disposable() {
|
||||
Disposer.register(getProject(), new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
extensionPoint.unregisterExtension(extension);
|
||||
@@ -1167,7 +1167,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
PlatformTestCase.synchronizeTempDirVfs(tempDir);
|
||||
|
||||
myPsiManager = (PsiManagerImpl)PsiManager.getInstance(getProject());
|
||||
InspectionsKt.configureInspections(LocalInspectionTool.EMPTY_ARRAY, getProject(), getTestRootDisposable());
|
||||
InspectionsKt.configureInspections(LocalInspectionTool.EMPTY_ARRAY, getProject(), myProjectFixture.getProject());
|
||||
|
||||
DaemonCodeAnalyzerImpl daemonCodeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject());
|
||||
daemonCodeAnalyzer.prepareForTest();
|
||||
@@ -1184,11 +1184,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
EdtTestUtil.runInEdtAndWait(() -> {
|
||||
try {
|
||||
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true); // return default value to avoid unnecessary save
|
||||
FileEditorManager editorManager = FileEditorManager.getInstance(getProject());
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
for (VirtualFile openFile : editorManager.getOpenFiles()) {
|
||||
editorManager.closeFile(openFile);
|
||||
}
|
||||
closeOpenFiles();
|
||||
}
|
||||
finally {
|
||||
myEditor = null;
|
||||
@@ -1210,6 +1206,14 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
}
|
||||
}
|
||||
|
||||
private void closeOpenFiles() {
|
||||
FileEditorManager editorManager = FileEditorManager.getInstance(getProject());
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
for (VirtualFile openFile : editorManager.getOpenFiles()) {
|
||||
editorManager.closeFile(openFile);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PsiFile[] configureByFilesInner(@NotNull String... filePaths) {
|
||||
assertInitialized();
|
||||
|
||||
Reference in New Issue
Block a user