mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
FileStructureTestCase refactoring: move logic out of setUp, allow testing by text
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
-Simple.java
|
||||
-Simple
|
||||
aaa(): void
|
||||
bbb(): void
|
||||
[bbb(): void]
|
||||
clone(): Object
|
||||
equals(Object): boolean
|
||||
[fff(): void]
|
||||
fff(): void
|
||||
finalize(): void
|
||||
getClass(): Class<?>
|
||||
hashCode(): int
|
||||
@@ -13,4 +13,4 @@
|
||||
toString(): String
|
||||
wait(): void
|
||||
wait(long): void
|
||||
wait(long, int): void
|
||||
wait(long, int): void
|
||||
+5
@@ -28,6 +28,11 @@ public class JavaFileStructureHierarchyTest extends JavaFileStructureTestCase {
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.copyDirectoryToProject("", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureDefault() {
|
||||
super.configureDefault();
|
||||
setShowParents(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,11 @@ public abstract class JavaFileStructureTestCase extends FileStructureTestBase {
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myShowAnonymousByDefault = PropertiesComponent.getInstance().getBoolean(getAnonymousPropertyName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureDefault() {
|
||||
super.configureDefault();
|
||||
if (getTestName(false).contains("Anonymous")) {
|
||||
setShowAnonymous(true);
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
package com.intellij.testFramework;
|
||||
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase;
|
||||
import com.intellij.util.ui.tree.TreeUtil;
|
||||
import org.junit.Before;
|
||||
|
||||
import javax.swing.tree.TreePath;
|
||||
|
||||
@@ -26,33 +26,26 @@ import javax.swing.tree.TreePath;
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public abstract class FileStructureTestBase extends CodeInsightFixtureTestCase {
|
||||
|
||||
protected FileStructureTestFixture myPopupFixture;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
setupStructurePopup();
|
||||
myPopupFixture = new FileStructureTestFixture(myFixture);
|
||||
Disposer.register(getProject(), myPopupFixture);
|
||||
}
|
||||
|
||||
protected void setupStructurePopup() {
|
||||
protected void configureDefault() {
|
||||
myFixture.configureByFile(getFileName(getFileExtension()));
|
||||
myPopupFixture = new FileStructureTestFixture(myFixture.getProject(), myFixture.getEditor(), getFile());
|
||||
myPopupFixture.update();
|
||||
}
|
||||
|
||||
protected abstract String getFileExtension();
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
try {
|
||||
if (myPopupFixture != null) {
|
||||
myPopupFixture.dispose();
|
||||
myPopupFixture = null;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
super.tearDown();
|
||||
}
|
||||
super.tearDown();
|
||||
myPopupFixture = null;
|
||||
}
|
||||
|
||||
private String getFileName(String ext) {
|
||||
@@ -64,14 +57,22 @@ public abstract class FileStructureTestBase extends CodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
protected void checkTree(String filter) {
|
||||
configureDefault();
|
||||
myPopupFixture.update();
|
||||
myPopupFixture.getPopup().setSearchFilterForTests(filter);
|
||||
myPopupFixture.getBuilder().refilter(null, false, true);
|
||||
myPopupFixture.getBuilder().queueUpdate();
|
||||
TreeUtil.selectPath(myPopupFixture.getTree(), (TreePath)myPopupFixture.getSpeedSearch().findElement(filter));
|
||||
checkTree();
|
||||
checkResult();
|
||||
}
|
||||
|
||||
protected void checkTree() {
|
||||
configureDefault();
|
||||
myPopupFixture.update();
|
||||
checkResult();
|
||||
}
|
||||
|
||||
protected void checkResult() {
|
||||
assertSameLinesWithFile(getTestDataPath() + "/" + getTreeFileName(), PlatformTestUtil.print(myPopupFixture.getTree(), true).trim());
|
||||
}
|
||||
}
|
||||
|
||||
+32
-19
@@ -17,12 +17,12 @@ package com.intellij.testFramework;
|
||||
|
||||
import com.intellij.ide.actions.ViewStructureAction;
|
||||
import com.intellij.ide.util.FileStructurePopup;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestFixture;
|
||||
import com.intellij.ui.treeStructure.Tree;
|
||||
import com.intellij.ui.treeStructure.filtered.FilteringTreeBuilder;
|
||||
import com.intellij.ui.treeStructure.filtered.FilteringTreeStructure;
|
||||
@@ -33,33 +33,28 @@ import org.jetbrains.annotations.Nullable;
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class FileStructureTestFixture {
|
||||
private final PsiFile myFile;
|
||||
public class FileStructureTestFixture implements Disposable {
|
||||
private final CodeInsightTestFixture myFixture;
|
||||
|
||||
private FileStructurePopup myPopup;
|
||||
private PsiFile myFile;
|
||||
|
||||
public FileStructureTestFixture(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
|
||||
myFile = file;
|
||||
myPopup = ViewStructureAction.createPopup(project, TextEditorProvider.getInstance().getTextEditor(editor));
|
||||
assert myPopup != null;
|
||||
myPopup.createCenterPanel();
|
||||
getBuilder().getUi().getUpdater().setPassThroughMode(true);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
Disposer.dispose(myPopup);
|
||||
public FileStructureTestFixture(CodeInsightTestFixture fixture) {
|
||||
myFixture = fixture;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public FilteringTreeStructure.FilteringNode update() {
|
||||
final Ref<FilteringTreeStructure.FilteringNode> nodeRef = new Ref<FilteringTreeStructure.FilteringNode>();
|
||||
myPopup.getTreeBuilder().refilter().doWhenProcessed(new Runnable() {
|
||||
final FileStructurePopup popup = getPopup();
|
||||
popup.getTreeBuilder().refilter().doWhenProcessed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getStructure().rebuild();
|
||||
updateTree();
|
||||
getBuilder().updateFromRoot();
|
||||
TreeUtil.expandAll(getTree());
|
||||
nodeRef.set(myPopup.selectPsiElement(myPopup.getCurrentElement(myFile)));
|
||||
nodeRef.set(popup.selectPsiElement(popup.getCurrentElement(myFile)));
|
||||
getBuilder().getUi().select(nodeRef.get(), null);
|
||||
}
|
||||
});
|
||||
@@ -67,15 +62,15 @@ public class FileStructureTestFixture {
|
||||
}
|
||||
|
||||
public Tree getTree() {
|
||||
return myPopup.getTree();
|
||||
return getPopup().getTree();
|
||||
}
|
||||
|
||||
public FilteringTreeBuilder getBuilder() {
|
||||
return myPopup.getTreeBuilder();
|
||||
return getPopup().getTreeBuilder();
|
||||
}
|
||||
|
||||
public FileStructurePopup.MyTreeSpeedSearch getSpeedSearch() {
|
||||
return (FileStructurePopup.MyTreeSpeedSearch)myPopup.getSpeedSearch();
|
||||
return (FileStructurePopup.MyTreeSpeedSearch)getPopup().getSpeedSearch();
|
||||
}
|
||||
|
||||
|
||||
@@ -102,6 +97,24 @@ public class FileStructureTestFixture {
|
||||
|
||||
@NotNull
|
||||
public FileStructurePopup getPopup() {
|
||||
if (myPopup == null || myFile != myFixture.getFile()) {
|
||||
if (myPopup != null) {
|
||||
Disposer.dispose(myPopup);
|
||||
myPopup = null;
|
||||
}
|
||||
myFile = myFixture.getFile();
|
||||
myPopup = ViewStructureAction.createPopup(myFixture.getProject(), TextEditorProvider.getInstance().getTextEditor(myFixture.getEditor()));
|
||||
assert myPopup != null;
|
||||
Disposer.register(this, myPopup);
|
||||
myPopup.createCenterPanel();
|
||||
myPopup.getTreeBuilder().getUi().getUpdater().setPassThroughMode(true);
|
||||
}
|
||||
return myPopup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
myPopup = null;
|
||||
myFile = null;
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,11 @@ public class HtmlFileStructureTest extends FileStructureTestBase {
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myHtml5OutlineModeDefault = PropertiesComponent.getInstance().getBoolean(getHtml5OutlineModePropertyName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureDefault() {
|
||||
super.configureDefault();
|
||||
setHtml5OutlineMode(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-HtmlFile:ImplicitSections.html
|
||||
-body
|
||||
-[section]
|
||||
-[body]
|
||||
-section
|
||||
h5
|
||||
h4
|
||||
-h3
|
||||
|
||||
Reference in New Issue
Block a user