Use directive configuring in resolve reference tests

This commit is contained in:
Nikolay Krasko
2013-07-10 21:29:24 +04:00
parent 68bd7405ff
commit 970586bfdd
7 changed files with 35 additions and 16 deletions
@@ -25,7 +25,8 @@ import com.intellij.psi.PsiReference;
import com.intellij.psi.ResolveResult;
import com.intellij.testFramework.LightCodeInsightTestCase;
import junit.framework.Assert;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.InTextDirectivesUtils;
import org.jetbrains.jet.plugin.PluginTestCaseBase;
import org.jetbrains.jet.testing.ReferenceUtils;
@@ -43,41 +44,44 @@ public class ResolveBaseTest extends LightCodeInsightTestCase {
}
public void testResolveClass() throws Exception {
doSingleResolveTest("(<root>).Test");
doSingleResolveTest();
}
public void testResolvePackageInProperty() throws Exception {
doSingleResolveTest("test1");
doSingleResolveTest();
}
public void testSamConstructor() throws Exception {
doSingleResolveTest("(java.util).Comparator");
doSingleResolveTest();
}
public void testSamConstructorTypeArguments() throws Exception {
doSingleResolveTest("(java.util).Comparator");
doSingleResolveTest();
}
public void testSamAdapter() throws Exception {
doSingleResolveTest("(in javax.swing.SwingUtilities).invokeLater(Runnable)");
doSingleResolveTest();
}
public void testSeveralOverrides() throws Exception {
doMultiResolveTest();
}
protected void doSingleResolveTest(@Nullable String referenceToString) throws Exception {
protected void doSingleResolveTest() throws Exception {
String testName = getTestName(false);
configureByFile(testName + ".kt");
String referenceToString = InTextDirectivesUtils.findStringWithPrefixes(getFile().getText(), "REF:");
Assert.assertNotNull("Test data wasn't found, use \"// REF: \" directive", referenceToString);
int offset = getEditor().getCaretModel().getOffset();
PsiReference psiReference = getFile().findReferenceAt(offset);
if (psiReference != null) {
PsiElement resolvedTo = psiReference.resolve();
if (resolvedTo != null) {
String resolvedToElementStr = ReferenceUtils.renderAsGotoImplementation(resolvedTo);
String notEqualMessage = String.format("Found reference to '%s', but '%s' was expected", resolvedToElementStr,
referenceToString != null ? referenceToString : "<null>");
String notEqualMessage = String.format("Found reference to '%s', but '%s' was expected",
resolvedToElementStr, referenceToString);
assertEquals(notEqualMessage, referenceToString, resolvedToElementStr);
}
else {
@@ -116,6 +120,7 @@ public class ResolveBaseTest extends LightCodeInsightTestCase {
return PluginTestCaseBase.jdkFromIdeaHome();
}
@NotNull
@Override
protected String getTestDataPath() {
return new File(PluginTestCaseBase.getTestDataPathBase(), "/resolve/").getPath() + File.separator;