From 6795622202a5c9cef4de780a4d290fc2079c2f7f Mon Sep 17 00:00:00 2001 From: chrisly42 Date: Sun, 9 Jun 2019 14:17:44 +0200 Subject: [PATCH] Finally was able to remove JUnit workaround for test invokation with availability of JUnit 5.5.0-RC1. --- build.gradle | 4 +- .../jupiter/LightCodeInsightExtension.java | 43 +++++++++++-- ...roundUntilJupiterGetsExecutorProvider.java | 44 -------------- .../plugins/cajon/AbstractCajonTest.kt | 43 ------------- ...ssertThatBinaryExpressionInspectionTest.kt | 12 ++-- ...ssertThatBooleanConditionInspectionTest.kt | 16 +++-- ...CollectionOrMapExpressionInspectionTest.kt | 26 ++++---- ...sertThatEnumerableIsEmptyInspectionTest.kt | 10 ++-- .../AssertThatGuavaOptionalInspectionTest.kt | 50 +++++++--------- .../AssertThatInstanceOfInspectionTest.kt | 12 ++-- ...tInvertedBooleanConditionInspectionTest.kt | 10 ++-- .../AssertThatJava8OptionalInspectionTest.kt | 26 ++++---- ...ThatObjectIsNullOrNotNullInspectionTest.kt | 12 ++-- .../AssertThatSizeInspectionTest.kt | 38 ++++++------ ...ssertThatStringExpressionInspectionTest.kt | 36 ++++++----- .../AssertThatStringIsEmptyInspectionTest.kt | 22 ++++--- ...AssumeThatInsteadOfReturnInspectionTest.kt | 10 ++-- .../ImplicitAssertionInspectionTest.kt | 14 ++--- .../JUnitAssertToAssertJInspectionTest.kt | 12 ++-- .../JoinAssertThatStatementsInspectionTest.kt | 10 ++-- .../ExtractorReferenceContributorTest.kt | 60 +++++++------------ 21 files changed, 201 insertions(+), 309 deletions(-) delete mode 100644 src/test/java/de/platon42/intellij/jupiter/WorkaroundUntilJupiterGetsExecutorProvider.java diff --git a/build.gradle b/build.gradle index 0fa2e8c..dda7cf8 100644 --- a/build.gradle +++ b/build.gradle @@ -22,8 +22,8 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" testCompile "org.assertj:assertj-core:3.12.2" testCompile "org.assertj:assertj-guava:3.2.1" - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.0' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.0' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.0-RC1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.0-RC1' testImplementation "org.jetbrains.kotlin:kotlin-test" // testImplementation "org.jetbrains.kotlin:kotlin-test-junit" } diff --git a/src/test/java/de/platon42/intellij/jupiter/LightCodeInsightExtension.java b/src/test/java/de/platon42/intellij/jupiter/LightCodeInsightExtension.java index 66a67f6..ff78afc 100644 --- a/src/test/java/de/platon42/intellij/jupiter/LightCodeInsightExtension.java +++ b/src/test/java/de/platon42/intellij/jupiter/LightCodeInsightExtension.java @@ -8,9 +8,8 @@ import com.intellij.openapi.roots.ModifiableRootModel; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.testFramework.LightProjectDescriptor; -import com.intellij.testFramework.PsiTestUtil; -import com.intellij.testFramework.UsefulTestCase; +import com.intellij.testFramework.*; +import com.intellij.testFramework.fixtures.IdeaTestExecutionPolicy; import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; import org.jetbrains.annotations.NotNull; @@ -19,6 +18,7 @@ import org.junit.jupiter.api.extension.ExtensionContext.Namespace; import org.junit.jupiter.api.extension.ExtensionContext.Store; import java.lang.annotation.Annotation; +import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.net.URISyntaxException; import java.nio.file.Path; @@ -26,7 +26,7 @@ import java.nio.file.Paths; import java.util.logging.Logger; import java.util.stream.Stream; -public class LightCodeInsightExtension implements ParameterResolver, AfterTestExecutionCallback { +public class LightCodeInsightExtension implements ParameterResolver, AfterTestExecutionCallback, InvocationInterceptor { private static final Logger LOG = Logger.getLogger(LightCodeInsightExtension.class.getName()); @@ -77,6 +77,41 @@ public class LightCodeInsightExtension implements ParameterResolver, AfterTestEx return context.getStore(Namespace.create(LightCodeInsightExtension.class, context.getRequiredTestMethod())); } + @Override + public void interceptTestMethod(Invocation invocation, ReflectiveInvocationContext invocationContext, ExtensionContext extensionContext) throws Throwable { + Throwable[] throwables = new Throwable[1]; + + Runnable runnable = () -> { + try { + TestLoggerFactory.onTestStarted(); + invocation.proceed(); + TestLoggerFactory.onTestFinished(true); + } catch (Throwable e) { + TestLoggerFactory.onTestFinished(false); + e.fillInStackTrace(); + throwables[0] = e; + } + }; + + invokeTestRunnable(runnable); + + if (throwables[0] != null) { + throw throwables[0]; + } + } + + private static void invokeTestRunnable(@NotNull Runnable runnable) { + IdeaTestExecutionPolicy policy = IdeaTestExecutionPolicy.current(); + if (policy != null && !policy.runInDispatchThread()) { + runnable.run(); + } else { + EdtTestUtilKt.runInEdtAndWait(() -> { + runnable.run(); + return null; + }); + } + } + private static class LightCodeInsightFixtureTestCaseWrapper extends LightCodeInsightFixtureTestCase { private final ExtensionContext extensionContext; diff --git a/src/test/java/de/platon42/intellij/jupiter/WorkaroundUntilJupiterGetsExecutorProvider.java b/src/test/java/de/platon42/intellij/jupiter/WorkaroundUntilJupiterGetsExecutorProvider.java deleted file mode 100644 index 600b3c7..0000000 --- a/src/test/java/de/platon42/intellij/jupiter/WorkaroundUntilJupiterGetsExecutorProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -package de.platon42.intellij.jupiter; - -import com.intellij.testFramework.EdtTestUtilKt; -import com.intellij.testFramework.TestLoggerFactory; -import com.intellij.testFramework.fixtures.IdeaTestExecutionPolicy; -import org.jetbrains.annotations.NotNull; - -// See https://github.com/junit-team/junit5/issues/157 -public class WorkaroundUntilJupiterGetsExecutorProvider { - - protected static void runTest(Runnable test) throws Throwable { - Throwable[] throwables = new Throwable[1]; - - Runnable runnable = () -> { - try { - TestLoggerFactory.onTestStarted(); - test.run(); - TestLoggerFactory.onTestFinished(true); - } catch (Throwable e) { - TestLoggerFactory.onTestFinished(false); - e.fillInStackTrace(); - throwables[0] = e; - } - }; - - invokeTestRunnable(runnable); - - if (throwables[0] != null) { - throw throwables[0]; - } - } - - private static void invokeTestRunnable(@NotNull Runnable runnable) { - IdeaTestExecutionPolicy policy = IdeaTestExecutionPolicy.current(); - if (policy != null && !policy.runInDispatchThread()) { - runnable.run(); - } else { - EdtTestUtilKt.runInEdtAndWait(() -> { - runnable.run(); - return null; - }); - } - } -} diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/AbstractCajonTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/AbstractCajonTest.kt index 933223a..22619fb 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/AbstractCajonTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/AbstractCajonTest.kt @@ -1,10 +1,7 @@ package de.platon42.intellij.plugins.cajon import com.intellij.pom.java.LanguageLevel -import com.intellij.testFramework.TestLoggerFactory -import com.intellij.testFramework.fixtures.IdeaTestExecutionPolicy import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture -import com.intellij.testFramework.runInEdtAndWait import de.platon42.intellij.jupiter.AddLocalJarToModule import de.platon42.intellij.jupiter.LightCodeInsightExtension import de.platon42.intellij.jupiter.TestDataPath @@ -14,7 +11,6 @@ import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.DisplayNameGeneration import org.junit.jupiter.api.DisplayNameGenerator import org.junit.jupiter.api.extension.ExtendWith -import java.lang.reflect.InvocationTargetException import java.lang.reflect.Method @ExtendWith(LightCodeInsightExtension::class) @@ -24,45 +20,6 @@ import java.lang.reflect.Method @DisplayNameGeneration(AbstractCajonTest.CutOffFixtureDisplayNameGenerator::class) abstract class AbstractCajonTest { - // See https://github.com/junit-team/junit5/issues/157, should be resolved with junit5 5.5 M2 - protected fun runTest(body: () -> Unit) { - val throwables = arrayOfNulls(1) - - invokeTestRunnable { - try { - TestLoggerFactory.onTestStarted() - body() - TestLoggerFactory.onTestFinished(true) - } catch (e: InvocationTargetException) { - TestLoggerFactory.onTestFinished(false) - e.fillInStackTrace() - throwables[0] = e.targetException - } catch (e: IllegalAccessException) { - TestLoggerFactory.onTestFinished(false) - e.fillInStackTrace() - throwables[0] = e - } catch (e: Throwable) { - TestLoggerFactory.onTestFinished(false) - throwables[0] = e - } - } - - if (throwables[0] != null) { - throw throwables[0]!! - } - } - - private fun invokeTestRunnable(runnable: () -> Unit) { - val policy = IdeaTestExecutionPolicy.current() - if (policy != null && !policy.runInDispatchThread()) { - runnable() - } else { - runInEdtAndWait { - runnable() - } - } - } - protected fun executeQuickFixes(myFixture: JavaCodeInsightTestFixture, regex: Regex, expectedFixes: Int) { val quickfixes = myFixture.getAllQuickFixes().filter { it.text.matches(regex) } assertThat(quickfixes).`as`("Fixes matched by $regex: ${myFixture.getAllQuickFixes().map { it.text }}").hasSize(expectedFixes) diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspectionTest.kt index e883a79..20d1970 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBinaryExpressionInspectionTest.kt @@ -11,12 +11,10 @@ internal class AssertThatBinaryExpressionInspectionTest : AbstractCajonTest() { @Test @TestDataSubPath("inspections/BinaryExpression") internal fun assertThat_of_binary_expression_can_be_moved_out(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(AssertThatBinaryExpressionInspection::class.java) - myFixture.configureByFile("BinaryExpressionBefore.java") - executeQuickFixes(myFixture, Regex.fromLiteral("Split binary expression out of assertThat()"), 149) - executeQuickFixes(myFixture, Regex.fromLiteral("Split equals() expression out of assertThat()"), 13) - myFixture.checkResultByFile("BinaryExpressionAfter.java") - } + myFixture.enableInspections(AssertThatBinaryExpressionInspection::class.java) + myFixture.configureByFile("BinaryExpressionBefore.java") + executeQuickFixes(myFixture, Regex.fromLiteral("Split binary expression out of assertThat()"), 149) + executeQuickFixes(myFixture, Regex.fromLiteral("Split equals() expression out of assertThat()"), 13) + myFixture.checkResultByFile("BinaryExpressionAfter.java") } } \ No newline at end of file diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBooleanConditionInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBooleanConditionInspectionTest.kt index 63c4e7c..9ca3354 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBooleanConditionInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatBooleanConditionInspectionTest.kt @@ -11,14 +11,12 @@ internal class AssertThatBooleanConditionInspectionTest : AbstractCajonTest() { @Test @TestDataSubPath("inspections/BooleanCondition") internal fun assertThat_with_isEqualTo_true_or_false_can_use_isTrue_or_isFalse(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(AssertThatBooleanConditionInspection::class.java) - myFixture.configureByFile("BooleanConditionBefore.java") - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isTrue()"), 6) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isFalse()"), 5) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with isTrue()"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with isFalse()"), 4) - myFixture.checkResultByFile("BooleanConditionAfter.java") - } + myFixture.enableInspections(AssertThatBooleanConditionInspection::class.java) + myFixture.configureByFile("BooleanConditionBefore.java") + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isTrue()"), 6) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isFalse()"), 5) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with isTrue()"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with isFalse()"), 4) + myFixture.checkResultByFile("BooleanConditionAfter.java") } } \ No newline at end of file diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatCollectionOrMapExpressionInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatCollectionOrMapExpressionInspectionTest.kt index c27661e..7953087 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatCollectionOrMapExpressionInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatCollectionOrMapExpressionInspectionTest.kt @@ -11,19 +11,17 @@ internal class AssertThatCollectionOrMapExpressionInspectionTest : AbstractCajon @Test @TestDataSubPath("inspections/CollectionMapExpression") internal fun assertThat_with_certain_Collection_and_Map_methods(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(AssertThatCollectionOrMapExpressionInspection::class.java) - myFixture.configureByFile("CollectionMapExpressionBefore.java") - executeQuickFixes(myFixture, Regex.fromLiteral("Remove isEmpty() of actual expression and use assertThat().isEmpty() instead"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove contains() of actual expression and use assertThat().contains() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove containsAll() of actual expression and use assertThat().containsAll() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove containsKey() of actual expression and use assertThat().containsKey() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove containsValue() of actual expression and use assertThat().containsValue() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove isEmpty() of actual expression and use assertThat().isNotEmpty() instead"), 5) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove contains() of actual expression and use assertThat().doesNotContain() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove containsKey() of actual expression and use assertThat().doesNotContainKey() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove containsValue() of actual expression and use assertThat().doesNotContainValue() instead"), 2) - myFixture.checkResultByFile("CollectionMapExpressionAfter.java") - } + myFixture.enableInspections(AssertThatCollectionOrMapExpressionInspection::class.java) + myFixture.configureByFile("CollectionMapExpressionBefore.java") + executeQuickFixes(myFixture, Regex.fromLiteral("Remove isEmpty() of actual expression and use assertThat().isEmpty() instead"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove contains() of actual expression and use assertThat().contains() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove containsAll() of actual expression and use assertThat().containsAll() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove containsKey() of actual expression and use assertThat().containsKey() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove containsValue() of actual expression and use assertThat().containsValue() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove isEmpty() of actual expression and use assertThat().isNotEmpty() instead"), 5) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove contains() of actual expression and use assertThat().doesNotContain() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove containsKey() of actual expression and use assertThat().doesNotContainKey() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove containsValue() of actual expression and use assertThat().doesNotContainValue() instead"), 2) + myFixture.checkResultByFile("CollectionMapExpressionAfter.java") } } \ No newline at end of file diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatEnumerableIsEmptyInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatEnumerableIsEmptyInspectionTest.kt index 83c2efa..9abd8fd 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatEnumerableIsEmptyInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatEnumerableIsEmptyInspectionTest.kt @@ -11,11 +11,9 @@ internal class AssertThatEnumerableIsEmptyInspectionTest : AbstractCajonTest() { @Test @TestDataSubPath("inspections/EnumerableIsEmpty") internal fun assertThat_with_hasSize_zero_can_use_isEmpty(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(AssertThatEnumerableIsEmptyInspection::class.java) - myFixture.configureByFile("EnumerableIsEmptyBefore.java") - executeQuickFixes(myFixture, Regex.fromLiteral("Replace hasSize() with isEmpty()"), 5) - myFixture.checkResultByFile("EnumerableIsEmptyAfter.java") - } + myFixture.enableInspections(AssertThatEnumerableIsEmptyInspection::class.java) + myFixture.configureByFile("EnumerableIsEmptyBefore.java") + executeQuickFixes(myFixture, Regex.fromLiteral("Replace hasSize() with isEmpty()"), 5) + myFixture.checkResultByFile("EnumerableIsEmptyAfter.java") } } \ No newline at end of file diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatGuavaOptionalInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatGuavaOptionalInspectionTest.kt index 7835055..c807283 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatGuavaOptionalInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatGuavaOptionalInspectionTest.kt @@ -14,41 +14,35 @@ internal class AssertThatGuavaOptionalInspectionTest : AbstractCajonTest() { @Test internal fun assertThat_get_or_isPresent_for_Guava_Optional_can_be_simplified(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(AssertThatGuavaOptionalInspection::class.java) - myFixture.configureByFile("GuavaOptionalBefore.java") - executeQuickFixes(myFixture, Regex.fromLiteral("Remove isPresent() of actual expression and use assertThat().isPresent() instead"), 6) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove isPresent() of actual expression and use assertThat().isAbsent() instead"), 5) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove orNull() of actual expression and use assertThat().isPresent() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove orNull() of actual expression and use assertThat().isAbsent() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove get() of actual expression and use assertThat().contains() instead"), 1) - executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap expected expression and replace isEqualTo() with contains()"), 6) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with Guava assertThat().isAbsent()"), 3) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with Guava assertThat().isPresent()"), 3) - myFixture.checkResultByFile("GuavaOptionalAfter.java") - } + myFixture.enableInspections(AssertThatGuavaOptionalInspection::class.java) + myFixture.configureByFile("GuavaOptionalBefore.java") + executeQuickFixes(myFixture, Regex.fromLiteral("Remove isPresent() of actual expression and use assertThat().isPresent() instead"), 6) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove isPresent() of actual expression and use assertThat().isAbsent() instead"), 5) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove orNull() of actual expression and use assertThat().isPresent() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove orNull() of actual expression and use assertThat().isAbsent() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove get() of actual expression and use assertThat().contains() instead"), 1) + executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap expected expression and replace isEqualTo() with contains()"), 6) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with Guava assertThat().isAbsent()"), 3) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with Guava assertThat().isPresent()"), 3) + myFixture.checkResultByFile("GuavaOptionalAfter.java") } @Test internal fun adds_missing_Guava_import_any_order(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(AssertThatGuavaOptionalInspection::class.java) - myFixture.configureByFile("WithoutPriorGuavaImportBefore.java") - executeQuickFixes(myFixture, Regex(".*eplace .* with .*"), 4) - executeQuickFixes(myFixture, Regex("Remove .*"), 3) - myFixture.checkResultByFile("WithoutPriorGuavaImportAfter.java") - } + myFixture.enableInspections(AssertThatGuavaOptionalInspection::class.java) + myFixture.configureByFile("WithoutPriorGuavaImportBefore.java") + executeQuickFixes(myFixture, Regex(".*eplace .* with .*"), 4) + executeQuickFixes(myFixture, Regex("Remove .*"), 3) + myFixture.checkResultByFile("WithoutPriorGuavaImportAfter.java") } @Test internal fun adds_missing_Guava_import_isAbsent_first(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(AssertThatGuavaOptionalInspection::class.java) - myFixture.configureByFile("WithoutPriorGuavaImportBefore.java") - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with Guava assertThat().isAbsent()"), 1) - executeQuickFixes(myFixture, Regex(".*eplace .* with .*"), 3) - executeQuickFixes(myFixture, Regex("Remove .*"), 3) - myFixture.checkResultByFile("WithoutPriorGuavaImportAfter.java") - } + myFixture.enableInspections(AssertThatGuavaOptionalInspection::class.java) + myFixture.configureByFile("WithoutPriorGuavaImportBefore.java") + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with Guava assertThat().isAbsent()"), 1) + executeQuickFixes(myFixture, Regex(".*eplace .* with .*"), 3) + executeQuickFixes(myFixture, Regex("Remove .*"), 3) + myFixture.checkResultByFile("WithoutPriorGuavaImportAfter.java") } } \ No newline at end of file diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatInstanceOfInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatInstanceOfInspectionTest.kt index 789e5d9..c0901e0 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatInstanceOfInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatInstanceOfInspectionTest.kt @@ -11,12 +11,10 @@ internal class AssertThatInstanceOfInspectionTest : AbstractCajonTest() { @Test @TestDataSubPath("inspections/InstanceOf") internal fun assertThat_with_instanceof_can_be_moved_out(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(AssertThatInstanceOfInspection::class.java) - myFixture.configureByFile("InstanceOfBefore.java") - executeQuickFixes(myFixture, Regex.fromLiteral("Remove instanceof in actual expression and use assertThat().isInstanceOf() instead"), 6) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove instanceof in actual expression and use assertThat().isNotInstanceOf() instead"), 6) - myFixture.checkResultByFile("InstanceOfAfter.java") - } + myFixture.enableInspections(AssertThatInstanceOfInspection::class.java) + myFixture.configureByFile("InstanceOfBefore.java") + executeQuickFixes(myFixture, Regex.fromLiteral("Remove instanceof in actual expression and use assertThat().isInstanceOf() instead"), 6) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove instanceof in actual expression and use assertThat().isNotInstanceOf() instead"), 6) + myFixture.checkResultByFile("InstanceOfAfter.java") } } \ No newline at end of file diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatInvertedBooleanConditionInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatInvertedBooleanConditionInspectionTest.kt index 66cc02f..09a9379 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatInvertedBooleanConditionInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatInvertedBooleanConditionInspectionTest.kt @@ -11,11 +11,9 @@ internal class AssertThatInvertedBooleanConditionInspectionTest : AbstractCajonT @Test @TestDataSubPath("inspections/InvertedBooleanCondition") internal fun assertThat_with_inverted_boolean_condition_can_be_inverted(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(AssertThatInvertedBooleanConditionInspection::class.java) - myFixture.configureByFile("InvertedBooleanConditionBefore.java") - executeQuickFixes(myFixture, Regex.fromLiteral("Invert condition in assertThat()"), 25) - myFixture.checkResultByFile("InvertedBooleanConditionAfter.java") - } + myFixture.enableInspections(AssertThatInvertedBooleanConditionInspection::class.java) + myFixture.configureByFile("InvertedBooleanConditionBefore.java") + executeQuickFixes(myFixture, Regex.fromLiteral("Invert condition in assertThat()"), 25) + myFixture.checkResultByFile("InvertedBooleanConditionAfter.java") } } \ No newline at end of file diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatJava8OptionalInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatJava8OptionalInspectionTest.kt index 9c547d5..1bc7467 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatJava8OptionalInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatJava8OptionalInspectionTest.kt @@ -11,19 +11,17 @@ internal class AssertThatJava8OptionalInspectionTest : AbstractCajonTest() { @Test @TestDataSubPath("inspections/Java8Optional") internal fun assertThat_get_or_isPresent_for_Java8_Optional_can_be_simplified(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(AssertThatJava8OptionalInspection::class.java) - myFixture.configureByFile("Java8OptionalBefore.java") - executeQuickFixes(myFixture, Regex.fromLiteral("Remove isPresent() of actual expression and use assertThat().isPresent() instead"), 6) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove isPresent() of actual expression and use assertThat().isNotPresent() instead"), 5) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove orElse() of actual expression and use assertThat().isPresent() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove orElse() of actual expression and use assertThat().isNotPresent() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove get() of actual expression and use assertThat().contains() instead"), 1) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove get() of actual expression and use assertThat().containsSame() instead"), 1) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isNotPresent()"), 1) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with isPresent()"), 1) - executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap expected expression and replace isEqualTo() with contains()"), 2) - myFixture.checkResultByFile("Java8OptionalAfter.java") - } + myFixture.enableInspections(AssertThatJava8OptionalInspection::class.java) + myFixture.configureByFile("Java8OptionalBefore.java") + executeQuickFixes(myFixture, Regex.fromLiteral("Remove isPresent() of actual expression and use assertThat().isPresent() instead"), 6) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove isPresent() of actual expression and use assertThat().isNotPresent() instead"), 5) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove orElse() of actual expression and use assertThat().isPresent() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove orElse() of actual expression and use assertThat().isNotPresent() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove get() of actual expression and use assertThat().contains() instead"), 1) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove get() of actual expression and use assertThat().containsSame() instead"), 1) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isNotPresent()"), 1) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with isPresent()"), 1) + executeQuickFixes(myFixture, Regex.fromLiteral("Unwrap expected expression and replace isEqualTo() with contains()"), 2) + myFixture.checkResultByFile("Java8OptionalAfter.java") } } \ No newline at end of file diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatObjectIsNullOrNotNullInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatObjectIsNullOrNotNullInspectionTest.kt index f15b99f..8ab6b0b 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatObjectIsNullOrNotNullInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatObjectIsNullOrNotNullInspectionTest.kt @@ -11,12 +11,10 @@ internal class AssertThatObjectIsNullOrNotNullInspectionTest : AbstractCajonTest @Test @TestDataSubPath("inspections/ObjectIsNullOrNotNull") internal fun assertThat_with_isEqualTo_null_can_use_isNull(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(AssertThatObjectIsNullOrNotNullInspection::class.java) - myFixture.configureByFile("ObjectIsNullOrNotNullBefore.java") - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isNull()"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with isNotNull()"), 5) - myFixture.checkResultByFile("ObjectIsNullOrNotNullAfter.java") - } + myFixture.enableInspections(AssertThatObjectIsNullOrNotNullInspection::class.java) + myFixture.configureByFile("ObjectIsNullOrNotNullBefore.java") + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isNull()"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotEqualTo() with isNotNull()"), 5) + myFixture.checkResultByFile("ObjectIsNullOrNotNullAfter.java") } } \ No newline at end of file diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatSizeInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatSizeInspectionTest.kt index 5934277..5a6cb7a 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatSizeInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatSizeInspectionTest.kt @@ -13,26 +13,24 @@ internal class AssertThatSizeInspectionTest : AbstractCajonTest() { @Test @TestDataSubPath("inspections/Size") internal fun assertThat_size_of_array_or_collection_can_be_simplified(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(AssertThatSizeInspection::class.java) - myFixture.configureByFile("SizeBefore.java") - assertThat(myFixture.doHighlighting()).extrakting { it.description }.containsOnlyOnce("Try to operate on the iterable itself rather than its size") + myFixture.enableInspections(AssertThatSizeInspection::class.java) + myFixture.configureByFile("SizeBefore.java") + assertThat(myFixture.doHighlighting()).extrakting { it.description }.containsOnlyOnce("Try to operate on the iterable itself rather than its size") - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isEmpty()"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isZero() with isEmpty()"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotZero() with isNotEmpty()"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isGreaterThan() with isNotEmpty()"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isGreaterThanOrEqualTo() with isNotEmpty()"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isLessThan() with isEmpty()"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isLessThanOrEqualTo() with isEmpty()"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with hasSameSizeAs()"), 12) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with hasSize()"), 8) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isGreaterThan() with hasSizeGreaterThan()"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isGreaterThanOrEqualTo() with hasSizeGreaterThanOrEqualTo()"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isLessThan() with hasSizeLessThan()"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isLessThanOrEqualTo() with hasSizeLessThanOrEqualTo()"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove size determination of expected expression and replace hasSize() with hasSameSizeAs()"), 14) - myFixture.checkResultByFile("SizeAfter.java") - } + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isEmpty()"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isZero() with isEmpty()"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isNotZero() with isNotEmpty()"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isGreaterThan() with isNotEmpty()"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isGreaterThanOrEqualTo() with isNotEmpty()"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isLessThan() with isEmpty()"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isLessThanOrEqualTo() with isEmpty()"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with hasSameSizeAs()"), 12) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with hasSize()"), 8) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isGreaterThan() with hasSizeGreaterThan()"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isGreaterThanOrEqualTo() with hasSizeGreaterThanOrEqualTo()"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isLessThan() with hasSizeLessThan()"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isLessThanOrEqualTo() with hasSizeLessThanOrEqualTo()"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove size determination of expected expression and replace hasSize() with hasSameSizeAs()"), 14) + myFixture.checkResultByFile("SizeAfter.java") } } \ No newline at end of file diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatStringExpressionInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatStringExpressionInspectionTest.kt index 0c66936..b3fc232 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatStringExpressionInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatStringExpressionInspectionTest.kt @@ -11,24 +11,22 @@ internal class AssertThatStringExpressionInspectionTest : AbstractCajonTest() { @Test @TestDataSubPath("inspections/StringExpression") internal fun assertThat_with_certain_String_methods(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(AssertThatStringExpressionInspection::class.java) - myFixture.configureByFile("StringExpressionBefore.java") - executeQuickFixes(myFixture, Regex.fromLiteral("Remove isEmpty() of actual expression and use assertThat().isEmpty() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove equals() of actual expression and use assertThat().isEqualTo() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove equalsIgnoreCase() of actual expression and use assertThat().isEqualToIgnoringCase() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove contentEquals() of actual expression and use assertThat().isEqualTo() instead"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove contains() of actual expression and use assertThat().contains() instead"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove startsWith() of actual expression and use assertThat().startsWith() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove endsWith() of actual expression and use assertThat().endsWith() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove isEmpty() of actual expression and use assertThat().isNotEmpty() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove equals() of actual expression and use assertThat().isNotEqualTo() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove equalsIgnoreCase() of actual expression and use assertThat().isNotEqualToIgnoringCase() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove contentEquals() of actual expression and use assertThat().isNotEqualTo() instead"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove contains() of actual expression and use assertThat().doesNotContain() instead"), 4) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove startsWith() of actual expression and use assertThat().doesNotStartWith() instead"), 2) - executeQuickFixes(myFixture, Regex.fromLiteral("Remove endsWith() of actual expression and use assertThat().doesNotEndWith() instead"), 3) - myFixture.checkResultByFile("StringExpressionAfter.java") - } + myFixture.enableInspections(AssertThatStringExpressionInspection::class.java) + myFixture.configureByFile("StringExpressionBefore.java") + executeQuickFixes(myFixture, Regex.fromLiteral("Remove isEmpty() of actual expression and use assertThat().isEmpty() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove equals() of actual expression and use assertThat().isEqualTo() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove equalsIgnoreCase() of actual expression and use assertThat().isEqualToIgnoringCase() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove contentEquals() of actual expression and use assertThat().isEqualTo() instead"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove contains() of actual expression and use assertThat().contains() instead"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove startsWith() of actual expression and use assertThat().startsWith() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove endsWith() of actual expression and use assertThat().endsWith() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove isEmpty() of actual expression and use assertThat().isNotEmpty() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove equals() of actual expression and use assertThat().isNotEqualTo() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove equalsIgnoreCase() of actual expression and use assertThat().isNotEqualToIgnoringCase() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove contentEquals() of actual expression and use assertThat().isNotEqualTo() instead"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove contains() of actual expression and use assertThat().doesNotContain() instead"), 4) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove startsWith() of actual expression and use assertThat().doesNotStartWith() instead"), 2) + executeQuickFixes(myFixture, Regex.fromLiteral("Remove endsWith() of actual expression and use assertThat().doesNotEndWith() instead"), 3) + myFixture.checkResultByFile("StringExpressionAfter.java") } } \ No newline at end of file diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatStringIsEmptyInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatStringIsEmptyInspectionTest.kt index 5ef11ad..d917259 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatStringIsEmptyInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssertThatStringIsEmptyInspectionTest.kt @@ -13,17 +13,15 @@ internal class AssertThatStringIsEmptyInspectionTest : AbstractCajonTest() { @Test @TestDataSubPath("inspections/StringIsEmpty") internal fun assertThat_with_isEqualTo_emptyString_can_use_isEmpty(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(AssertThatStringIsEmptyInspection::class.java) - myFixture.configureByFile("StringIsEmptyBefore.java") - val highlights = myFixture.doHighlighting() - .asSequence() - .filter { it.description?.contains(" can be simplified to") ?: false } - .toList() - assertThat(highlights).hasSize(6).extrakting { it.text }.doesNotContain("assertThat") - executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isEmpty()"), 3) - executeQuickFixes(myFixture, Regex.fromLiteral("Replace hasSize() with isEmpty()"), 3) - myFixture.checkResultByFile("StringIsEmptyAfter.java") - } + myFixture.enableInspections(AssertThatStringIsEmptyInspection::class.java) + myFixture.configureByFile("StringIsEmptyBefore.java") + val highlights = myFixture.doHighlighting() + .asSequence() + .filter { it.description?.contains(" can be simplified to") ?: false } + .toList() + assertThat(highlights).hasSize(6).extrakting { it.text }.doesNotContain("assertThat") + executeQuickFixes(myFixture, Regex.fromLiteral("Replace isEqualTo() with isEmpty()"), 3) + executeQuickFixes(myFixture, Regex.fromLiteral("Replace hasSize() with isEmpty()"), 3) + myFixture.checkResultByFile("StringIsEmptyAfter.java") } } \ No newline at end of file diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssumeThatInsteadOfReturnInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssumeThatInsteadOfReturnInspectionTest.kt index 5d48454..85ea523 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssumeThatInsteadOfReturnInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/AssumeThatInsteadOfReturnInspectionTest.kt @@ -14,11 +14,9 @@ internal class AssumeThatInsteadOfReturnInspectionTest : AbstractCajonTest() { @Test @TestDataSubPath("inspections/AssumeThat") internal fun conditional_returns_can_be_replaced_by_assumeThat(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(AssumeThatInsteadOfReturnInspection::class.java) - myFixture.configureByFile("AssumeThatBefore.java") - executeQuickFixes(myFixture, Regex.fromLiteral("Replace if statement by assumeTrue()"), 5) - myFixture.checkResultByFile("AssumeThatAfter.java") - } + myFixture.enableInspections(AssumeThatInsteadOfReturnInspection::class.java) + myFixture.configureByFile("AssumeThatBefore.java") + executeQuickFixes(myFixture, Regex.fromLiteral("Replace if statement by assumeTrue()"), 5) + myFixture.checkResultByFile("AssumeThatAfter.java") } } \ No newline at end of file diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/ImplicitAssertionInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/ImplicitAssertionInspectionTest.kt index 22a39dd..d94da65 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/ImplicitAssertionInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/ImplicitAssertionInspectionTest.kt @@ -14,13 +14,11 @@ internal class ImplicitAssertionInspectionTest : AbstractCajonTest() { @Test @TestDataSubPath("inspections/ImplicitAssertion") internal fun implicit_assertions_can_be_removed(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(ImplicitAssertionInspection::class.java) - myFixture.configureByFile("ImplicitAssertionBefore.java") - executeQuickFixes(myFixture, Regex("Delete implicit isNotNull\\(\\) covered by .*"), 101) - executeQuickFixes(myFixture, Regex("Delete implicit isNotEmpty\\(\\) covered by .*"), 17) - executeQuickFixes(myFixture, Regex("Delete implicit isPresent\\(\\) covered by .*"), 8) - myFixture.checkResultByFile("ImplicitAssertionAfter.java") - } + myFixture.enableInspections(ImplicitAssertionInspection::class.java) + myFixture.configureByFile("ImplicitAssertionBefore.java") + executeQuickFixes(myFixture, Regex("Delete implicit isNotNull\\(\\) covered by .*"), 101) + executeQuickFixes(myFixture, Regex("Delete implicit isNotEmpty\\(\\) covered by .*"), 17) + executeQuickFixes(myFixture, Regex("Delete implicit isPresent\\(\\) covered by .*"), 8) + myFixture.checkResultByFile("ImplicitAssertionAfter.java") } } \ No newline at end of file diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/JUnitAssertToAssertJInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/JUnitAssertToAssertJInspectionTest.kt index e96ed6e..f2924f9 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/JUnitAssertToAssertJInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/JUnitAssertToAssertJInspectionTest.kt @@ -15,12 +15,10 @@ internal class JUnitAssertToAssertJInspectionTest : AbstractCajonTest() { @Test @TestDataSubPath("inspections/JUnitAssertToAssertJ") internal fun junit_Assertions_can_be_converted_into_AssertJ(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(JUnitAssertToAssertJInspection::class.java) - myFixture.configureByFile("JUnitAssertToAssertJInspectionBefore.java") - executeQuickFixes(myFixture, Regex("Convert assert.*\\(\\) to assertThat\\(\\).*"), 48) - executeQuickFixes(myFixture, Regex("Convert assume.*\\(\\) to assumeThat\\(\\).*"), 7) - myFixture.checkResultByFile("JUnitAssertToAssertJInspectionAfter.java") - } + myFixture.enableInspections(JUnitAssertToAssertJInspection::class.java) + myFixture.configureByFile("JUnitAssertToAssertJInspectionBefore.java") + executeQuickFixes(myFixture, Regex("Convert assert.*\\(\\) to assertThat\\(\\).*"), 48) + executeQuickFixes(myFixture, Regex("Convert assume.*\\(\\) to assumeThat\\(\\).*"), 7) + myFixture.checkResultByFile("JUnitAssertToAssertJInspectionAfter.java") } } \ No newline at end of file diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/JoinAssertThatStatementsInspectionTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/JoinAssertThatStatementsInspectionTest.kt index fd25551..b573762 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/inspections/JoinAssertThatStatementsInspectionTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/inspections/JoinAssertThatStatementsInspectionTest.kt @@ -11,11 +11,9 @@ internal class JoinAssertThatStatementsInspectionTest : AbstractCajonTest() { @Test @TestDataSubPath("inspections/JoinStatements") internal fun assertThat_statements_can_be_joined_together(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.enableInspections(JoinAssertThatStatementsInspection::class.java) - myFixture.configureByFile("JoinStatementsBefore.java") - executeQuickFixes(myFixture, Regex.fromLiteral("Join assertThat() statements"), 5) - myFixture.checkResultByFile("JoinStatementsAfter.java") - } + myFixture.enableInspections(JoinAssertThatStatementsInspection::class.java) + myFixture.configureByFile("JoinStatementsBefore.java") + executeQuickFixes(myFixture, Regex.fromLiteral("Join assertThat() statements"), 5) + myFixture.checkResultByFile("JoinStatementsAfter.java") } } \ No newline at end of file diff --git a/src/test/java/de/platon42/intellij/plugins/cajon/references/ExtractorReferenceContributorTest.kt b/src/test/java/de/platon42/intellij/plugins/cajon/references/ExtractorReferenceContributorTest.kt index 55f8a9b..e567ef6 100644 --- a/src/test/java/de/platon42/intellij/plugins/cajon/references/ExtractorReferenceContributorTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/cajon/references/ExtractorReferenceContributorTest.kt @@ -13,81 +13,61 @@ internal class ExtractorReferenceContributorTest : AbstractCajonTest() { @Test internal fun extractor_is_able_to_find_reference_for_field_extracting(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.configureByFiles("FindReference1.java", "Address.java", "Contact.java") - assertThat(myFixture.elementAtCaret.text).isEqualTo("private String name;") - } + myFixture.configureByFiles("FindReference1.java", "Address.java", "Contact.java") + assertThat(myFixture.elementAtCaret.text).isEqualTo("private String name;") } @Test internal fun extractor_is_able_to_find_reference_for_first_part_of_a_path(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.configureByFiles("FindReference2.java", "Address.java", "Contact.java") - assertThat(myFixture.elementAtCaret.text).isEqualTo("protected Address address;") - } + myFixture.configureByFiles("FindReference2.java", "Address.java", "Contact.java") + assertThat(myFixture.elementAtCaret.text).isEqualTo("protected Address address;") } @Test internal fun extractor_is_able_to_find_reference_for_second_part_of_a_path_and_both_getter_and_field(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.configureByFiles("FindReference3.java", "Address.java", "Contact.java") - assertThat(myFixture.elementAtCaret.text).startsWith("private String street;") - } + myFixture.configureByFiles("FindReference3.java", "Address.java", "Contact.java") + assertThat(myFixture.elementAtCaret.text).startsWith("private String street;") } @Test internal fun extractor_is_able_to_find_reference_on_a_bare_method_call(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.configureByFiles("FindReference4.java", "Address.java", "Contact.java") - assertThat(myFixture.elementAtCaret.text).startsWith("public Boolean getREALLYnoMAILINGS()") - } + myFixture.configureByFiles("FindReference4.java", "Address.java", "Contact.java") + assertThat(myFixture.elementAtCaret.text).startsWith("public Boolean getREALLYnoMAILINGS()") } @Test internal fun extractor_is_able_to_find_reference_with_only_Getter_on_second_part(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.configureByFiles("FindReference5.java", "Address.java", "Contact.java") - assertThat(myFixture.elementAtCaret.text).startsWith("public boolean isNoMailings()") - } + myFixture.configureByFiles("FindReference5.java", "Address.java", "Contact.java") + assertThat(myFixture.elementAtCaret.text).startsWith("public boolean isNoMailings()") } @Test internal fun extractor_is_able_to_find_reference_using_byName_extractor(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.configureByFiles("FindReference6.java", "Address.java", "Contact.java") - assertThat(myFixture.elementAtCaret.text).isEqualTo("private String name;") - } + myFixture.configureByFiles("FindReference6.java", "Address.java", "Contact.java") + assertThat(myFixture.elementAtCaret.text).isEqualTo("private String name;") } @Test internal fun extractor_is_able_to_find_reference_using_resultOf_extractor(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.configureByFiles("FindReference7.java", "Address.java", "Contact.java") - assertThat(myFixture.elementAtCaret.text).startsWith("public String getStreetName()") - } + myFixture.configureByFiles("FindReference7.java", "Address.java", "Contact.java") + assertThat(myFixture.elementAtCaret.text).startsWith("public String getStreetName()") } @Test internal fun extractor_is_able_to_find_reference_for_field_extraction_on_list(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.configureByFiles("FindReference8.java", "Address.java", "Contact.java") - assertThat(myFixture.elementAtCaret.text).isEqualTo("private String name;") - } + myFixture.configureByFiles("FindReference8.java", "Address.java", "Contact.java") + assertThat(myFixture.elementAtCaret.text).isEqualTo("private String name;") } @Test internal fun extractor_is_able_to_find_reference_for_field_flat_extraction_of_path_on_list(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.configureByFiles("FindReference9.java", "Address.java", "Contact.java") - assertThat(myFixture.elementAtCaret.text).startsWith("private String street;") - } + myFixture.configureByFiles("FindReference9.java", "Address.java", "Contact.java") + assertThat(myFixture.elementAtCaret.text).startsWith("private String street;") } @Test internal fun extractor_is_able_to_find_reference_for_extraction_on_result_of_method(@MyFixture myFixture: JavaCodeInsightTestFixture) { - runTest { - myFixture.configureByFiles("FindReference10.java", "Address.java", "Contact.java") - assertThat(myFixture.elementAtCaret.text).startsWith("public String getStreetName()") - } + myFixture.configureByFiles("FindReference10.java", "Address.java", "Contact.java") + assertThat(myFixture.elementAtCaret.text).startsWith("public String getStreetName()") } } \ No newline at end of file