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