AbstractIntentionTest: cleanup code
This commit is contained in:
@@ -56,12 +56,16 @@ abstract class AbstractIntentionTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (candidateFiles.isEmpty()) {
|
if (candidateFiles.isEmpty()) {
|
||||||
throw AssertionError(".intention file is not found for " + testDataFile +
|
throw AssertionError(
|
||||||
"\nAdd it to base directory of test data. It should contain fully-qualified name of intention class.")
|
".intention file is not found for " + testDataFile +
|
||||||
|
"\nAdd it to base directory of test data. It should contain fully-qualified name of intention class."
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if (candidateFiles.size > 1) {
|
if (candidateFiles.size > 1) {
|
||||||
throw AssertionError("Several .intention files are available for " + testDataFile +
|
throw AssertionError(
|
||||||
"\nPlease remove some of them\n" + candidateFiles)
|
"Several .intention files are available for " + testDataFile +
|
||||||
|
"\nPlease remove some of them\n" + candidateFiles
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val className = FileUtil.loadFile(candidateFiles[0]).trim { it <= ' ' }
|
val className = FileUtil.loadFile(candidateFiles[0]).trim { it <= ' ' }
|
||||||
@@ -79,7 +83,7 @@ abstract class AbstractIntentionTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
sourceFilePaths.add(mainFile.name)
|
sourceFilePaths.add(mainFile.name)
|
||||||
extraFileLoop@ while (true) {
|
extraFileLoop@ while (true) {
|
||||||
for (extension in EXTENSIONS) {
|
for (extension in EXTENSIONS) {
|
||||||
val extraFile = File(parentDir, mainFileName + "." + i + extension)
|
val extraFile = File(parentDir, "$mainFileName.$i$extension")
|
||||||
if (extraFile.exists()) {
|
if (extraFile.exists()) {
|
||||||
sourceFilePaths.add(extraFile.name)
|
sourceFilePaths.add(extraFile.name)
|
||||||
i++
|
i++
|
||||||
@@ -131,8 +135,7 @@ abstract class AbstractIntentionTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
}
|
}
|
||||||
ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, progressIndicator)
|
ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, progressIndicator)
|
||||||
return result.get(10, TimeUnit.SECONDS)
|
return result.get(10, TimeUnit.SECONDS)
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
progressIndicator.cancel()
|
progressIndicator.cancel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,15 +145,22 @@ abstract class AbstractIntentionTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
val isApplicableString = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// ${isApplicableDirectiveName()}: ")
|
val isApplicableString = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// ${isApplicableDirectiveName()}: ")
|
||||||
val isApplicableExpected = isApplicableString == null || isApplicableString == "true"
|
val isApplicableExpected = isApplicableString == null || isApplicableString == "true"
|
||||||
|
|
||||||
val isApplicableOnPooled = computeUnderProgressIndicatorAndWait { ApplicationManager.getApplication().runReadAction(Computable { intentionAction.isAvailable(project, editor, file) }) }
|
val isApplicableOnPooled = computeUnderProgressIndicatorAndWait {
|
||||||
|
ApplicationManager.getApplication().runReadAction(Computable { intentionAction.isAvailable(project, editor, file) })
|
||||||
|
}
|
||||||
|
|
||||||
val isApplicableOnEdt = intentionAction.isAvailable(project, editor, file)
|
val isApplicableOnEdt = intentionAction.isAvailable(project, editor, file)
|
||||||
|
|
||||||
Assert.assertEquals("There should not be any difference what thread isApplicable is called from", isApplicableOnPooled, isApplicableOnEdt)
|
Assert.assertEquals(
|
||||||
|
"There should not be any difference what thread isApplicable is called from",
|
||||||
|
isApplicableOnPooled,
|
||||||
|
isApplicableOnEdt
|
||||||
|
)
|
||||||
|
|
||||||
Assert.assertTrue(
|
Assert.assertTrue(
|
||||||
"isAvailable() for " + intentionAction.javaClass + " should return " + isApplicableExpected,
|
"isAvailable() for " + intentionAction.javaClass + " should return " + isApplicableExpected,
|
||||||
isApplicableExpected == isApplicableOnEdt)
|
isApplicableExpected == isApplicableOnEdt
|
||||||
|
)
|
||||||
|
|
||||||
val intentionTextString = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// " + intentionTextDirectiveName() + ": ")
|
val intentionTextString = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// " + intentionTextDirectiveName() + ": ")
|
||||||
|
|
||||||
@@ -162,11 +172,8 @@ abstract class AbstractIntentionTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (isApplicableExpected) {
|
if (isApplicableExpected) {
|
||||||
project.executeWriteCommand(
|
project.executeWriteCommand(intentionAction.text) {
|
||||||
intentionAction.text, null
|
|
||||||
) {
|
|
||||||
intentionAction.invoke(project, editor, file)
|
intentionAction.invoke(project, editor, file)
|
||||||
null
|
|
||||||
}
|
}
|
||||||
// Don't bother checking if it should have failed.
|
// Don't bother checking if it should have failed.
|
||||||
if (shouldFailString.isEmpty()) {
|
if (shouldFailString.isEmpty()) {
|
||||||
@@ -175,25 +182,21 @@ abstract class AbstractIntentionTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
if (filePath == mainFilePath) {
|
if (filePath == mainFilePath) {
|
||||||
try {
|
try {
|
||||||
myFixture.checkResultByFile(canonicalPathToExpectedFile)
|
myFixture.checkResultByFile(canonicalPathToExpectedFile)
|
||||||
}
|
} catch (e: ComparisonFailure) {
|
||||||
catch (e: ComparisonFailure) {
|
|
||||||
KotlinTestUtils
|
KotlinTestUtils
|
||||||
.assertEqualsToFile(File(testDataPath, canonicalPathToExpectedFile), editor.document.text)
|
.assertEqualsToFile(File(testDataPath, canonicalPathToExpectedFile), editor.document.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
KotlinTestUtils.assertEqualsToFile(File(testDataPath, canonicalPathToExpectedFile), value.text)
|
KotlinTestUtils.assertEqualsToFile(File(testDataPath, canonicalPathToExpectedFile), value.text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TestCase.assertEquals("Expected test to fail.", "", shouldFailString)
|
TestCase.assertEquals("Expected test to fail.", "", shouldFailString)
|
||||||
}
|
} catch (e: BaseRefactoringProcessor.ConflictsInTestsException) {
|
||||||
catch (e: BaseRefactoringProcessor.ConflictsInTestsException) {
|
|
||||||
TestCase.assertEquals("Failure message mismatch.", shouldFailString, StringUtil.join(e.messages.sorted(), ", "))
|
TestCase.assertEquals("Failure message mismatch.", shouldFailString, StringUtil.join(e.messages.sorted(), ", "))
|
||||||
}
|
} catch (e: CommonRefactoringUtil.RefactoringErrorHintException) {
|
||||||
catch (e: CommonRefactoringUtil.RefactoringErrorHintException) {
|
|
||||||
TestCase.assertEquals("Failure message mismatch.", shouldFailString, e.message?.replace('\n', ' '))
|
TestCase.assertEquals("Failure message mismatch.", shouldFailString, e.message?.replace('\n', ' '))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user