mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
tree tests
This commit is contained in:
@@ -34,11 +34,9 @@ package com.intellij.projectView;
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.ide.structureView.impl.java.InheritedMembersFilter;
|
||||
import com.intellij.ide.structureView.newStructureView.StructureViewComponent;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
@@ -48,6 +46,7 @@ import com.intellij.psi.JavaDirectoryService;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.TestSourceBasedTestCase;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
@@ -69,55 +68,55 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase {
|
||||
final StructureViewComponent structureViewComponent =
|
||||
(StructureViewComponent)fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);
|
||||
final Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiClass.getContainingFile());
|
||||
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(),
|
||||
"-Class1.java\n" +
|
||||
" -Class1\n" +
|
||||
" getValue():int\n" +
|
||||
" getClass():Class<? extends Object>\n" +
|
||||
" hashCode():int\n" +
|
||||
" equals(Object):boolean\n" +
|
||||
" clone():Object\n" +
|
||||
" toString():String\n" +
|
||||
" notify():void\n" +
|
||||
" notifyAll():void\n" +
|
||||
" wait(long):void\n" +
|
||||
" wait(long, int):void\n" +
|
||||
" wait():void\n" +
|
||||
" finalize():void\n" +
|
||||
" myField1:boolean\n" +
|
||||
" myField2:boolean\n");
|
||||
PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(),
|
||||
"-Class1.java\n" +
|
||||
" -Class1\n" +
|
||||
" getValue():int\n" +
|
||||
" getClass():Class<? extends Object>\n" +
|
||||
" hashCode():int\n" +
|
||||
" equals(Object):boolean\n" +
|
||||
" clone():Object\n" +
|
||||
" toString():String\n" +
|
||||
" notify():void\n" +
|
||||
" notifyAll():void\n" +
|
||||
" wait(long):void\n" +
|
||||
" wait(long, int):void\n" +
|
||||
" wait():void\n" +
|
||||
" finalize():void\n" +
|
||||
" myField1:boolean\n" +
|
||||
" myField2:boolean\n");
|
||||
|
||||
CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
protected void run() throws Throwable {
|
||||
final int offset = document.getLineStartOffset(5);
|
||||
document.insertString(offset, " boolean myNewField = false;\n");
|
||||
}
|
||||
}, null, null);
|
||||
}.execute().throwException();
|
||||
|
||||
|
||||
PsiDocumentManager.getInstance(myProject).commitDocument(document);
|
||||
|
||||
IdeaTestUtil.waitForAlarm(600);
|
||||
PlatformTestUtil.waitForAlarm(600);
|
||||
|
||||
//TreeUtil.expand(structureViewComponent.getTree(), 3);
|
||||
|
||||
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" +
|
||||
" -Class1\n" + " getValue():int\n" +
|
||||
" getClass():Class<? extends Object>\n" +
|
||||
" hashCode():int\n" +
|
||||
" equals(Object):boolean\n" +
|
||||
" clone():Object\n" +
|
||||
" toString():String\n" +
|
||||
" notify():void\n" +
|
||||
" notifyAll():void\n" +
|
||||
" wait(long):void\n" +
|
||||
" wait(long, int):void\n" +
|
||||
" wait():void\n" +
|
||||
" finalize():void\n" +
|
||||
" myField1:boolean\n" +
|
||||
" myField2:boolean\n" +
|
||||
" myNewField:boolean = false\n");
|
||||
PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" +
|
||||
" -Class1\n" + " getValue():int\n" +
|
||||
" getClass():Class<? extends Object>\n" +
|
||||
" hashCode():int\n" +
|
||||
" equals(Object):boolean\n" +
|
||||
" clone():Object\n" +
|
||||
" toString():String\n" +
|
||||
" notify():void\n" +
|
||||
" notifyAll():void\n" +
|
||||
" wait(long):void\n" +
|
||||
" wait(long, int):void\n" +
|
||||
" wait():void\n" +
|
||||
" finalize():void\n" +
|
||||
" myField1:boolean\n" +
|
||||
" myField2:boolean\n" +
|
||||
" myNewField:boolean = false\n");
|
||||
|
||||
Disposer.dispose(structureViewComponent);
|
||||
|
||||
@@ -138,31 +137,31 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase {
|
||||
try {
|
||||
structureViewComponent.setActionActive(InheritedMembersFilter.ID, true);
|
||||
|
||||
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" +
|
||||
" -Class2\n" +
|
||||
" +InnerClass1\n" +
|
||||
" +InnerClass2\n" +
|
||||
" getValue():int\n" +
|
||||
" myField1:boolean\n" +
|
||||
" myField2:boolean\n" +
|
||||
" myField3:boolean\n" +
|
||||
" myField4:boolean\n");
|
||||
PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" +
|
||||
" -Class2\n" +
|
||||
" +InnerClass1\n" +
|
||||
" +InnerClass2\n" +
|
||||
" getValue():int\n" +
|
||||
" myField1:boolean\n" +
|
||||
" myField2:boolean\n" +
|
||||
" myField3:boolean\n" +
|
||||
" myField4:boolean\n");
|
||||
|
||||
final PsiField innerClassField = psiClass.getInnerClasses()[0].getFields()[0];
|
||||
|
||||
structureViewComponent.select(innerClassField, true);
|
||||
|
||||
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" +
|
||||
" -Class2\n" +
|
||||
" -InnerClass1\n" +
|
||||
" +InnerClass12\n" +
|
||||
" myInnerClassField:int\n" +
|
||||
" +InnerClass2\n" +
|
||||
" getValue():int\n" +
|
||||
" myField1:boolean\n" +
|
||||
" myField2:boolean\n" +
|
||||
" myField3:boolean\n" +
|
||||
" myField4:boolean\n");
|
||||
PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" +
|
||||
" -Class2\n" +
|
||||
" -InnerClass1\n" +
|
||||
" +InnerClass12\n" +
|
||||
" myInnerClassField:int\n" +
|
||||
" +InnerClass2\n" +
|
||||
" getValue():int\n" +
|
||||
" myField1:boolean\n" +
|
||||
" myField2:boolean\n" +
|
||||
" myField3:boolean\n" +
|
||||
" myField4:boolean\n");
|
||||
|
||||
CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
|
||||
@Override
|
||||
@@ -175,25 +174,25 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase {
|
||||
innerClassField.delete();
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
assertTrue(e.getLocalizedMessage(), false);
|
||||
fail(e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, null, null);
|
||||
|
||||
IdeaTestUtil.waitForAlarm(600);
|
||||
PlatformTestUtil.waitForAlarm(600);
|
||||
|
||||
IdeaTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" +
|
||||
" -Class2\n" +
|
||||
" -InnerClass1\n" +
|
||||
" +InnerClass12\n" +
|
||||
" +InnerClass2\n" +
|
||||
" getValue():int\n" +
|
||||
" myField1:boolean\n" +
|
||||
" myField2:boolean\n" +
|
||||
" myField3:boolean\n" +
|
||||
" myField4:boolean\n");
|
||||
PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class2.java\n" +
|
||||
" -Class2\n" +
|
||||
" -InnerClass1\n" +
|
||||
" +InnerClass12\n" +
|
||||
" +InnerClass2\n" +
|
||||
" getValue():int\n" +
|
||||
" myField1:boolean\n" +
|
||||
" myField2:boolean\n" +
|
||||
" myField3:boolean\n" +
|
||||
" myField4:boolean\n");
|
||||
|
||||
}
|
||||
finally {
|
||||
@@ -213,26 +212,26 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase {
|
||||
(StructureViewComponent)fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);
|
||||
|
||||
final JTree tree = structureViewComponent.getTree();
|
||||
IdeaTestUtil.assertTreeEqual(tree, "-test.xml\n" +
|
||||
" -test\n" +
|
||||
" +level1\n" +
|
||||
" +level1\n" +
|
||||
" +level1\n" +
|
||||
" +level1\n");
|
||||
PlatformTestUtil.assertTreeEqual(tree, "-test.xml\n" +
|
||||
" -test\n" +
|
||||
" +level1\n" +
|
||||
" +level1\n" +
|
||||
" +level1\n" +
|
||||
" +level1\n");
|
||||
|
||||
tree.expandPath(tree.getPathForRow(3));
|
||||
|
||||
IdeaTestUtil.waitForAlarm(600);
|
||||
PlatformTestUtil.waitForAlarm(600);
|
||||
|
||||
|
||||
IdeaTestUtil.assertTreeEqual(tree,
|
||||
"-test.xml\n" +
|
||||
" -test\n" +
|
||||
" +level1\n" +
|
||||
" -level1\n" +
|
||||
" +level2\n" +
|
||||
" +level1\n" +
|
||||
" +level1\n");
|
||||
PlatformTestUtil.assertTreeEqual(tree,
|
||||
"-test.xml\n" +
|
||||
" -test\n" +
|
||||
" +level1\n" +
|
||||
" -level1\n" +
|
||||
" +level2\n" +
|
||||
" +level1\n" +
|
||||
" +level1\n");
|
||||
|
||||
Disposer.dispose(structureViewComponent);
|
||||
}
|
||||
@@ -246,4 +245,9 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase {
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRunInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@ import com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode;
|
||||
import com.intellij.ide.util.treeView.*;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.project.DumbAwareRunnable;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
import com.intellij.openapi.startup.StartupManager;
|
||||
import com.intellij.openapi.ui.Queryable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
@@ -300,4 +298,9 @@ public abstract class BaseProjectViewTestCase extends TestSourceBasedTestCase {
|
||||
protected String getTestDataPath() {
|
||||
return PathManagerEx.getTestDataPath(getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRunInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ public class FileTemplateUtil{
|
||||
final Properties finalProps = props;
|
||||
CommandProcessor.getInstance().executeCommand(project, new Runnable(){
|
||||
public void run(){
|
||||
final Runnable run = new Runnable(){
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable(){
|
||||
public void run(){
|
||||
try{
|
||||
CreateFromTemplateHandler handler = findHandler(template);
|
||||
@@ -321,8 +321,7 @@ public class FileTemplateUtil{
|
||||
commandException[0] = ex;
|
||||
}
|
||||
}
|
||||
};
|
||||
ApplicationManager.getApplication().runWriteAction(run);
|
||||
});
|
||||
}
|
||||
}, template.isJavaClassTemplate()
|
||||
? IdeBundle.message("command.create.class.from.template")
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
package com.intellij.testFramework;
|
||||
|
||||
import com.intellij.ide.*;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.ide.IdeEventQueue;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeStructure;
|
||||
import com.intellij.idea.Bombed;
|
||||
@@ -48,9 +49,10 @@ import org.jetbrains.annotations.TestOnly;
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.util.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.InvocationEvent;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
|
||||
/**
|
||||
@@ -99,14 +101,14 @@ public class PlatformTestUtil {
|
||||
}
|
||||
|
||||
public static String print(JTree tree, boolean withSelection, Condition<String> nodePrintCondition) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
Object root = tree.getModel().getRoot();
|
||||
printImpl(tree, root, buffer, 0, withSelection, nodePrintCondition);
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
|
||||
private static void printImpl(JTree tree, Object root, StringBuffer buffer, int level, boolean withSelection, @Nullable Condition<String> nodePrintCondition) {
|
||||
private static void printImpl(JTree tree, Object root, StringBuilder buffer, int level, boolean withSelection, @Nullable Condition<String> nodePrintCondition) {
|
||||
DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode)root;
|
||||
|
||||
|
||||
@@ -116,7 +118,7 @@ public class PlatformTestUtil {
|
||||
nodeText = toString(userObject, null);
|
||||
}
|
||||
else {
|
||||
nodeText = defaultMutableTreeNode + "";
|
||||
nodeText = String.valueOf(defaultMutableTreeNode);
|
||||
}
|
||||
|
||||
|
||||
@@ -163,8 +165,10 @@ public class PlatformTestUtil {
|
||||
Assert.assertEquals(expected, treeStringPresentation);
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public static void waitForAlarm(final int delay) throws InterruptedException {
|
||||
final boolean[] invoked = new boolean[]{false};
|
||||
assert !ApplicationManager.getApplication().isWriteAccessAllowed(): "It's a bad idea to wait for an alarm under the write action. Somebody creates an alarm which requires read action and you are deadlocked.";
|
||||
final AtomicBoolean invoked = new AtomicBoolean();
|
||||
final Alarm alarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD);
|
||||
alarm.addRequest(new Runnable() {
|
||||
@Override
|
||||
@@ -175,7 +179,7 @@ public class PlatformTestUtil {
|
||||
alarm.addRequest(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
invoked[0] = true;
|
||||
invoked.set(true);
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
@@ -185,10 +189,13 @@ public class PlatformTestUtil {
|
||||
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
|
||||
while (!invoked[0]) {
|
||||
boolean sleptAlready = false;
|
||||
while (!invoked.get()) {
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
Thread.sleep(delay);
|
||||
Thread.sleep(sleptAlready ? 10 : delay);
|
||||
sleptAlready = true;
|
||||
}
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
|
||||
@@ -52,7 +52,7 @@ public class TransferToEDTQueue<T> {
|
||||
T thing = myQueue.poll();
|
||||
if (thing == null) break;
|
||||
if (!myProcessor.process(thing)) {
|
||||
myQueue.clear();
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
processed++;
|
||||
|
||||
Reference in New Issue
Block a user