anonymous tests

This commit is contained in:
Konstantin Bulenkov
2012-01-31 17:21:22 +01:00
parent c2dcc5229d
commit 80ccdf22ba
10 changed files with 115 additions and 9 deletions
@@ -0,0 +1,8 @@
class Anonymous {
int num1;
int num2;
Object o = new Object(){<caret>};
Anonymous() {}
void foo() {}
}
@@ -0,0 +1,8 @@
-Anonymous.java
-Anonymous
Anonymous()
foo():void
num1:int
num2:int
-[o:Object = new Object() {...}]
$1
@@ -0,0 +1,15 @@
class AnonymousInAnonymous {
int num1;
int num2;
AnonymousInAnonymous() {}
void foo() {
new Object() {
public String toString() {
return new Object(){
void method() {<caret>}
}.toString();
}
};
}
}
@@ -0,0 +1,10 @@
-AnonymousInAnonymous.java
-AnonymousInAnonymous
AnonymousInAnonymous()
-foo():void
-$1
-toString():String
-Anonymous
[method():void]
num1:int
num2:int
+10
View File
@@ -0,0 +1,10 @@
class Anonymous {
int num1;
int num2;
Object o = new Object(){
int num = 1;
};
Anonymous() {}
void foo() {}
}
@@ -24,8 +24,10 @@ public class JavaFileStructureSelectionTest extends JavaFileStructureTestCase {
return "selection";
}
public void testField() throws Exception {checkTree();}
public void testMethod() throws Exception {checkTree();}
public void testConstructor() throws Exception {checkTree();}
public void testInsideClass() throws Exception {checkTree();}
public void testField() throws Exception {checkTree();}
public void testMethod() throws Exception {checkTree();}
public void testConstructor() throws Exception {checkTree();}
public void testInsideClass() throws Exception {checkTree();}
public void testAnonymous() throws Exception {checkTree();}
public void testAnonymousInAnonymous() throws Exception {checkTree();}
}
@@ -33,6 +33,9 @@ public abstract class JavaFileStructureTestCase extends FileStructureTestBase {
public void setUp() throws Exception {
super.setUp();
myShowAnonymousByDefault = PropertiesComponent.getInstance().getBoolean(getAnonymousPropertyName(), false);
if (getTestName(false).contains("Anonymous")) {
setShowAnonymous(true);
}
}
@Override
@@ -40,6 +43,11 @@ public abstract class JavaFileStructureTestCase extends FileStructureTestBase {
return "java";
}
public void setShowAnonymous(boolean show) throws Exception {
myPopup.setTreeActionState(JavaAnonymousClassesNodeProvider.class, show);
update();
}
@Override
public void tearDown() throws Exception {
PropertiesComponent.getInstance().setValue(getAnonymousPropertyName(), Boolean.toString(myShowAnonymousByDefault));
@@ -107,6 +107,7 @@ public class FileStructurePopup implements Disposable {
private int myPreferredWidth;
private final FilteringTreeStructure myFilteringStructure;
private PsiElement myInitialPsiElement;
private Map<Class, JCheckBox> myCheckBoxes = new HashMap<Class, JCheckBox>();
public FileStructurePopup(StructureViewModel structureViewModel,
@Nullable Editor editor,
@@ -128,7 +129,7 @@ public class FileStructurePopup implements Disposable {
myTreeStructure = new SmartTreeStructure(project, myTreeModel){
public void rebuildTree() {
if (!myPopup.isDisposed()) {
if (ApplicationManager.getApplication().isUnitTestMode() || !myPopup.isDisposed()) {
super.rebuildTree();
}
}
@@ -503,7 +504,7 @@ public class FileStructurePopup implements Disposable {
return null;
}
protected JComponent createCenterPanel() {
public JComponent createCenterPanel() {
List<FileStructureFilter> fileStructureFilters = new ArrayList<FileStructureFilter>();
List<FileStructureNodeProvider> fileStructureNodeProviders = new ArrayList<FileStructureNodeProvider>();
if (myTreeActionsOwner != null) {
@@ -704,6 +705,7 @@ public class FileStructurePopup implements Disposable {
}
chkFilter.setText(text);
panel.add(chkFilter);
myCheckBoxes.put(action.getClass(), chkFilter);
}
private static boolean getDefaultValue(TreeAction action) {
@@ -742,6 +744,16 @@ public class FileStructurePopup implements Disposable {
return myAbstractTreeBuilder;
}
public void setTreeActionState(Class<? extends TreeAction> action, boolean state) {
final JCheckBox checkBox = myCheckBoxes.get(action);
if (checkBox != null) {
checkBox.setSelected(state);
for (ActionListener listener : checkBox.getActionListeners()) {
listener.actionPerformed(new ActionEvent(this, 1, ""));
}
}
}
private class FileStructurePopupFilter implements ElementFilter {
private String myLastFilter = null;
private HashSet<Object> myVisibleParents = new HashSet<Object>();
@@ -36,7 +36,7 @@ import java.io.File;
* @author Konstantin Bulenkov
*/
public abstract class FileStructureTestBase extends CodeInsightFixtureTestCase {
FileStructurePopup myPopup;
protected FileStructurePopup myPopup;
@Before
public void setUp() throws Exception {
@@ -46,6 +46,9 @@ public abstract class FileStructureTestBase extends CodeInsightFixtureTestCase {
myFixture.getProject(),
null,
TextEditorProvider.getInstance().getTextEditor(myFixture.getEditor()));
assert myPopup != null;
myPopup.createCenterPanel();
getBuilder().getUi().getUpdater().setPassThroughMode(true);
update();
}
@@ -71,15 +74,17 @@ public abstract class FileStructureTestBase extends CodeInsightFixtureTestCase {
}
private void update() throws InterruptedException {
public void update() throws InterruptedException {
myPopup.getTreeBuilder().refilter().doWhenProcessed(new Runnable() {
@Override
public void run() {
getStructure().rebuild();
updateTree();
getBuilder().updateFromRoot();
TreeUtil.expandAll(getTree());
final FilteringTreeStructure.FilteringNode node = myPopup.selectPsiElement(myPopup.getCurrentElement(getFile()));
getTree().getSelectionModel().setSelectionPath(getTree().getPath(node));
getBuilder().getUi().select(node, null);
}
});
}
@@ -0,0 +1,28 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.testFramework;
import com.intellij.ide.util.treeView.AbstractTreeBuilder;
import com.intellij.ide.util.treeView.AbstractTreeUpdater;
/**
* @author Konstantin Bulenkov
*/
public class TestTreeUpdater extends AbstractTreeUpdater {
public TestTreeUpdater(AbstractTreeBuilder treeBuilder) {
super(treeBuilder);
}
}