J2K: AbstractInlineTest
This commit is contained in:
@@ -14,65 +14,51 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.refactoring.inline;
|
package org.jetbrains.kotlin.idea.refactoring.inline
|
||||||
|
|
||||||
import com.intellij.codeInsight.TargetElementUtilBase;
|
import com.intellij.codeInsight.TargetElementUtil
|
||||||
import com.intellij.openapi.application.ApplicationManager;
|
import com.intellij.codeInsight.TargetElementUtil.ELEMENT_NAME_ACCEPTED
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.codeInsight.TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
import com.intellij.refactoring.util.CommonRefactoringUtil
|
||||||
import com.intellij.testFramework.LightProjectDescriptor;
|
import com.intellij.testFramework.UsefulTestCase
|
||||||
import org.jetbrains.annotations.NotNull;
|
import junit.framework.TestCase
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase;
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor;
|
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils;
|
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||||
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
import java.io.File;
|
abstract class AbstractInlineTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||||
import java.io.IOException;
|
protected fun doTest(path: String) {
|
||||||
import java.util.List;
|
val afterFile = File(path + ".after")
|
||||||
|
|
||||||
import static com.intellij.codeInsight.TargetElementUtilBase.ELEMENT_NAME_ACCEPTED;
|
myFixture.configureByFile(path)
|
||||||
import static com.intellij.codeInsight.TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED;
|
|
||||||
|
|
||||||
public abstract class AbstractInlineTest extends KotlinLightCodeInsightFixtureTestCase {
|
val afterFileExists = afterFile.exists()
|
||||||
protected void doTest(@NotNull String path) throws IOException {
|
|
||||||
File afterFile = new File(path + ".after");
|
|
||||||
|
|
||||||
myFixture.configureByFile(path);
|
val targetElement = TargetElementUtil.findTargetElement(myFixture.editor, ELEMENT_NAME_ACCEPTED or REFERENCED_ELEMENT_ACCEPTED)
|
||||||
|
val handler = KotlinInlineValHandler()
|
||||||
|
|
||||||
boolean afterFileExists = afterFile.exists();
|
val expectedErrors = InTextDirectivesUtils.findLinesWithPrefixesRemoved(myFixture.file.text, "// ERROR: ")
|
||||||
|
|
||||||
final PsiElement targetElement =
|
|
||||||
TargetElementUtilBase.findTargetElement(myFixture.getEditor(), ELEMENT_NAME_ACCEPTED | REFERENCED_ELEMENT_ACCEPTED);
|
|
||||||
final KotlinInlineValHandler handler = new KotlinInlineValHandler();
|
|
||||||
|
|
||||||
List<String> expectedErrors = InTextDirectivesUtils.findLinesWithPrefixesRemoved(myFixture.getFile().getText(), "// ERROR: ");
|
|
||||||
if (handler.canInlineElement(targetElement)) {
|
if (handler.canInlineElement(targetElement)) {
|
||||||
try {
|
try {
|
||||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
runWriteAction { handler.inlineElement(myFixture.project, myFixture.editor, targetElement) }
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
handler.inlineElement(myFixture.getProject(), myFixture.getEditor(), targetElement);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
assertTrue(afterFileExists);
|
TestCase.assertTrue(afterFileExists)
|
||||||
assertEmpty(expectedErrors);
|
UsefulTestCase.assertEmpty(expectedErrors)
|
||||||
myFixture.checkResult(FileUtil.loadFile(afterFile, true));
|
myFixture.checkResult(FileUtil.loadFile(afterFile, true))
|
||||||
} catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
|
}
|
||||||
assertFalse(afterFileExists);
|
catch (e: CommonRefactoringUtil.RefactoringErrorHintException) {
|
||||||
assertEquals(1, expectedErrors.size());
|
TestCase.assertFalse(afterFileExists)
|
||||||
assertEquals(expectedErrors.get(0).replace("\\n", "\n"), e.getMessage());
|
TestCase.assertEquals(1, expectedErrors.size)
|
||||||
|
TestCase.assertEquals(expectedErrors[0].replace("\\n", "\n"), e.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assertFalse(afterFileExists);
|
TestCase.assertFalse(afterFileExists)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||||
@Override
|
|
||||||
protected LightProjectDescriptor getProjectDescriptor() {
|
|
||||||
return KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user