Add tests for ClassInheritorsSearch and AnnotatedMembersSearch
Add test for junit
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
[Deprecated] class TestClass1 {}
|
||||
|
||||
[java.lang.Deprecated] class TestClass2 {}
|
||||
|
||||
Deprecated class TestClass3 {}
|
||||
|
||||
java.lang.Deprecated class TestClass4 {}
|
||||
|
||||
class TestClass5 {
|
||||
Deprecated class innerTestClass5() {}
|
||||
}
|
||||
|
||||
// ANNOTATION: java.lang.Deprecated
|
||||
// SEARCH: JetLightClass:TestClass1, JetLightClass:TestClass2, JetLightClass:TestClass3
|
||||
// SEARCH: JetLightClass:TestClass4
|
||||
// SEARCH: JetLightClass:TestClass5.innerTestClass5
|
||||
@@ -0,0 +1,30 @@
|
||||
Deprecated fun test1() {}
|
||||
|
||||
java.lang.Deprecated fun test2() {}
|
||||
|
||||
fun test3() {
|
||||
Deprecated fun test3inner() {}
|
||||
}
|
||||
|
||||
class Test4() {
|
||||
Deprecated fun test4() {}
|
||||
}
|
||||
|
||||
class Test5() {
|
||||
fun test5() {
|
||||
Deprecated fun test5inner() {}
|
||||
}
|
||||
}
|
||||
|
||||
class Test6() {
|
||||
class object {
|
||||
Deprecated fun test6() {}
|
||||
}
|
||||
}
|
||||
|
||||
object Test7 {
|
||||
Deprecated fun test7() {}
|
||||
}
|
||||
|
||||
// ANNOTATION: java.lang.Deprecated
|
||||
// SEARCH: PsiMethod:test1, PsiMethod:test2, PsiMethod:test4, PsiMethod:test6, PsiMethod:test7
|
||||
@@ -0,0 +1,8 @@
|
||||
MyAnnotation("f", "s") fun test1() {}
|
||||
|
||||
MyAnnotation("f", "s") class Test1() {}
|
||||
|
||||
annotation class MyAnnotation(val first: String, val second: String)
|
||||
|
||||
// ANNOTATION: MyAnnotation
|
||||
// SEARCH: PsiMethod:test1, JetLightClass:Test1
|
||||
@@ -0,0 +1,4 @@
|
||||
class A: Object() {}
|
||||
|
||||
// CLASS: java.lang.Object
|
||||
// SEARCH: JetLightClass:A
|
||||
@@ -0,0 +1,6 @@
|
||||
class A: Base() {}
|
||||
|
||||
open class Base() {}
|
||||
|
||||
// CLASS: Base
|
||||
// SEARCH: JetLightClass:A
|
||||
@@ -0,0 +1,12 @@
|
||||
import junit.framework.TestCase
|
||||
|
||||
class Test1: TestCase() {
|
||||
fun test1() {}
|
||||
}
|
||||
|
||||
class Test2: junit.framework.TestCase() {
|
||||
fun test2() {}
|
||||
}
|
||||
|
||||
// CLASS: junit.framework.TestCase
|
||||
// SEARCH: JetLightClass:Test1, JetLightClass:Test2
|
||||
@@ -0,0 +1,20 @@
|
||||
import org.junit.Test
|
||||
|
||||
class MyTestClass {
|
||||
[org.junit.Test] fun test1() {}
|
||||
|
||||
org.junit.Test fun test2() {}
|
||||
|
||||
[Test] fun test3() {}
|
||||
|
||||
Test fun test4() {}
|
||||
|
||||
[Deprecated org.junit.Test] fun test5() {}
|
||||
|
||||
[Deprecated Test] fun test6() {}
|
||||
|
||||
fun test7() {}
|
||||
}
|
||||
|
||||
// ANNOTATION: org.junit.Test
|
||||
// SEARCH: PsiMethod:test1, PsiMethod:test2, PsiMethod:test3, PsiMethod:test4, PsiMethod:test5, PsiMethod:test6
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2010-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 org.jetbrains.jet.search;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import com.intellij.util.Query;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.JetLightProjectDescriptor;
|
||||
import org.jetbrains.jet.testing.InTextDirectivesUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractSearcherTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
protected PsiClass getPsiClass(String className) {
|
||||
PsiClass psiClass = JavaPsiFacade.getInstance(getProject()).findClass(className, getGlobalScope());
|
||||
assertNotNull("Couldn't find a psiClass: " + className, psiClass);
|
||||
return psiClass;
|
||||
}
|
||||
|
||||
private GlobalSearchScope getGlobalScope() {
|
||||
return GlobalSearchScope.allScope(getProject());
|
||||
}
|
||||
|
||||
protected GlobalSearchScope getProjectScope() {
|
||||
return GlobalSearchScope.projectScope(getProject());
|
||||
}
|
||||
|
||||
protected void checkResult(Query<?> actual) throws IOException {
|
||||
List<String> expected = InTextDirectivesUtils.findListWithPrefix("// SEARCH: ", FileUtil.loadFile(new File(getPathToFile())));
|
||||
List<String> actualModified = new ArrayList<String>();
|
||||
for (Object member : actual) {
|
||||
actualModified.add(member.toString());
|
||||
}
|
||||
Collections.sort(expected);
|
||||
Collections.sort(actualModified);
|
||||
assertOrderedEquals(actualModified, expected);
|
||||
}
|
||||
|
||||
protected String getPathToFile() {
|
||||
return getTestDataPath() + File.separator + getName() + ".kt";
|
||||
}
|
||||
|
||||
protected String getFileName() {
|
||||
return getName() + ".kt";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JetLightProjectDescriptor.INSTANCE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2010-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 org.jetbrains.jet.search;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.searches.AnnotatedMembersSearch;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import org.jetbrains.jet.testing.InTextDirectivesUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class AnnotatedMembersSearchTest extends AbstractSearcherTest {
|
||||
|
||||
public void testAnnotationsOnClass() throws IOException {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAnnotationsOnFunction() throws IOException {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAnnotationsWithParameters() throws IOException {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws IOException {
|
||||
myFixture.configureByFile(getFileName());
|
||||
List<String> directives = InTextDirectivesUtils.findListWithPrefix("// ANNOTATION: ", FileUtil.loadFile(new File(getPathToFile())));
|
||||
assertFalse("Specify ANNOTATION directive in test file", directives.isEmpty());
|
||||
String annotationClassName = directives.get(0);
|
||||
PsiClass psiClass = getPsiClass(annotationClassName);
|
||||
checkResult(AnnotatedMembersSearch.search(psiClass, getProjectScope()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return new File(PluginTestCaseBase.getTestDataPathBase(), "/search/annotations").getPath() + File.separator;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2010-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 org.jetbrains.jet.search;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import org.jetbrains.jet.testing.InTextDirectivesUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class ClassInheritorsSearchTest extends AbstractSearcherTest {
|
||||
|
||||
public void testInheritanceFromKotlinClass() throws IOException {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInheritanceFromJavaClass() throws IOException {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws IOException {
|
||||
myFixture.configureByFile(getFileName());
|
||||
List<String> directives = InTextDirectivesUtils.findListWithPrefix("// CLASS: ", FileUtil.loadFile(new File(getPathToFile())));
|
||||
assertFalse("Specify CLASS directive in test file", directives.isEmpty());
|
||||
String superClassName = directives.get(0);
|
||||
PsiClass psiClass = getPsiClass(superClassName);
|
||||
checkResult(ClassInheritorsSearch.search(psiClass, getProjectScope(), false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return new File(PluginTestCaseBase.getTestDataPathBase(), "/search/inheritance").getPath() + File.separator;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright 2010-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 org.jetbrains.jet.search;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.module.StdModuleTypes;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.searches.AnnotatedMembersSearch;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import org.jetbrains.jet.testing.InTextDirectivesUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class JUnitMembersSearcherTest extends AbstractSearcherTest {
|
||||
private static final LightProjectDescriptor junitProjectDescriptor = new LightProjectDescriptor() {
|
||||
@Override
|
||||
public ModuleType getModuleType() {
|
||||
return StdModuleTypes.JAVA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sdk getSdk() {
|
||||
return PluginTestCaseBase.jdkFromIdeaHome();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) {
|
||||
Library library = model.getModuleLibraryTable().createLibrary("junit");
|
||||
Library.ModifiableModel modifiableModel = library.getModifiableModel();
|
||||
modifiableModel.addRoot(VfsUtil.getUrlForLibraryRoot(
|
||||
new File(PathManager.getHomePath().replace(File.separatorChar, '/') + "/lib/junit-4.10.jar")),
|
||||
OrderRootType.CLASSES);
|
||||
modifiableModel.commit();
|
||||
}
|
||||
};
|
||||
|
||||
public void testJunit3() throws IOException {
|
||||
myFixture.configureByFile(getFileName());
|
||||
List<String> directives = InTextDirectivesUtils.findListWithPrefix("// CLASS: ", FileUtil.loadFile(new File(getPathToFile())));
|
||||
assertFalse("Specify CLASS directive in test file", directives.isEmpty());
|
||||
String superClassName = directives.get(0);
|
||||
PsiClass psiClass = getPsiClass(superClassName);
|
||||
checkResult(ClassInheritorsSearch.search(psiClass, getProjectScope(), false));
|
||||
}
|
||||
|
||||
public void testJunit4() throws IOException {
|
||||
myFixture.configureByFile(getFileName());
|
||||
List<String> directives = InTextDirectivesUtils.findListWithPrefix("// ANNOTATION: ", FileUtil.loadFile(new File(getPathToFile())));
|
||||
assertFalse("Specify ANNOTATION directive in test file", directives.isEmpty());
|
||||
String annotationClassName = directives.get(0);
|
||||
PsiClass psiClass = getPsiClass(annotationClassName);
|
||||
checkResult(AnnotatedMembersSearch.search(psiClass, getProjectScope()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return new File(PluginTestCaseBase.getTestDataPathBase(), "/search/junit").getPath() + File.separator;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
|
||||
return junitProjectDescriptor;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user