This commit is contained in:
Roman Shevchenko
2011-03-10 16:40:49 +01:00
parent da30b2c5f4
commit 958da8c725
4 changed files with 41 additions and 39 deletions
@@ -62,29 +62,29 @@ public class ClassNameCompletionTest extends CompletionTestCase {
checkResultByFile(path + "/after2.java");
}
public void testExcessParensAfterNew() throws Throwable { doTest(); }
public void testExcessParensAfterNew() throws Exception { doTest(); }
public void testReuseParensAfterNew() throws Throwable { doTest(); }
public void testReuseParensAfterNew() throws Exception { doTest(); }
public void testBracesAfterNew() throws Throwable { doTest(); }
public void testBracesAfterNew() throws Exception { doTest(); }
public void testInPlainTextFile() throws Throwable {
public void testInPlainTextFile() throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".txt");
checkResultByFile(BASE_PATH + getTestName(false) + "_after.txt");
}
public void testDoubleStringBuffer() throws Throwable {
public void testDoubleStringBuffer() throws Exception {
createClass("package java.lang; public class StringBuffer {}");
doTest();
assertNull(myItems);
}
public void testReplaceReferenceExpressionWithTypeElement() throws Throwable {
public void testReplaceReferenceExpressionWithTypeElement() throws Exception {
createClass("package foo.bar; public class ABCDEF {}");
doTest();
}
public void testCamelHumpPrefix() throws Throwable {
public void testCamelHumpPrefix() throws Exception {
String path = BASE_PATH + "/java/";
configureByFile(path + getTestName(false) + ".java");
complete();
@@ -174,34 +174,48 @@ public class ClassNameCompletionTest extends CompletionTestCase {
checkResultByFile(path + "/test13-result.java");
}
public void testInMethodCall() throws Throwable {
public void testInMethodCall() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
configureByFile(path + "/methodCall-source.java");
performAction();
checkResultByFile(path + "/methodCall-result.java");
}
public void testInMethodCallQualifier() throws Throwable {
public void testInMethodCallQualifier() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
configureByFile(path + "/methodCall1-source.java");
performAction();
checkResultByFile(path + "/methodCall1-result.java");
}
public void testInVariableDeclarationType() throws Throwable {
public void testInVariableDeclarationType() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
configureByFile(path + "/varType-source.java");
performAction();
checkResultByFile(path + "/varType-result.java");
}
public void testExtraSpace() throws Throwable { doJavaTest(); }
public void testExtraSpace() throws Exception { doJavaTest(); }
public void testAnnotation() throws Throwable { doJavaTest(); }
public void testAnnotation() throws Exception { doJavaTest(); }
public void testInStaticImport() throws Throwable { doJavaTest(); }
public void testInStaticImport() throws Exception { doJavaTest(); }
public void testInCommentWithPackagePrefix() throws Throwable { doJavaTest(); }
public void testInCommentWithPackagePrefix() throws Exception { doJavaTest(); }
public void testQualifyNameOnSecondCompletion() throws Exception {
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Exception {
final Module module = ModuleManager.getInstance(getProject()).newModule("second.iml", new JavaModuleType());
createClass(module, "package foo.bar; class AxBxCxDxEx {}");
}
}.execute().throwException();
configureByFileNoCompletion(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-source.java");
new CodeCompletionHandlerBase(CompletionType.CLASS_NAME).invokeCompletion(myProject, myEditor, 2, false);
checkResultByFile(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-result.java");
}
private void doJavaTest() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
@@ -229,18 +243,4 @@ public class ClassNameCompletionTest extends CompletionTestCase {
testLookupManager.forceSelection(Lookup.NORMAL_SELECT_CHAR, 0);
}
}
public void testQualifyNameOnSecondCompletion() throws Throwable {
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
final Module module = ModuleManager.getInstance(getProject()).newModule("second.iml", new JavaModuleType());
createClass(module, "package foo.bar; class AxBxCxDxEx {}");
}
}.execute().throwException();
configureByFileNoCompletion(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-source.java");
new CodeCompletionHandlerBase(CompletionType.CLASS_NAME).invokeCompletion(myProject, myEditor, 2, false);
checkResultByFile(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-result.java");
}
}
@@ -121,7 +121,7 @@ public class VariablesCompletionTest extends CompletionTestCase {
configureByFile(FILE_PREFIX + "locals/" + "UnresolvedMethodName.java");
complete();
checkResultByFile(FILE_PREFIX + "locals/" + "UnresolvedMethodName.java");
testByCount(2, "creAnInt", "createStylesheetCombobox");
doTestByCount(2, "creAnInt", "createStylesheetCombobox");
}
public void testArrayMethodName() throws Throwable {
@@ -126,11 +126,11 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
return configureByFile(vFile, projectFile);
}
protected PsiFile configureByText(final FileType fileType, @NonNls final String text) throws Throwable {
protected PsiFile configureByText(final FileType fileType, @NonNls final String text) throws Exception {
return configureByText(fileType, text, null);
}
protected PsiFile configureByText(final FileType fileType, @NonNls final String text, final String _extension) throws Throwable {
protected PsiFile configureByText(final FileType fileType, @NonNls final String text, final String _extension) throws Exception {
final String extension = _extension == null ? fileType.getDefaultExtension():_extension;
File dir = createTempDirectory();
@@ -139,7 +139,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
if (fileTypeManager.getFileTypeByExtension(extension) != fileType) {
new WriteCommandAction(getProject()) {
@Override
protected void run(Result result) throws Throwable {
protected void run(Result result) throws Exception {
fileTypeManager.associateExtension(fileType, extension);
}
}.execute();
@@ -7,6 +7,7 @@ import com.intellij.codeInsight.lookup.impl.LookupImpl;
import com.intellij.psi.statistics.StatisticsManager;
import com.intellij.psi.statistics.impl.StatisticsManagerImpl;
import com.intellij.testFramework.PlatformTestCase;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
@@ -51,7 +52,7 @@ public abstract class CompletionTestCase extends DaemonAnalyzerTestCase {
new CodeCompletionHandlerBase(myType).invokeCompletion(myProject, myEditor, time, false);
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(myEditor);
myItems = lookup == null ? null : lookup.getItems().toArray(LookupElement.EMPTY_ARRAY);
myItems = lookup == null ? null : lookup.getItems().toArray(new LookupElement[lookup.getItems().size()]);
myPrefix = lookup == null ? "" : lookup.getItems().get(0).getPrefixMatcher().getPrefix();
}
@@ -61,6 +62,7 @@ public abstract class CompletionTestCase extends DaemonAnalyzerTestCase {
protected void selectItem(LookupElement item, char ch) {
final LookupImpl lookup = (LookupImpl)LookupManager.getInstance(myProject).getActiveLookup();
assert lookup != null;
lookup.setCurrentItem(item);
lookup.finishLookup(ch);
}
@@ -69,19 +71,18 @@ public abstract class CompletionTestCase extends DaemonAnalyzerTestCase {
selectItem(item, (char)0);
}
protected void testByCount(int finalCount, String... values) {
protected void doTestByCount(int finalCount, String... values) {
int index = 0;
if (myItems == null) {
assertEquals(0, finalCount);
return;
}
for (int i = 0; i < myItems.length; i++) {
final LookupElement myItem = myItems[i];
for (int j = 0; j < values.length; j++) {
if (values[j] == null) {
for (final LookupElement myItem : myItems) {
for (String value : values) {
if (value == null) {
assertFalse("Unacceptable value reached", true);
}
if (values[j].equals(myItem.getLookupString())) {
if (value.equals(myItem.getLookupString())) {
index++;
break;
}
@@ -90,6 +91,7 @@ public abstract class CompletionTestCase extends DaemonAnalyzerTestCase {
assertEquals(Arrays.toString(myItems), finalCount, index);
}
@Nullable
protected LookupImpl getActiveLookup() {
return (LookupImpl)LookupManager.getActiveLookup(myEditor);
}