Refactor: AnnotatedMembersSearchTest is now generated and J2K'ed

This commit is contained in:
Pavel V. Talanov
2017-04-28 19:56:48 +03:00
parent 55a0e138fc
commit ac92cf8bea
4 changed files with 159 additions and 104 deletions
@@ -166,6 +166,7 @@ import org.jetbrains.kotlin.resolve.constants.evaluate.AbstractCompileTimeConsta
import org.jetbrains.kotlin.resolve.constraintSystem.AbstractConstraintSystemTest
import org.jetbrains.kotlin.samWithReceiver.AbstractSamWithReceiverScriptTest
import org.jetbrains.kotlin.samWithReceiver.AbstractSamWithReceiverTest
import org.jetbrains.kotlin.search.AbstractAnnotatedMembersSearchTest
import org.jetbrains.kotlin.search.AbstractInheritorsSearchTest
import org.jetbrains.kotlin.serialization.AbstractLocalClassProtoTest
import org.jetbrains.kotlin.shortenRefs.AbstractShortenRefsTest
@@ -556,6 +557,10 @@ fun main(args: Array<String>) {
model("search/inheritance")
}
testClass<AbstractAnnotatedMembersSearchTest> {
model("search/annotations")
}
testClass<AbstractQuickFixMultiFileTest> {
model("quickfix", pattern = """^(\w+)\.((before\.Main\.\w+)|(test))$""", testMethod = "doTestWithExtraFile")
}
@@ -1,104 +0,0 @@
/*
* Copyright 2010-2015 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.kotlin.search;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.psi.PsiClass;
import com.intellij.psi.search.searches.AnnotatedMembersSearch;
import com.intellij.testFramework.LightProjectDescriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.idea.search.PsiBasedClassResolver;
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor;
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase;
import org.jetbrains.kotlin.test.InTextDirectivesUtils;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class AnnotatedMembersSearchTest extends AbstractSearcherTest {
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE;
}
public void testAnnotationsOnClass() throws IOException {
doTest();
}
public void testAnnotationsOnFunction() throws IOException {
doTest();
}
public void testAnnotationsWithParameters() throws IOException {
doTest();
}
public void testNestedClassAsAnnotation() throws IOException {
doTest();
}
public void testAmbiguousNestedNonAnnotationClass() throws IOException {
doTest();
}
public void testAmbiguousNestedPrivateAnnotationClass() throws IOException {
doTest();
}
public void testNestedPrivateAnnotationClass() throws IOException {
doTest();
}
public void testTypeAlias() throws IOException {
doTest();
}
public void testDefaultImport() throws IOException {
doTest();
}
private void doTest() throws IOException {
myFixture.configureByFile(getFileName());
String fileText = FileUtil.loadFile(new File(getPathToFile()), true);
List<String> directives = InTextDirectivesUtils.findListWithPrefixes(fileText,
"// ANNOTATION: ");
assertFalse("Specify ANNOTATION directive in test file", directives.isEmpty());
String annotationClassName = directives.get(0);
PsiClass psiClass = getPsiClass(annotationClassName);
PsiBasedClassResolver.Companion.getTrueHits().set(0);
PsiBasedClassResolver.Companion.getFalseHits().set(0);
checkResult(getPathToFile(), AnnotatedMembersSearch.search(psiClass, getProjectScope()));
Integer optimizedTrue = InTextDirectivesUtils.getPrefixedInt(fileText, "// OPTIMIZED_TRUE:");
if (optimizedTrue != null) {
assertEquals(optimizedTrue.intValue(), PsiBasedClassResolver.Companion.getTrueHits().get());
}
Integer optimizedFalse = InTextDirectivesUtils.getPrefixedInt(fileText, "// OPTIMIZED_FALSE:");
if (optimizedFalse != null) {
assertEquals(optimizedFalse.intValue(), PsiBasedClassResolver.Companion.getFalseHits().get());
}
}
@Override
protected String getTestDataPath() {
return new File(PluginTestCaseBase.getTestDataPathBase(), "/search/annotations").getPath() + File.separator;
}
}
@@ -0,0 +1,62 @@
/*
* Copyright 2010-2015 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.kotlin.search
import com.intellij.openapi.util.io.FileUtil
import com.intellij.psi.search.searches.AnnotatedMembersSearch
import com.intellij.testFramework.LightProjectDescriptor
import junit.framework.TestCase
import org.jetbrains.kotlin.idea.search.PsiBasedClassResolver
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import java.io.File
abstract class AbstractAnnotatedMembersSearchTest : AbstractSearcherTest() {
override fun getProjectDescriptor(): LightProjectDescriptor {
return KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
}
fun doTest(path: String) {
myFixture.configureByFile(path)
val fileText = FileUtil.loadFile(File(path), true)
val directives = InTextDirectivesUtils.findListWithPrefixes(fileText, "// ANNOTATION: ")
TestCase.assertFalse("Specify ANNOTATION directive in test file", directives.isEmpty())
val annotationClassName = directives.first()
val psiClass = getPsiClass(annotationClassName)
PsiBasedClassResolver.trueHits.set(0)
PsiBasedClassResolver.falseHits.set(0)
AbstractSearcherTest.checkResult(path, AnnotatedMembersSearch.search(psiClass, projectScope))
val optimizedTrue = InTextDirectivesUtils.getPrefixedInt(fileText, "// OPTIMIZED_TRUE:")
if (optimizedTrue != null) {
TestCase.assertEquals(optimizedTrue.toInt(), PsiBasedClassResolver.trueHits.get())
}
val optimizedFalse = InTextDirectivesUtils.getPrefixedInt(fileText, "// OPTIMIZED_FALSE:")
if (optimizedFalse != null) {
TestCase.assertEquals(optimizedFalse.toInt(), PsiBasedClassResolver.falseHits.get())
}
}
override fun getTestDataPath(): String {
return File(PluginTestCaseBase.getTestDataPathBase(), "/search/annotations").path + File.separator
}
}
@@ -0,0 +1,92 @@
/*
* Copyright 2010-2017 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.kotlin.search;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TargetBackend;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/search/annotations")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class AnnotatedMembersSearchTestGenerated extends AbstractAnnotatedMembersSearchTest {
public void testAllFilesPresentInAnnotations() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/search/annotations"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("testAmbiguousNestedNonAnnotationClass.kt")
public void testTestAmbiguousNestedNonAnnotationClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/search/annotations/testAmbiguousNestedNonAnnotationClass.kt");
doTest(fileName);
}
@TestMetadata("testAmbiguousNestedPrivateAnnotationClass.kt")
public void testTestAmbiguousNestedPrivateAnnotationClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/search/annotations/testAmbiguousNestedPrivateAnnotationClass.kt");
doTest(fileName);
}
@TestMetadata("testAnnotationsOnClass.kt")
public void testTestAnnotationsOnClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/search/annotations/testAnnotationsOnClass.kt");
doTest(fileName);
}
@TestMetadata("testAnnotationsOnFunction.kt")
public void testTestAnnotationsOnFunction() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/search/annotations/testAnnotationsOnFunction.kt");
doTest(fileName);
}
@TestMetadata("testAnnotationsWithParameters.kt")
public void testTestAnnotationsWithParameters() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/search/annotations/testAnnotationsWithParameters.kt");
doTest(fileName);
}
@TestMetadata("testDefaultImport.kt")
public void testTestDefaultImport() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/search/annotations/testDefaultImport.kt");
doTest(fileName);
}
@TestMetadata("testNestedClassAsAnnotation.kt")
public void testTestNestedClassAsAnnotation() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/search/annotations/testNestedClassAsAnnotation.kt");
doTest(fileName);
}
@TestMetadata("testNestedPrivateAnnotationClass.kt")
public void testTestNestedPrivateAnnotationClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/search/annotations/testNestedPrivateAnnotationClass.kt");
doTest(fileName);
}
@TestMetadata("testTypeAlias.kt")
public void testTestTypeAlias() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/search/annotations/testTypeAlias.kt");
doTest(fileName);
}
}