Optimize Imports tests: Switch to generated approach
Move test and rename test data Delete unused testdata Rewrite OptimizeImportOnFlyTest
This commit is contained in:
@@ -98,6 +98,7 @@ import org.jetbrains.jet.plugin.navigation.AbstractKotlinGotoTest
|
||||
import org.jetbrains.jet.plugin.AbstractExpressionSelectionTest
|
||||
import org.jetbrains.jet.plugin.refactoring.move.AbstractJetMoveTest
|
||||
import org.jetbrains.jet.plugin.libraries.AbstractDecompiledTextTest
|
||||
import org.jetbrains.jet.plugin.imports.AbstractOptimizeImportsTest
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
System.setProperty("java.awt.headless", "true")
|
||||
@@ -514,6 +515,10 @@ fun main(args: Array<String>) {
|
||||
testClass(javaClass<AbstractDecompiledTextTest>()) {
|
||||
model("libraries/decompiledText", pattern = """^([^\.]+)$""")
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractOptimizeImportsTest>()) {
|
||||
model("editor/optimizeImports", extension = null, recursive = false)
|
||||
}
|
||||
}
|
||||
|
||||
testGroup("j2k/tests/test", "j2k/tests/testData") {
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
import MyJavaClass.TEST
|
||||
|
||||
fun main() {
|
||||
TEST
|
||||
}
|
||||
import MyJavaClass.TEST
|
||||
|
||||
fun main() {
|
||||
TEST
|
||||
}
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
import MyJavaClass
|
||||
import MyJavaClass.TEST
|
||||
|
||||
fun main() {
|
||||
TEST
|
||||
}
|
||||
import MyJavaClass
|
||||
import MyJavaClass.TEST
|
||||
|
||||
fun main() {
|
||||
TEST
|
||||
}
|
||||
+3
-3
@@ -1,3 +1,3 @@
|
||||
public class MyJavaClass {
|
||||
public static String TEST = "test";
|
||||
}
|
||||
public class MyJavaClass {
|
||||
public static String TEST = "test";
|
||||
}
|
||||
+3
-3
@@ -1,3 +1,3 @@
|
||||
import test1.test2
|
||||
|
||||
val s: test2.test3.Class1? = null
|
||||
import test1.test2
|
||||
|
||||
val s: test2.test3.Class1? = null
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
import test1
|
||||
import test1.test2
|
||||
import test1.test2.test3
|
||||
import test1.test2.test3.Class1
|
||||
|
||||
val s: test2.test3.Class1? = null
|
||||
import test1
|
||||
import test1.test2
|
||||
import test1.test2.test3
|
||||
import test1.test2.test3.Class1
|
||||
|
||||
val s: test2.test3.Class1? = null
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
package test1.test2.test3
|
||||
|
||||
public class Class1 {
|
||||
}
|
||||
package test1.test2.test3
|
||||
|
||||
public class Class1 {
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package sometest
|
||||
|
||||
import java.util.HashSet
|
||||
import java.util.ArrayList
|
||||
|
||||
class Action {
|
||||
fun test(hash: HashSet<Int>) {
|
||||
val test : ArrayList<Int>? = null
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package sometest
|
||||
|
||||
import java.util.ArrayList
|
||||
import java.util.HashSet
|
||||
|
||||
class Action {
|
||||
fun test(hash: HashSet<Int>) {
|
||||
val test : ArrayList<Int>? = null
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
import java.util.ArrayList
|
||||
@@ -1 +0,0 @@
|
||||
import java.util.HashSet
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.plugin.importOptimizer;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightTestCase;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.command.UndoConfirmationPolicy;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import org.jetbrains.jet.plugin.imports.KotlinImportOptimizer;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class OptimizeImportsMultiFileTest extends CodeInsightTestCase {
|
||||
|
||||
public void testKotlinPackage() throws Exception {
|
||||
doTest(getTestName(false) + "/main.kt", getTestName(false) + "/kotlinClass.kt");
|
||||
}
|
||||
|
||||
public void testJavaStaticField() throws Exception {
|
||||
doTest(getTestName(false) + "/main.kt", getTestName(false) + "/MyJavaClass.java");
|
||||
}
|
||||
|
||||
public void testArrayAccessExpression() throws Exception {
|
||||
doTest(getTestName(false) + "/main.kt", getTestName(false) + "/myClass.kt");
|
||||
}
|
||||
|
||||
public void testInvokeFunction() throws Exception {
|
||||
doTest(getTestName(false) + "/main.kt", getTestName(false) + "/myClass.kt");
|
||||
}
|
||||
|
||||
public void testIteratorFunction() throws Exception {
|
||||
doTest(getTestName(false) + "/main.kt", getTestName(false) + "/myClass.kt");
|
||||
}
|
||||
|
||||
public void testComponentFunction() throws Exception {
|
||||
doTest(getTestName(false) + "/main.kt", getTestName(false) + "/myClass.kt");
|
||||
}
|
||||
|
||||
public void doTest(String... fileNames) throws Exception {
|
||||
configureByFiles(null, fileNames);
|
||||
invokeFormatFile();
|
||||
checkResultByFile(checkFileName(), true);
|
||||
}
|
||||
|
||||
public String checkFileName() {
|
||||
return getTestName(false) + "/" + getTestName(false) + "_after.kt";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return new File(PluginTestCaseBase.getTestDataPathBase(), "/editor/optimizeImports/multifile").getPath() +
|
||||
File.separator;
|
||||
}
|
||||
|
||||
private void invokeFormatFile() {
|
||||
CommandProcessor.getInstance().executeCommand(
|
||||
getProject(), new KotlinImportOptimizer().processFile(getFile()),
|
||||
"Optimize Imports", null, UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.plugin.importOptimizer;
|
||||
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.command.UndoConfirmationPolicy;
|
||||
import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import org.jetbrains.jet.plugin.imports.KotlinImportOptimizer;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class OptimizeImportsTest extends JetLightCodeInsightFixtureTestCase {
|
||||
public void testAlreadyOptimized() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDefaultJsImports() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testRemoveImportsIfGeneral() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testRemoveImportsIfGeneralBefore() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDuplicatedImports() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testUnusedImports() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testWithAliases() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testKt2488EnumEntry() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testKt1850FullQualified() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testKt1850InnerClass() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPartiallyQualified() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testKt2709() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSamConstructor() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void doTest() throws Exception {
|
||||
myFixture.configureByFile(fileName());
|
||||
invokeOptimizeImports();
|
||||
myFixture.checkResultByFile(checkFileName(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return new File(PluginTestCaseBase.getTestDataPathBase(), "/editor/optimizeImports").getPath() +
|
||||
File.separator;
|
||||
}
|
||||
|
||||
public String checkFileName() {
|
||||
return getTestName(false) + "_after.kt";
|
||||
}
|
||||
|
||||
private void invokeOptimizeImports() {
|
||||
CommandProcessor.getInstance().executeCommand(myFixture.getProject(), new KotlinImportOptimizer().processFile(myFixture.getFile()),
|
||||
"Optimize Imports", null, UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.plugin.imports
|
||||
|
||||
import com.intellij.openapi.command.CommandProcessor
|
||||
import com.intellij.openapi.command.UndoConfirmationPolicy
|
||||
import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase
|
||||
import java.io.File
|
||||
import org.junit.Assert
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase
|
||||
|
||||
public abstract class AbstractOptimizeImportsTest() : JetLightCodeInsightFixtureTestCase() {
|
||||
|
||||
public fun doTest(path: String) {
|
||||
val fixture = myFixture!!
|
||||
fixture.setTestDataPath(path)
|
||||
val (expectedFile, testFiles) = findTestFiles(path)
|
||||
fixture.configureByFiles(*testFiles.map { it.name : String? }.copyToArray())
|
||||
CommandProcessor.getInstance()!!.executeCommand(
|
||||
getProject(),
|
||||
KotlinImportOptimizer().processFile(fixture.getFile()),
|
||||
"Optimize Imports",
|
||||
null,
|
||||
UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION
|
||||
)
|
||||
fixture.checkResultByFile(expectedFile.name, true)
|
||||
}
|
||||
|
||||
private fun findTestFiles(path: String): Pair<File, List<File>> {
|
||||
val files = File(path).listFiles()!!
|
||||
val testName = getTestName(false)
|
||||
|
||||
val expectedFileName = "$testName.after.kt"
|
||||
val expectedFile = files.find { it.name == expectedFileName }
|
||||
Assert.assertNotNull("Can't find $expectedFileName", expectedFile)
|
||||
|
||||
val fileToBeOptimizedName = "$testName.kt"
|
||||
val fileToBeOptimized = files.find { it.name == fileToBeOptimizedName }
|
||||
Assert.assertNotNull("Can't find $fileToBeOptimizedName", fileToBeOptimized)
|
||||
|
||||
val testFiles = listOf(fileToBeOptimized!!) + files.filter { it != fileToBeOptimized && it != expectedFile }
|
||||
return Pair(expectedFile!!, testFiles)
|
||||
}
|
||||
|
||||
override fun getTestDataPath() = "${PluginTestCaseBase.getTestDataPathBase()}/editor/optimizeImports/${getTestName(false)}"
|
||||
}
|
||||
+5
-17
@@ -14,44 +14,32 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.importOptimizer;
|
||||
package org.jetbrains.jet.plugin.imports;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import org.jetbrains.jet.plugin.quickfix.ImportInsertHelper;
|
||||
|
||||
public class OptimizeImportsOnFlyTest extends LightDaemonAnalyzerTestCase {
|
||||
|
||||
public void testOptimizeImportsOnFly() {
|
||||
doTest("java.util.HashSet");
|
||||
}
|
||||
|
||||
public void doTest(final String importString) {
|
||||
configureByFile(getTestName(false) + ".kt");
|
||||
public void testOptimizeImportsOnFly() throws Exception {
|
||||
configureFromFileText("test.kt", "import java.util.ArrayList");
|
||||
boolean oldValue = CodeInsightSettings.getInstance().OPTIMIZE_IMPORTS_ON_THE_FLY;
|
||||
try {
|
||||
CodeInsightSettings.getInstance().OPTIMIZE_IMPORTS_ON_THE_FLY = true;
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ImportInsertHelper.addImportDirectiveIfNeeded(new FqName(importString), (JetFile) getFile());
|
||||
ImportInsertHelper.addImportDirectiveIfNeeded(new FqName("java.util.HashSet"), (JetFile) getFile());
|
||||
}
|
||||
});
|
||||
}
|
||||
finally {
|
||||
CodeInsightSettings.getInstance().OPTIMIZE_IMPORTS_ON_THE_FLY = oldValue;
|
||||
}
|
||||
checkResultByFile(getTestName(false) + ".kt.after");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PluginTestCaseBase.getTestDataPathBase() + "/editor/optimizeImports/onFly/";
|
||||
checkResultByText("import java.util.HashSet");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.plugin.imports;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
|
||||
import org.jetbrains.jet.plugin.imports.AbstractOptimizeImportsTest;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/editor/optimizeImports")
|
||||
public class OptimizeImportsTestGenerated extends AbstractOptimizeImportsTest {
|
||||
public void testAllFilesPresentInOptimizeImports() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/editor/optimizeImports"), Pattern.compile("^([^\\.]+)$"), false);
|
||||
}
|
||||
|
||||
@TestMetadata("AlreadyOptimized")
|
||||
public void testAlreadyOptimized() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/AlreadyOptimized");
|
||||
}
|
||||
|
||||
@TestMetadata("ArrayAccessExpression")
|
||||
public void testArrayAccessExpression() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/ArrayAccessExpression");
|
||||
}
|
||||
|
||||
@TestMetadata("ComponentFunction")
|
||||
public void testComponentFunction() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/ComponentFunction");
|
||||
}
|
||||
|
||||
@TestMetadata("DefaultJsImports")
|
||||
public void testDefaultJsImports() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/DefaultJsImports");
|
||||
}
|
||||
|
||||
@TestMetadata("DuplicatedImports")
|
||||
public void testDuplicatedImports() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/DuplicatedImports");
|
||||
}
|
||||
|
||||
@TestMetadata("InvokeFunction")
|
||||
public void testInvokeFunction() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/InvokeFunction");
|
||||
}
|
||||
|
||||
@TestMetadata("IteratorFunction")
|
||||
public void testIteratorFunction() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/IteratorFunction");
|
||||
}
|
||||
|
||||
@TestMetadata("JavaStaticField")
|
||||
public void testJavaStaticField() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/JavaStaticField");
|
||||
}
|
||||
|
||||
@TestMetadata("KotlinPackage")
|
||||
public void testKotlinPackage() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/KotlinPackage");
|
||||
}
|
||||
|
||||
@TestMetadata("Kt1850FullQualified")
|
||||
public void testKt1850FullQualified() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/Kt1850FullQualified");
|
||||
}
|
||||
|
||||
@TestMetadata("Kt1850InnerClass")
|
||||
public void testKt1850InnerClass() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/Kt1850InnerClass");
|
||||
}
|
||||
|
||||
@TestMetadata("Kt2488EnumEntry")
|
||||
public void testKt2488EnumEntry() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/Kt2488EnumEntry");
|
||||
}
|
||||
|
||||
@TestMetadata("Kt2709")
|
||||
public void testKt2709() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/Kt2709");
|
||||
}
|
||||
|
||||
@TestMetadata("PartiallyQualified")
|
||||
public void testPartiallyQualified() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/PartiallyQualified");
|
||||
}
|
||||
|
||||
@TestMetadata("RemoveImportsIfGeneral")
|
||||
public void testRemoveImportsIfGeneral() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/RemoveImportsIfGeneral");
|
||||
}
|
||||
|
||||
@TestMetadata("RemoveImportsIfGeneralBefore")
|
||||
public void testRemoveImportsIfGeneralBefore() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/RemoveImportsIfGeneralBefore");
|
||||
}
|
||||
|
||||
@TestMetadata("SamConstructor")
|
||||
public void testSamConstructor() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/SamConstructor");
|
||||
}
|
||||
|
||||
@TestMetadata("UnusedImports")
|
||||
public void testUnusedImports() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/UnusedImports");
|
||||
}
|
||||
|
||||
@TestMetadata("WithAliases")
|
||||
public void testWithAliases() throws Exception {
|
||||
doTest("idea/testData/editor/optimizeImports/WithAliases");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user