diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 9ecc838..b39d2d2 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -120,12 +120,16 @@ jobs:
gradle-home-cache-cleanup: true
# Run tests
- - name: Run Tests
- run: ./gradlew check
+ - name: Run JUnit 5 Tests
+ run: ./gradlew runTestsInIJCommunity
+
+ # Run tests
+ - name: Run JUnit 5 Tests with K2
+ run: ./gradlew runTestsWithK2InIJCommunity
# Run tests
- name: Run JUnit 3 Tests
- run: ./gradlew testWithJunit3 -Pidea.home.path=./intellij-community
+ run: ./gradlew runJUnit3TestsInIJCommunity -Pidea.home.path=./intellij-community
# Collect Tests Result of failed tests
- name: Collect Tests Result
@@ -135,12 +139,6 @@ jobs:
name: tests-result
path: ${{ github.workspace }}/build/reports/tests
- # Upload the Kover report to CodeCov
- - name: Upload Code Coverage Report
- uses: codecov/codecov-action@v4
- with:
- files: ${{ github.workspace }}/build/reports/kover/report.xml
-
# Run plugin structure verification along with IntelliJ Plugin Verifier
verify:
name: Verify plugin
diff --git a/.gitignore b/.gitignore
index a2bb2d7..d54b9c7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -43,6 +43,7 @@ IntelliJBehave.zip
*.ipr
*.iws
.idea
+.intellijPlatform
# Atlassian Plugin Configuration
atlassian-ide-plugin.xml
diff --git a/.run/Run Tests - JUnit3.run.xml b/.run/Run Tests - JUnit3.run.xml
new file mode 100644
index 0000000..eed44f1
--- /dev/null
+++ b/.run/Run Tests - JUnit3.run.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ true
+ false
+ false
+
+
+
\ No newline at end of file
diff --git a/.run/Run Tests - JUnit5 - K2.run.xml b/.run/Run Tests - JUnit5 - K2.run.xml
new file mode 100644
index 0000000..8101c89
--- /dev/null
+++ b/.run/Run Tests - JUnit5 - K2.run.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ true
+ false
+ false
+
+
+
\ No newline at end of file
diff --git a/.run/Run Plugin Tests.run.xml b/.run/Run Tests - JUnit5.run.xml
similarity index 80%
rename from .run/Run Plugin Tests.run.xml
rename to .run/Run Tests - JUnit5.run.xml
index ae9ae13..c1bfca7 100644
--- a/.run/Run Plugin Tests.run.xml
+++ b/.run/Run Tests - JUnit5.run.xml
@@ -1,5 +1,5 @@
-
+
@@ -11,7 +11,7 @@
-
+
@@ -19,6 +19,7 @@
true
true
false
+ false
-
+
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 57e75e9..28bb3c4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,19 @@
## [Unreleased]
+## [1.67.0]
+### Changed
+- New supported IDE version range: 2024.2.1 - 2024.3.*.
+The previous version, 1.66.0 (and bugfixes of it) of JBehave Support will remain to support IDEs up to version 2024.2.0.2.
+- Updated the project to use the IntelliJ Platform Gradle Plugin 2.0.
+- Updated the project to use JDK 21.
+- Updated project configuration to make sure the plugin works when the K2 Kotlin compiler is enabled.
+- Removed a couple of deprecated API usage.
+
+### Fixed
+- Fixed the listener that tracks modifications of JBehave step def classes. It no longer fails when it encounters invalid files.
+- Fixed a potential exception during highlighting undefined steps.
+
## [1.66.0]
### Changed
- New supported IDE version range: 2023.2.8 - 2024.2.0.2
diff --git a/build.gradle.kts b/build.gradle.kts
index 29c6b6b..f6efc2d 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,72 +1,83 @@
import org.jetbrains.changelog.Changelog
import org.jetbrains.changelog.markdownToHTML
-
-fun properties(key: String) = providers.gradleProperty(key)
-fun environment(key: String) = providers.environmentVariable(key)
+import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
+import org.jetbrains.intellij.platform.gradle.TestFrameworkType
plugins {
id("java") // Java support
alias(libs.plugins.kotlin) // Kotlin support
- alias(libs.plugins.gradleIntelliJPlugin) // Gradle IntelliJ Plugin
+ alias(libs.plugins.intelliJPlatform) // IntelliJ Platform Gradle Plugin
alias(libs.plugins.changelog) // Gradle Changelog Plugin
}
-group = properties("pluginGroup").get()
-version = properties("pluginVersion").get()
+group = providers.gradleProperty("pluginGroup").get()
+version = providers.gradleProperty("pluginVersion").get()
+
+// Set the JVM language level used to build the project. Use Java 11 for 2020.3+, and Java 17 for 2022.2+.
+kotlin {
+ jvmToolchain(21)
+}
// Configure project's dependencies
repositories {
mavenCentral()
-}
-
-// Set the JVM language level used to build the project. Use Java 11 for 2020.3+, and Java 17 for 2022.2+.
-kotlin {
- jvmToolchain(17)
+ // IntelliJ Platform Gradle Plugin Repositories Extension - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-repositories-extension.html
+ intellijPlatform {
+ defaultRepositories()
+ }
}
dependencies {
- //https://kotlinlang.org/docs/reflection.html#jvm-dependency
- implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.25")
+ //JBehave
+
implementation("org.jbehave:jbehave-core:5.2.0")
- testImplementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.25")
- testImplementation("org.assertj:assertj-core:3.25.3")
+
+ //Testing
+
+ //Required for 'junit.framework.TestCase' referenced in 'com.intellij.testFramework.UsefulTestCase'
+ testImplementation(libs.junit)
+ testImplementation("org.assertj:assertj-core:3.26.3")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.11.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.11.0")
-}
-// Configure Gradle IntelliJ Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
-intellij {
- pluginName = properties("pluginName")
- version = properties("platformVersion")
- type = properties("platformType")
+ //Others
- // Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file.
- plugins = properties("platformPlugins").map { it.split(',').map(String::trim).filter(String::isNotEmpty) }
-}
+ implementation("org.apache.commons:commons-text:1.12.0")
-// Configure Gradle Changelog Plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
-changelog {
- groups.empty()
- repositoryUrl = properties("pluginRepositoryUrl")
-}
+ // IntelliJ Platform Gradle Plugin Dependencies Extension - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-dependencies-extension.html
-tasks {
- wrapper {
- gradleVersion = properties("gradleVersion").get()
+ intellijPlatform {
+ create(providers.gradleProperty("platformType"), providers.gradleProperty("platformVersion"))
+
+ // Plugin Dependencies. Uses `platformBundledPlugins` property from the gradle.properties file for bundled IntelliJ Platform plugins.
+ bundledPlugins(providers.gradleProperty("platformBundledPlugins").map { it.split(',') })
+
+ // Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file for plugin from JetBrains Marketplace.
+ plugins(providers.gradleProperty("platformPlugins").map { it.split(',') })
+
+ instrumentationTools()
+ pluginVerifier()
+ zipSigner()
+ testFramework(TestFrameworkType.Platform)
+ //Required for 'LightJavaCodeInsightFixtureTestCase5'
+ testFramework(TestFrameworkType.Plugin.Java)
+ //Required for the 'com.intellij.testFramework.junit5' package
+ testFramework(TestFrameworkType.JUnit5)
}
+}
- patchPluginXml {
- version = properties("pluginVersion")
- sinceBuild = properties("pluginSinceBuild")
- untilBuild = properties("pluginUntilBuild")
+// Configure IntelliJ Platform Gradle Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-extension.html
+intellijPlatform {
+ pluginConfiguration {
+ version = providers.gradleProperty("pluginVersion")
// Extract the section from README.md and provide for the plugin's manifest
- pluginDescription = providers.fileContents(layout.projectDirectory.file("README.md")).asText.map {
+ description = providers.fileContents(layout.projectDirectory.file("README.md")).asText.map {
val start = ""
val end = ""
- with (it.lines()) {
+ with(it.lines()) {
if (!containsAll(listOf(start, end))) {
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
}
@@ -76,7 +87,7 @@ tasks {
val changelog = project.changelog // local variable for configuration cache compatibility
// Get the latest available change notes from the changelog file
- changeNotes = properties("pluginVersion").map { pluginVersion ->
+ changeNotes = providers.gradleProperty("pluginVersion").map { pluginVersion ->
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
@@ -86,19 +97,76 @@ tasks {
)
}
}
+
+ ideaVersion {
+ sinceBuild = providers.gradleProperty("pluginSinceBuild")
+ untilBuild = providers.gradleProperty("pluginUntilBuild")
+ }
}
- test {
- useJUnitPlatform()
- //Required for running tests in 2021.3 due to it not finding test classes properly.
- //See https://app.slack.com/client/T5P9YATH9/C5U8BM1MK/thread/C5U8BM1MK-1639934273.054400
- isScanForTestClasses = false
- include("**/codeInspector/*Test.class", "**/resolver/*Test.class", "**/utility/*Test.class", "**/service/*Test.class", "**/jbehave/core/steps/*Test.class")
- exclude("**/highlighter/*Test.class", "**/parser/*Test.class", "**/spellchecker/*Test.class", "**/structure/*Test.class")
+ pluginVerification {
+ ides {
+ recommended()
+ }
}
}
-tasks.register("testWithJunit3") {
- include("**/highlighter/*Test.class", "**/parser/*Test.class", "**/spellchecker/*Test.class", "**/structure/*Test.class")
- exclude("**/highlighter/StoryLocalizedLexer_FrenchTest.class")
+intellijPlatformTesting {
+ val runTestsInIJCommunity by intellijPlatformTesting.testIde.registering {
+ type = IntelliJPlatformType.IntellijIdeaCommunity
+ version = "2024.2.1"
+ task {
+ useJUnitPlatform {
+ isScanForTestClasses = false
+ include("**/codeInspector/*Test.class", "**/resolver/*Test.class", "**/utility/*Test.class", "**/service/*Test.class", "**/jbehave/core/steps/*Test.class")
+ exclude("**/highlighter/*Test.class", "**/parser/*Test.class", "**/spellchecker/*Test.class", "**/structure/*Test.class")
+ }
+ }
+ }
+
+ val runTestsWithK2InIJCommunity by intellijPlatformTesting.testIde.registering {
+ type = IntelliJPlatformType.IntellijIdeaCommunity
+ version = "2024.2.1"
+ task {
+ //See https://kotlin.github.io/analysis-api/testing-in-k2-locally.html
+ jvmArgumentProviders += CommandLineArgumentProvider {
+ listOf("-Didea.kotlin.plugin.use.k2=true")
+ }
+ useJUnitPlatform {
+ isScanForTestClasses = false
+ include("**/codeInspector/*Test.class", "**/resolver/*Test.class", "**/utility/*Test.class", "**/service/*Test.class", "**/jbehave/core/steps/*Test.class")
+ exclude("**/highlighter/*Test.class", "**/parser/*Test.class", "**/spellchecker/*Test.class", "**/structure/*Test.class")
+ }
+ }
+ }
+
+ val runJUnit3TestsInIJCommunity by intellijPlatformTesting.testIde.registering {
+ type = IntelliJPlatformType.IntellijIdeaCommunity
+ version = "2024.2.1"
+ task {
+ useJUnit {
+ include("**/highlighter/*Test.class", "**/parser/*Test.class", "**/spellchecker/*Test.class", "**/structure/*Test.class")
+ exclude("**/highlighter/StoryLocalizedLexer_FrenchTest.class")
+ }
+ }
+ }
+}
+
+//Uncomment this to start the IDE with the K2 Kotlin compiler enabled
+//tasks.named("runIde") {
+// jvmArgumentProviders += CommandLineArgumentProvider {
+// listOf("-Didea.kotlin.plugin.use.k2=true")
+// }
+//}
+
+// Configure Gradle Changelog Plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
+changelog {
+ groups.empty()
+ repositoryUrl = providers.gradleProperty("pluginRepositoryUrl")
+}
+
+tasks {
+ wrapper {
+ gradleVersion = providers.gradleProperty("gradleVersion").get()
+ }
}
diff --git a/gradle.properties b/gradle.properties
index e1d83e0..548beaa 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -4,20 +4,22 @@ pluginGroup = com.github.kumaraman21.intellijbehave
pluginName = JBehave Support
pluginRepositoryUrl = https://github.com/witspirit/IntelliJBehave
# SemVer format -> https://semver.org
-pluginVersion = 1.66.0
+pluginVersion = 1.67.0
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
-pluginSinceBuild = 232.10335.12
-# 2024.2.0.2
-pluginUntilBuild = 242.20224.419
+pluginSinceBuild = 242.21829.142
+pluginUntilBuild = 243.*
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType = IC
-platformVersion = 2023.2.8
+platformVersion = 2024.2.1
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
-platformPlugins = java,Kotlin
+platformPlugins =
+
+# Example: platformBundledPlugins = com.intellij.java
+platformBundledPlugins = com.intellij.java,org.jetbrains.kotlin
# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion = 8.9
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index de27609..46a4d89 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -1,16 +1,16 @@
[versions]
# libraries
-annotations = "24.1.0"
+junit = "4.13.2"
# plugins
-kotlin = "1.9.23"
-changelog = "2.2.0"
-gradleIntelliJPlugin = "1.17.2"
+kotlin = "1.9.25"
+changelog = "2.2.1"
+intelliJPlatform = "2.0.1"
[libraries]
-annotations = { group = "org.jetbrains", name = "annotations", version.ref = "annotations" }
+junit = { group = "junit", name = "junit", version.ref = "junit" }
[plugins]
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }
-gradleIntelliJPlugin = { id = "org.jetbrains.intellij", version.ref = "gradleIntelliJPlugin" }
+intelliJPlatform = { id = "org.jetbrains.intellij.platform", version.ref = "intelliJPlatform" }
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
diff --git a/lib/jbehave-core-5.1.1.jar b/lib/jbehave-core-5.1.1.jar
deleted file mode 100644
index 2cc3705..0000000
Binary files a/lib/jbehave-core-5.1.1.jar and /dev/null differ
diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/codeInspector/UndefinedStepInspection.java b/src/main/java/com/github/kumaraman21/intellijbehave/codeInspector/UndefinedStepInspection.java
index 886c34c..afcc92a 100644
--- a/src/main/java/com/github/kumaraman21/intellijbehave/codeInspector/UndefinedStepInspection.java
+++ b/src/main/java/com/github/kumaraman21/intellijbehave/codeInspector/UndefinedStepInspection.java
@@ -73,6 +73,8 @@ public void visitElement(@NotNull PsiElement psiElement) {
private void highlightParameters(JBehaveStep step, JavaStepDefinition javaStepDefinition, ProblemsHolder holder) {
String stepText = step.getStepText();
String annotationText = javaStepDefinition.getAnnotationTextFor(stepText);
+ //ParametrizedString cannot be created with null content
+ if (annotationText == null) return;
int offset = step.getStepTextOffset();
for (StringToken token : new ParametrizedString(annotationText).tokenize(stepText)) {
diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/support/services/KotlinAnnotationsLoader.kt b/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/support/services/KotlinAnnotationsLoader.kt
index b5c8a31..66d40a5 100644
--- a/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/support/services/KotlinAnnotationsLoader.kt
+++ b/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/support/services/KotlinAnnotationsLoader.kt
@@ -28,7 +28,7 @@ class KotlinAnnotationsLoader private constructor() {
fun getAnnotations(qualifiedName: QualifiedName, project: Project, scope: GlobalSearchScope): Collection {
val name = qualifiedName.lastComponent
return if (name != null) {
- KotlinAnnotationsIndex.get(name, project, scope)
+ KotlinAnnotationsIndex[name, project, scope]
.asSequence()
.map { ktAnnotation ->
val function = ktAnnotation.parent?.parent as? KtFunction
diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/language/StoryLanguage.java b/src/main/java/com/github/kumaraman21/intellijbehave/language/StoryLanguage.java
index a578db7..4ce6989 100644
--- a/src/main/java/com/github/kumaraman21/intellijbehave/language/StoryLanguage.java
+++ b/src/main/java/com/github/kumaraman21/intellijbehave/language/StoryLanguage.java
@@ -27,7 +27,7 @@ public class StoryLanguage extends CompositeLanguage {
private StoryLanguage() {
super("Story", "text/story");
- SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(this, new SingleLazyInstanceSyntaxHighlighterFactory() {
+ SyntaxHighlighterFactory.getLanguageFactory().addExplicitExtension(this, new SingleLazyInstanceSyntaxHighlighterFactory() {
@NotNull
protected SyntaxHighlighter createHighlighter() {
return new StorySyntaxHighlighter();
diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/parser/JBehaveStep.java b/src/main/java/com/github/kumaraman21/intellijbehave/parser/JBehaveStep.java
index 11aa0f4..bd554b7 100644
--- a/src/main/java/com/github/kumaraman21/intellijbehave/parser/JBehaveStep.java
+++ b/src/main/java/com/github/kumaraman21/intellijbehave/parser/JBehaveStep.java
@@ -18,13 +18,14 @@
import com.github.kumaraman21.intellijbehave.highlighter.StoryTokenType;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;
+import com.intellij.openapi.application.ReadAction;
import com.intellij.psi.PsiReference;
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
import org.jbehave.core.steps.StepType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import static org.apache.commons.lang.StringUtils.trim;
+import static org.apache.commons.lang3.StringUtils.trim;
public class JBehaveStep extends ASTWrapperPsiElement {
private StepType stepType;
@@ -37,7 +38,7 @@ public JBehaveStep(@NotNull ASTNode node, StepType stepType) {
@Override
@NotNull
public PsiReference[] getReferences() {
- return ReferenceProvidersRegistry.getReferencesFromProviders(this);
+ return ReadAction.compute(() -> ReferenceProvidersRegistry.getReferencesFromProviders(this));
}
public StepType getStepType() {
diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/parser/StoryParser.java b/src/main/java/com/github/kumaraman21/intellijbehave/parser/StoryParser.java
index 0b2837f..4fb7e17 100644
--- a/src/main/java/com/github/kumaraman21/intellijbehave/parser/StoryParser.java
+++ b/src/main/java/com/github/kumaraman21/intellijbehave/parser/StoryParser.java
@@ -21,7 +21,7 @@
import com.intellij.lang.PsiParser;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
public class StoryParser implements PsiParser {
diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/resolver/StepDefinitionAnnotationConverter.java b/src/main/java/com/github/kumaraman21/intellijbehave/resolver/StepDefinitionAnnotationConverter.java
index 2ad75d3..b344496 100644
--- a/src/main/java/com/github/kumaraman21/intellijbehave/resolver/StepDefinitionAnnotationConverter.java
+++ b/src/main/java/com/github/kumaraman21/intellijbehave/resolver/StepDefinitionAnnotationConverter.java
@@ -15,8 +15,18 @@
*/
package com.github.kumaraman21.intellijbehave.resolver;
+import static com.github.kumaraman21.intellijbehave.utility.StepTypeMappings.ANNOTATION_TO_STEP_TYPE_MAPPING;
+import static com.intellij.openapi.application.ReadAction.compute;
+import static org.apache.commons.lang3.StringUtils.remove;
+import static org.apache.commons.lang3.StringUtils.removeEnd;
+import static org.apache.commons.lang3.StringUtils.removeStart;
+
import com.github.kumaraman21.intellijbehave.jbehave.core.steps.PatternVariantBuilder;
-import com.intellij.psi.*;
+import com.intellij.psi.PsiAnnotation;
+import com.intellij.psi.PsiAnnotationMemberValue;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiLiteral;
+import com.intellij.psi.PsiNameValuePair;
import org.jbehave.core.annotations.Alias;
import org.jbehave.core.annotations.Aliases;
import org.jbehave.core.steps.StepType;
@@ -26,9 +36,6 @@
import java.util.Set;
import java.util.stream.Collectors;
-import static com.github.kumaraman21.intellijbehave.utility.StepTypeMappings.ANNOTATION_TO_STEP_TYPE_MAPPING;
-import static org.apache.commons.lang.StringUtils.*;
-
public final class StepDefinitionAnnotationConverter {
public static Set convertFrom(PsiAnnotation[] annotations) {
@@ -37,28 +44,28 @@ public static Set convertFrom(PsiAnnotation[] annotati
StepType stepType = null;
for (PsiAnnotation annotation : annotations) {
- String annotationQualifiedName = annotation.getQualifiedName();
+ String annotationQualifiedName = compute(annotation::getQualifiedName);
// Given, When, Then
- final PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
+ final PsiNameValuePair[] attributes = compute(() -> annotation.getParameterList().getAttributes());
// When there are no attributes for the annotation, we got nothing to do here
if (attributes.length > 0) {
if (ANNOTATION_TO_STEP_TYPE_MAPPING.containsKey(annotationQualifiedName)) {
stepType = ANNOTATION_TO_STEP_TYPE_MAPPING.get(annotationQualifiedName);
- String annotationText = getTextFromValue(attributes[0].getValue());
+ String annotationText = getTextFromValue(compute(() -> attributes[0].getValue()));
if (res == null) {
res = new HashSet<>();
}
res.addAll(getPatternVariants(stepType, annotationText, annotation));
} else if (annotationQualifiedName != null) {
if (annotationQualifiedName.equals(Alias.class.getName())) {
- String annotationText = getTextFromValue(attributes[0].getValue());
+ String annotationText = getTextFromValue(compute(() -> attributes[0].getValue()));
if (res == null) {
res = new HashSet<>();
}
res.addAll(getPatternVariants(stepType, annotationText, annotation));
} else if (annotationQualifiedName.equals(Aliases.class.getName())) {
- PsiAnnotationMemberValue attributeValue = attributes[0].getValue();
+ PsiAnnotationMemberValue attributeValue = compute(() -> attributes[0].getValue());
if (attributeValue != null) {
PsiElement[] values = attributeValue.getChildren();
for (PsiElement value : values) {
@@ -80,13 +87,13 @@ public static Set convertFrom(PsiAnnotation[] annotati
private static Set getPatternVariants(final StepType stepType, String annotationText, final PsiAnnotation annotation) {
return new PatternVariantBuilder(annotationText)
- .allVariants()
- .stream()
- .map(variant -> new StepDefinitionAnnotation(stepType, variant, annotation))
- .collect(Collectors.toSet());
+ .allVariants()
+ .stream()
+ .map(variant -> new StepDefinitionAnnotation(stepType, variant, annotation))
+ .collect(Collectors.toSet());
}
private static String getTextFromValue(PsiElement value) {
- return remove(removeStart(removeEnd(value.getText(), "\""), "\""), "\\");
+ return remove(removeStart(removeEnd(compute(value::getText), "\""), "\""), "\\");
}
}
diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/resolver/StepDefinitionIterator.java b/src/main/java/com/github/kumaraman21/intellijbehave/resolver/StepDefinitionIterator.java
index 8ec8fda..fdb1672 100644
--- a/src/main/java/com/github/kumaraman21/intellijbehave/resolver/StepDefinitionIterator.java
+++ b/src/main/java/com/github/kumaraman21/intellijbehave/resolver/StepDefinitionIterator.java
@@ -15,6 +15,8 @@
*/
package com.github.kumaraman21.intellijbehave.resolver;
+import static com.intellij.openapi.application.ReadAction.compute;
+
import com.github.kumaraman21.intellijbehave.kotlin.KotlinConfigKt;
import com.github.kumaraman21.intellijbehave.kotlin.support.services.KotlinPsiClassesHandler;
import com.intellij.openapi.project.Project;
@@ -50,12 +52,12 @@ public StepType getStepType() {
@Override
public boolean processFile(@NotNull VirtualFile virtualFile) {
- PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
+ PsiFile psiFile = compute(() -> PsiManager.getInstance(project).findFile(virtualFile));
if (psiFile instanceof PsiClassOwner psiClassOwner) {
for (PsiClass psiClass : getPsiClasses(psiFile, psiClassOwner)) {
- for (PsiMethod method : psiClass.getMethods()) {
- PsiAnnotation[] annotations = method.getModifierList().getApplicableAnnotations();
+ for (PsiMethod method : compute(psiClass::getMethods)) {
+ PsiAnnotation[] annotations = compute(() -> method.getModifierList().getApplicableAnnotations());
for (StepDefinitionAnnotation stepDefinitionAnnotation : StepDefinitionAnnotationConverter.convertFrom(annotations)) {
if ((stepType == null || Objects.equals(stepType, stepDefinitionAnnotation.stepType()))
@@ -80,10 +82,10 @@ public boolean processFile(@NotNull VirtualFile virtualFile) {
private static PsiClass[] getPsiClasses(PsiFile psiFile, PsiClassOwner psiClassOwner) {
PsiClass[] psiClasses = null;
if (KotlinConfigKt.getPluginIsEnabled()) {
- psiClasses = KotlinPsiClassesHandler.getPsiClasses(psiFile);
+ psiClasses = compute(() -> KotlinPsiClassesHandler.getPsiClasses(psiFile));
}
- return psiClasses != null ? psiClasses : psiClassOwner.getClasses();
+ return psiClasses != null ? psiClasses : compute(psiClassOwner::getClasses);
}
public abstract boolean processStepDefinition(StepDefinitionAnnotation stepDefinitionAnnotation);
diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/resolver/StepPsiReference.java b/src/main/java/com/github/kumaraman21/intellijbehave/resolver/StepPsiReference.java
index 3409e41..82f90c5 100644
--- a/src/main/java/com/github/kumaraman21/intellijbehave/resolver/StepPsiReference.java
+++ b/src/main/java/com/github/kumaraman21/intellijbehave/resolver/StepPsiReference.java
@@ -15,6 +15,8 @@
*/
package com.github.kumaraman21.intellijbehave.resolver;
+import static com.intellij.openapi.application.ReadAction.compute;
+
import com.github.kumaraman21.intellijbehave.parser.JBehaveStep;
import com.github.kumaraman21.intellijbehave.service.JBehaveStepsIndex;
import com.github.kumaraman21.intellijbehave.service.JavaStepDefinition;
@@ -96,7 +98,7 @@ public boolean isReferenceTo(@NotNull PsiElement element) {
for (var resolvedJavaStepDefinition : resolveToDefinitions()) {
final PsiMethod method = resolvedJavaStepDefinition.getAnnotatedMethod();
if (method != null && !resolvedElements.contains(method)) {
- if (manager == null) manager = getElement().getManager();
+ if (manager == null) manager = compute(() -> getElement().getManager());
if (manager.areElementsEquivalent(method, element)) {
return true;
}
@@ -118,7 +120,7 @@ public JavaStepDefinition resolveToDefinition() {
@NotNull
private Collection resolveToDefinitions() {
- return JBehaveStepsIndex.getInstance(myStep.getProject()).findStepDefinitions(myStep);
+ return JBehaveStepsIndex.getInstance(compute(() -> myStep.getProject())).findStepDefinitions(myStep);
}
@Override
diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/runner/RunStoryAction.java b/src/main/java/com/github/kumaraman21/intellijbehave/runner/RunStoryAction.java
index d886d42..5b8b6a9 100644
--- a/src/main/java/com/github/kumaraman21/intellijbehave/runner/RunStoryAction.java
+++ b/src/main/java/com/github/kumaraman21/intellijbehave/runner/RunStoryAction.java
@@ -41,7 +41,7 @@
import static com.github.kumaraman21.intellijbehave.runner.StoryRunnerConfigurationType.JBEHAVE_STORY_RUNNER;
import static com.intellij.openapi.ui.Messages.getErrorIcon;
import static com.intellij.openapi.ui.Messages.showMessageDialog;
-import static org.apache.commons.lang.StringUtils.isBlank;
+import static org.apache.commons.lang3.StringUtils.isBlank;
public class RunStoryAction extends AnAction {
diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndex.java b/src/main/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndex.java
index f8968f1..e81c40c 100644
--- a/src/main/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndex.java
+++ b/src/main/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndex.java
@@ -46,7 +46,7 @@ public static JBehaveStepsIndex getInstance(Project project) {
@NotNull
public Collection findStepDefinitions(@NotNull JBehaveStep step) {
- return CachedValuesManager.getCachedValue(step, (CachedValueProvider extends Collection>) () -> {
+ return ReadAction.compute(() -> CachedValuesManager.getCachedValue(step, (CachedValueProvider extends Collection>) () -> {
Module module = ModuleUtilCore.findModuleForPsiElement(step);
if (module == null) {
@@ -73,7 +73,7 @@ public Collection findStepDefinitions(@NotNull JBehaveStep s
return new CachedValueProvider.Result<>(definitionsByClass.values(),
JBehaveStepDefClassesModificationTracker.getInstance(step.getProject()),
ProjectRootModificationTracker.getInstance(step.getProject()));
- });
+ }));
}
@NotNull
@@ -121,7 +121,7 @@ static Collection getAllStepAnnotations(@NotNull final PsiClass a
psiAnnotations.addAll(KotlinAnnotationsLoader.getAnnotations(QualifiedName.fromDottedString(annotationFqn), project, scope));
}
}
- psiAnnotations.addAll(JavaAnnotationIndex.getInstance().get(annClass.getName(), project, scope));
+ psiAnnotations.addAll(JavaAnnotationIndex.getInstance().getAnnotations(annClass.getName(), project, scope));
return psiAnnotations;
});
diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/service/JBehaveUtil.java b/src/main/java/com/github/kumaraman21/intellijbehave/service/JBehaveUtil.java
index 082ba82..fdf7555 100644
--- a/src/main/java/com/github/kumaraman21/intellijbehave/service/JBehaveUtil.java
+++ b/src/main/java/com/github/kumaraman21/intellijbehave/service/JBehaveUtil.java
@@ -1,11 +1,11 @@
package com.github.kumaraman21.intellijbehave.service;
+import static com.intellij.openapi.application.ReadAction.compute;
import static com.intellij.openapi.util.text.StringUtil.isEmptyOrSpaces;
import com.github.kumaraman21.intellijbehave.jbehave.core.steps.PatternVariantBuilder;
import com.github.kumaraman21.intellijbehave.language.StoryFileType;
import com.intellij.codeInsight.AnnotationUtil;
-import com.intellij.openapi.application.ReadAction;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiAnnotationMemberValue;
@@ -44,7 +44,7 @@ public final class JBehaveUtil {
* Returns if the provided annotation is one of {@link #JBEHAVE_ANNOTATIONS_SET}.
*/
public static boolean isJBehaveStepAnnotation(@NotNull PsiAnnotation annotation) {
- String annotationName = annotation.getQualifiedName();
+ String annotationName = compute(annotation::getQualifiedName);
return annotationName != null && JBEHAVE_ANNOTATIONS_SET.contains(annotationName);
}
@@ -56,7 +56,7 @@ public static boolean isJBehaveStepAnnotation(@NotNull PsiAnnotation annotation)
*/
public static boolean isAnnotationOfClass(@NotNull PsiAnnotation annotation,
@NotNull Class extends Annotation> annotationClass) {
- String annotationName = annotation.getQualifiedName();
+ String annotationName = compute(annotation::getQualifiedName);
return annotationName != null && annotationName.equals(annotationClass.getName());
}
@@ -66,7 +66,7 @@ public static boolean isAnnotationOfClass(@NotNull PsiAnnotation annotation,
*/
@NotNull
private static List getJBehaveStepAnnotations(@NotNull PsiMethod method) {
- return Stream.of(method.getModifierList().getAnnotations())
+ return Stream.of(compute(() -> method.getModifierList().getAnnotations()))
.filter(JBehaveUtil::isJBehaveStepAnnotation)
.collect(Collectors.toList());
}
@@ -80,7 +80,7 @@ private static List getJBehaveStepAnnotations(@NotNull PsiMethod
*/
public static boolean isStepDefinition(@NotNull PsiMethod method) {
return getJBehaveStepAnnotations(method).stream()
- .map(stepAnnotation -> stepAnnotation.findAttributeValue("value"))
+ .map(stepAnnotation -> compute(() -> stepAnnotation.findAttributeValue("value")))
.anyMatch(Objects::nonNull);
}
@@ -98,9 +98,9 @@ public static Set getAnnotationTexts(@NotNull PsiAnnotation stepAnnotati
getAnnotationText(stepAnnotation).ifPresent(annotationTexts::add);
//If the parent method is available, e.g. from JBehaveJavaStepDefinitionSearch, then use that, otherwise compute it
- PsiMethod method = parentMethod != null ? parentMethod : PsiTreeUtil.getParentOfType(stepAnnotation, PsiMethod.class);
+ PsiMethod method = parentMethod != null ? parentMethod : compute(() -> PsiTreeUtil.getParentOfType(stepAnnotation, PsiMethod.class));
if (method != null) {
- for (PsiAnnotation annotation : method.getModifierList().getAnnotations()) {
+ for (PsiAnnotation annotation : compute(() -> method.getModifierList().getAnnotations())) {
if (isAnnotationOfClass(annotation, Alias.class)) {
getAnnotationText(annotation).ifPresent(annotationTexts::add);
} else if (isAnnotationOfClass(annotation, Aliases.class)) {
@@ -121,14 +121,14 @@ public static Set getAnnotationTexts(@NotNull PsiAnnotation stepAnnotati
* @param annotation a JBehave annotation: Given, When, Then, Alias or Aliases
*/
private static Optional getAnnotationText(@NotNull PsiAnnotation annotation) {
- return Optional.ofNullable(AnnotationUtil.getStringAttributeValue(annotation, "value"));
+ return Optional.ofNullable(compute(() -> AnnotationUtil.getStringAttributeValue(annotation, "value")));
}
@NotNull
private static Set getAliasesAnnotationTexts(@NotNull PsiAnnotation aliasAnnotation) {
- return AnnotationUtil.arrayAttributeValues(aliasAnnotation.findAttributeValue("values"))
+ return compute(() -> AnnotationUtil.arrayAttributeValues(aliasAnnotation.findAttributeValue("values")))
.stream()
- .map(AnnotationUtil::getStringAttributeValue)
+ .map(attr -> compute(() -> AnnotationUtil.getStringAttributeValue(attr)))
.collect(Collectors.toSet());
}
@@ -153,10 +153,12 @@ public static List getAnnotationTexts(@NotNull PsiMethod method) {
*/
@NotNull
public static Integer getAnnotationPriority(@NotNull PsiAnnotation stepAnnotation) {
- PsiAnnotationMemberValue attrValue = stepAnnotation.findAttributeValue("priority");
+ PsiAnnotationMemberValue attrValue = compute(() -> stepAnnotation.findAttributeValue("priority"));
// TODO test change doesn't break other languages; this change works as a quick fix for Kotlin
//Object constValue = JavaPsiFacade.getInstance(stepAnnotation.getProject()).getConstantEvaluationHelper().computeConstantExpression(attrValue);
- Object constValue = JavaPsiFacade.getInstance(stepAnnotation.getProject()).getConstantEvaluationHelper().computeConstantExpression(attrValue.getOriginalElement());
+ Object constValue = compute(() -> JavaPsiFacade.getInstance(compute(stepAnnotation::getProject))
+ .getConstantEvaluationHelper()
+ .computeConstantExpression(attrValue.getOriginalElement()));
Integer priority = constValue instanceof Integer ? (Integer) constValue : null;
return priority != null ? priority : -1;
@@ -180,7 +182,7 @@ public static boolean findJBehaveReferencesToElement(@NotNull PsiElement stepDef
String word = getTheBiggestWordToSearchByIndex(stepText);
return isEmptyOrSpaces(word)
- || PsiSearchHelper.getInstance(stepDefinitionElement.getProject())
+ || PsiSearchHelper.getInstance(compute(stepDefinitionElement::getProject))
.processElementsWithWord(new MyReferenceCheckingProcessor(stepDefinitionElement, consumer), searchScope, word, (short) 5, true);
}
@@ -188,7 +190,7 @@ public static boolean findJBehaveReferencesToElement(@NotNull PsiElement stepDef
* Returns a search scope that is based on the {@code originalScopeComputation} but that is restricted to JBehave Story file types.
*/
public static SearchScope restrictScopeToJBehaveFiles(final SearchScope originalScope) {
- return ReadAction.compute(() ->
+ return compute(() ->
originalScope instanceof GlobalSearchScope globalSearchScope
? GlobalSearchScope.getScopeRestrictedByFileTypes(globalSearchScope, StoryFileType.STORY_FILE_TYPE)
: originalScope);
diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/service/JavaStepDefinition.java b/src/main/java/com/github/kumaraman21/intellijbehave/service/JavaStepDefinition.java
index bca1387..5e8c83c 100644
--- a/src/main/java/com/github/kumaraman21/intellijbehave/service/JavaStepDefinition.java
+++ b/src/main/java/com/github/kumaraman21/intellijbehave/service/JavaStepDefinition.java
@@ -1,9 +1,9 @@
package com.github.kumaraman21.intellijbehave.service;
import static com.github.kumaraman21.intellijbehave.utility.StepTypeMappings.ANNOTATION_TO_STEP_TYPE_MAPPING;
+import static com.intellij.openapi.application.ReadAction.compute;
import com.github.kumaraman21.intellijbehave.parser.JBehaveStep;
-import com.intellij.openapi.application.ReadAction;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.SmartPointerManager;
@@ -27,7 +27,7 @@ public final class JavaStepDefinition {
private final SmartPsiElementPointer annotationPointer;
public JavaStepDefinition(PsiAnnotation annotation) {
- annotationPointer = SmartPointerManager.getInstance(annotation.getProject()).createSmartPsiElementPointer(annotation);
+ annotationPointer = compute(() -> SmartPointerManager.getInstance(annotation.getProject()).createSmartPsiElementPointer(annotation));
}
/**
@@ -87,7 +87,7 @@ private PsiAnnotation getAnnotation() {
*/
@Nullable
public PsiMethod getAnnotatedMethod() {
- return PsiTreeUtil.getParentOfType(getAnnotation(), PsiMethod.class);
+ return compute(() -> PsiTreeUtil.getParentOfType(getAnnotation(), PsiMethod.class));
}
@NotNull
@@ -106,7 +106,7 @@ public StepType getAnnotationType() {
final PsiAnnotation annotation = getAnnotation();
return annotation == null
? null
- : ANNOTATION_TO_STEP_TYPE_MAPPING.get(ReadAction.compute(annotation::getQualifiedName));
+ : ANNOTATION_TO_STEP_TYPE_MAPPING.get(compute(annotation::getQualifiedName));
}
/**
diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/service/StepAnnotationsCache.java b/src/main/java/com/github/kumaraman21/intellijbehave/service/StepAnnotationsCache.java
index 3980df4..0e5822b 100644
--- a/src/main/java/com/github/kumaraman21/intellijbehave/service/StepAnnotationsCache.java
+++ b/src/main/java/com/github/kumaraman21/intellijbehave/service/StepAnnotationsCache.java
@@ -49,7 +49,7 @@ public StepAnnotations cacheStepAnnotations(Module module, GlobalSearchScope dep
*/
@Nullable("When there is no annotation class found.")
private PsiClass findStepAnnotation(String stepAnnotationClassFqn, GlobalSearchScope dependenciesScope) {
- var stepDefAnnotationCandidates = JavaFullClassNameIndex.getInstance().get(stepAnnotationClassFqn, project, dependenciesScope);
+ var stepDefAnnotationCandidates = JavaFullClassNameIndex.getInstance().getClasses(stepAnnotationClassFqn, project, dependenciesScope);
for (PsiClass stepDefAnnotations : stepDefAnnotationCandidates) {
if (stepAnnotationClassFqn.equals(stepDefAnnotations.getQualifiedName())) {
return stepDefAnnotations;
diff --git a/src/main/kotlin/com/github/kumaraman21/intellijbehave/JBehaveStepDefClassPsiChangeListener.kt b/src/main/kotlin/com/github/kumaraman21/intellijbehave/JBehaveStepDefClassPsiChangeListener.kt
index 5ad289a..ae0fee9 100644
--- a/src/main/kotlin/com/github/kumaraman21/intellijbehave/JBehaveStepDefClassPsiChangeListener.kt
+++ b/src/main/kotlin/com/github/kumaraman21/intellijbehave/JBehaveStepDefClassPsiChangeListener.kt
@@ -26,13 +26,13 @@ class JBehaveStepDefClassPsiChangeListener(val project: Project) : PsiTreeChange
private fun updateJBehaveTestClassModificationTracker(event: PsiTreeChangeEvent) {
val file = event.file
- if (file != null) {
+ if (file != null && file.isValid) {
updateModificationTrackerIfFileContainsJBehaveStepDefClass(file)
}
//file is null when the file has just been deleted
else {
val child = event.child
- if (child is PsiJavaFile) {
+ if (child is PsiJavaFile && child.isValid) {
updateModificationTrackerIfFileContainsJBehaveStepDefClass(child)
}
}
diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml
index 10f79f9..936b31e 100644
--- a/src/main/resources/META-INF/plugin.xml
+++ b/src/main/resources/META-INF/plugin.xml
@@ -43,7 +43,7 @@
]]>
Bert Van Vlerken, Victor Rosenberg
-
+
com.intellij.modules.java
org.jetbrains.kotlin
@@ -62,6 +62,11 @@
+
+
+
+
+
getFixture().copyDirectoryToProject("src", ""), ModalityState.nonModal());
}
}
diff --git a/src/test/java/com/github/kumaraman21/intellijbehave/JBehaveSupportTestBase.java b/src/test/java/com/github/kumaraman21/intellijbehave/JBehaveSupportTestBase.java
index 670c0dc..78933c5 100644
--- a/src/test/java/com/github/kumaraman21/intellijbehave/JBehaveSupportTestBase.java
+++ b/src/test/java/com/github/kumaraman21/intellijbehave/JBehaveSupportTestBase.java
@@ -1,17 +1,12 @@
package com.github.kumaraman21.intellijbehave;
-import com.intellij.openapi.Disposable;
-import com.intellij.openapi.module.Module;
+import static com.intellij.openapi.application.ReadAction.compute;
+
import com.intellij.openapi.projectRoots.JavaSdk;
-import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess;
-import com.intellij.testFramework.PsiTestUtil;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase5;
-import com.intellij.util.PathUtil;
-import org.jetbrains.annotations.NotNull;
-import org.junit.jupiter.api.BeforeEach;
-
-import java.io.File;
/**
* Base test class for this plugin.
@@ -19,25 +14,19 @@
public abstract class JBehaveSupportTestBase extends LightJavaCodeInsightFixtureTestCase5 {
protected JBehaveSupportTestBase() {
- super(new DefaultLightProjectDescriptor(() -> JavaSdk.getInstance().createJdk("Real JDK", System.getenv("JAVA_HOME"), false)));
+ super(new DefaultLightProjectDescriptor(() -> JavaSdk.getInstance().createJdk("Real JDK", System.getenv("JAVA_HOME"), false))
+ .withRepositoryLibrary("org.jbehave:jbehave-core:5.2.0"));
}
protected JBehaveSupportTestBase(DefaultLightProjectDescriptor projectDescriptor) {
super(projectDescriptor);
}
- @BeforeEach
- protected void setUp() {
- loadLibraries();
- }
-
- protected void loadLibraries() {
- loadLibrary(getFixture().getProjectDisposable(), getFixture().getModule(), "JBehave Core", "jbehave-core-5.1.1.jar");
+ protected int getCaretOffset() {
+ return compute(() -> getFixture().getCaretOffset());
}
- private static void loadLibrary(@NotNull Disposable projectDisposable, @NotNull Module module, String libraryName, String libraryJarName) {
- String libPath = PathUtil.toSystemIndependentName(new File("lib").getAbsolutePath());
- VfsRootAccess.allowRootAccess(projectDisposable, libPath);
- PsiTestUtil.addLibrary(projectDisposable, module, libraryName, libPath, libraryJarName);
+ protected PsiElement getParentOfElementAtCaretIn(PsiFile psiFile) {
+ return compute(() -> psiFile.findElementAt(getFixture().getCaretOffset()).getParent());
}
}
diff --git a/src/test/java/com/github/kumaraman21/intellijbehave/codeInspector/ContentEntryInspectionTestBase.java b/src/test/java/com/github/kumaraman21/intellijbehave/codeInspector/ContentEntryInspectionTestBase.java
index bb9721e..07dc429 100644
--- a/src/test/java/com/github/kumaraman21/intellijbehave/codeInspector/ContentEntryInspectionTestBase.java
+++ b/src/test/java/com/github/kumaraman21/intellijbehave/codeInspector/ContentEntryInspectionTestBase.java
@@ -1,10 +1,12 @@
package com.github.kumaraman21.intellijbehave.codeInspector;
+import static com.intellij.openapi.application.ApplicationManager.getApplication;
+
import com.github.kumaraman21.intellijbehave.ContentEntryProjectDescriptor;
import com.github.kumaraman21.intellijbehave.JBehaveSupportTestBase;
import com.intellij.codeInspection.InspectionProfileEntry;
+import com.intellij.openapi.application.ModalityState;
import com.intellij.testFramework.TestDataFile;
-import org.junit.jupiter.api.BeforeEach;
/**
* Base test class for inspections using content entries.
@@ -12,7 +14,7 @@
abstract class ContentEntryInspectionTestBase extends JBehaveSupportTestBase {
public ContentEntryInspectionTestBase() {
- super(new ContentEntryProjectDescriptor());
+ super(new ContentEntryProjectDescriptor().withRepositoryLibrary("org.jbehave:jbehave-core:5.2.0"));
}
/**
@@ -20,11 +22,12 @@ public ContentEntryInspectionTestBase() {
*/
protected abstract InspectionProfileEntry getInspection();
- @Override
- @BeforeEach
- protected void setUp() {
- super.setUp();
- getFixture().copyDirectoryToProject("src", "");
+ /**
+ * The directory has to be copied in each related test method, instead of in a before hooks,
+ * so that it is called properly on EDT in write-safe context.
+ */
+ protected void copySrcDirectoryToProject() {
+ getApplication().invokeAndWait(() -> getFixture().copyDirectoryToProject("src", ""), ModalityState.nonModal());
}
/**
diff --git a/src/test/java/com/github/kumaraman21/intellijbehave/codeInspector/UndefinedStepInspectionTest.java b/src/test/java/com/github/kumaraman21/intellijbehave/codeInspector/UndefinedStepInspectionTest.java
index 88fa659..55734d8 100644
--- a/src/test/java/com/github/kumaraman21/intellijbehave/codeInspector/UndefinedStepInspectionTest.java
+++ b/src/test/java/com/github/kumaraman21/intellijbehave/codeInspector/UndefinedStepInspectionTest.java
@@ -1,14 +1,12 @@
package com.github.kumaraman21.intellijbehave.codeInspector;
import com.intellij.codeInspection.InspectionProfileEntry;
-import com.intellij.testFramework.junit5.RunInEdt;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Test;
/**
* Integration test for {@link UndefinedStepInspection}.
*/
-@RunInEdt
class UndefinedStepInspectionTest extends ContentEntryInspectionTestBase {
@Nullable
@@ -24,6 +22,7 @@ protected InspectionProfileEntry getInspection() {
@Test
void highlightingUndefinedSteps() {
+ copySrcDirectoryToProject();
getFixture().copyFileToProject("main/java/OtherStepDefs.java");
getFixture().copyFileToProject("main/java/StepDefs.java");
doTest("src/test/resources/undefined_steps.story");
diff --git a/src/test/java/com/github/kumaraman21/intellijbehave/codeInspector/UnusedStepDeclarationInspectionTest.java b/src/test/java/com/github/kumaraman21/intellijbehave/codeInspector/UnusedStepDeclarationInspectionTest.java
index 54cde84..9833446 100644
--- a/src/test/java/com/github/kumaraman21/intellijbehave/codeInspector/UnusedStepDeclarationInspectionTest.java
+++ b/src/test/java/com/github/kumaraman21/intellijbehave/codeInspector/UnusedStepDeclarationInspectionTest.java
@@ -1,14 +1,12 @@
package com.github.kumaraman21.intellijbehave.codeInspector;
import com.intellij.codeInspection.InspectionProfileEntry;
-import com.intellij.testFramework.junit5.RunInEdt;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Test;
/**
* Integration test for {@link UnusedStepDeclarationInspection}.
*/
-@RunInEdt
class UnusedStepDeclarationInspectionTest extends ContentEntryInspectionTestBase {
@Nullable
@@ -24,6 +22,7 @@ protected InspectionProfileEntry getInspection() {
@Test
void highlightingUnusedStepDeclaration() {
+ copySrcDirectoryToProject();
getFixture().copyFileToProject("main/java/OtherStepDefs.java");
getFixture().copyFileToProject("test/resources/unused_step_declarations.story");
doTest("main/java/StepDefs.java");
diff --git a/src/test/java/com/github/kumaraman21/intellijbehave/resolver/StepDefinitionIteratorTest.java b/src/test/java/com/github/kumaraman21/intellijbehave/resolver/StepDefinitionIteratorTest.java
index c48f00b..cafa153 100644
--- a/src/test/java/com/github/kumaraman21/intellijbehave/resolver/StepDefinitionIteratorTest.java
+++ b/src/test/java/com/github/kumaraman21/intellijbehave/resolver/StepDefinitionIteratorTest.java
@@ -4,7 +4,6 @@
import com.github.kumaraman21.intellijbehave.ContentEntryTestBase;
import com.intellij.openapi.project.Project;
-import com.intellij.testFramework.junit5.RunInEdt;
import org.jbehave.core.steps.StepType;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Test;
@@ -14,7 +13,6 @@
/**
* Integration test for {@link StepDefinitionIterator}.
*/
-@RunInEdt
class StepDefinitionIteratorTest extends ContentEntryTestBase {
@Nullable
@@ -25,6 +23,7 @@ protected String getTestDataPath() {
@Test
void processesEverything() {
+ copySrcDirectoryToProject();
getFixture().copyFileToProject("main/java/OtherStepDefs.java");
getFixture().copyFileToProject("main/kotlin/AnotherStepDefs.kt");
getFixture().copyFileToProject("src/test/resources/iterator.story");
@@ -38,6 +37,7 @@ void processesEverything() {
@Test
void processesNothing() {
+ copySrcDirectoryToProject();
getFixture().copyFileToProject("main/java/OtherStepDefs.java");
getFixture().copyFileToProject("main/kotlin/AnotherStepDefs.kt");
getFixture().copyFileToProject("src/test/resources/iterator.story");
@@ -51,6 +51,7 @@ void processesNothing() {
@Test
void processesFiltered() {
+ copySrcDirectoryToProject();
getFixture().copyFileToProject("main/java/OtherStepDefs.java");
getFixture().copyFileToProject("main/kotlin/AnotherStepDefs.kt");
getFixture().copyFileToProject("src/test/resources/iterator.story");
@@ -64,6 +65,7 @@ void processesFiltered() {
@Test
void processesFilteredKotlin() {
+ copySrcDirectoryToProject();
getFixture().copyFileToProject("main/java/OtherStepDefs.java");
getFixture().copyFileToProject("main/java/StepDefs.java");
getFixture().copyFileToProject("src/test/resources/iterator.story");
diff --git a/src/test/java/com/github/kumaraman21/intellijbehave/resolver/StepPsiReferenceContributorTest.java b/src/test/java/com/github/kumaraman21/intellijbehave/resolver/StepPsiReferenceContributorTest.java
index 36abcbc..46b20b0 100644
--- a/src/test/java/com/github/kumaraman21/intellijbehave/resolver/StepPsiReferenceContributorTest.java
+++ b/src/test/java/com/github/kumaraman21/intellijbehave/resolver/StepPsiReferenceContributorTest.java
@@ -3,15 +3,14 @@
import static org.assertj.core.api.Assertions.assertThat;
import com.github.kumaraman21.intellijbehave.ContentEntryTestBase;
+import com.intellij.openapi.application.ReadAction;
import com.intellij.psi.PsiReference;
-import com.intellij.testFramework.junit5.RunInEdt;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Test;
/**
* Integration test for {@link StepPsiReferenceContributor}.
*/
-@RunInEdt
class StepPsiReferenceContributorTest extends ContentEntryTestBase {
@Nullable
@@ -22,15 +21,16 @@ protected String getTestDataPath() {
@Test
void shouldProviderReferenceForStep() {
+ copySrcDirectoryToProject();
var storyFile = getFixture().configureByFile("test/resources/step_reference.story");
getFixture().copyFileToProject("main/java/StepDefs.java");
- var step = storyFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var step = getParentOfElementAtCaretIn(storyFile);
PsiReference[] references = step.getReferences();
assertThat(references).hasSize(1);
assertThat(references[0])
.isInstanceOf(StepPsiReference.class)
- .extracting(ref -> ref.resolve().getText())
+ .extracting(ref -> ReadAction.compute(() -> ref.resolve().getText()))
.isEqualTo("""
@When("search for $string")
public void searchForText(@Named("string") String string) {
@@ -39,9 +39,10 @@ public void searchForText(@Named("string") String string) {
@Test
void shouldNotProvideReferenceForNonStepElement() {
+ copySrcDirectoryToProject();
var storyFile = getFixture().configureByFile("test/resources/non_step_reference.story");
getFixture().copyFileToProject("main/java/StepDefs.java");
- var step = storyFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var step = getParentOfElementAtCaretIn(storyFile);
assertThat(step.getReferences()).isEmpty();
}
diff --git a/src/test/java/com/github/kumaraman21/intellijbehave/resolver/StepPsiReferenceTest.java b/src/test/java/com/github/kumaraman21/intellijbehave/resolver/StepPsiReferenceTest.java
index 256da39..c669c0b 100644
--- a/src/test/java/com/github/kumaraman21/intellijbehave/resolver/StepPsiReferenceTest.java
+++ b/src/test/java/com/github/kumaraman21/intellijbehave/resolver/StepPsiReferenceTest.java
@@ -1,5 +1,6 @@
package com.github.kumaraman21.intellijbehave.resolver;
+import static com.intellij.openapi.application.ReadAction.compute;
import static org.assertj.core.api.Assertions.assertThat;
import com.github.kumaraman21.intellijbehave.ContentEntryTestBase;
@@ -7,14 +8,12 @@
import com.intellij.psi.PsiManager;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiReference;
-import com.intellij.testFramework.junit5.RunInEdt;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Test;
/**
* Integration test for {@link StepPsiReference}.
*/
-@RunInEdt
class StepPsiReferenceTest extends ContentEntryTestBase {
@Nullable
@@ -27,25 +26,27 @@ protected String getTestDataPath() {
@Test
void shouldBeReferenceToPsiMethod() {
+ copySrcDirectoryToProject();
var storyFile = getFixture().configureByFile("test/resources/step_reference.story");
getFixture().copyFileToProject("main/java/StepDefs.java");
- var step = storyFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var step = getParentOfElementAtCaretIn(storyFile);
PsiReference[] references = step.getReferences();
assertThat(references).hasSize(1);
- var resolvedMethod = (PsiMethod) references[0].resolve();
+ var resolvedMethod = (PsiMethod) compute(() -> references[0].resolve());
assertThat(references[0].isReferenceTo(resolvedMethod)).isTrue();
}
@Test
void shouldNotBeReferenceToElement() {
+ copySrcDirectoryToProject();
var storyFile = getFixture().configureByFile("test/resources/step_reference.story");
var stepDefVirtualFile = getFixture().copyFileToProject("main/java/StepDefs.java");
- var step = storyFile.findElementAt(getFixture().getCaretOffset()).getParent();
- var stepDefFile = PsiManager.getInstance(getFixture().getProject()).findFile(stepDefVirtualFile);
- var notReferencedStepDefMethod = ((PsiJavaFile) stepDefFile).getClasses()[0].findMethodsByName("openAUrl", false)[0];
+ var step = getParentOfElementAtCaretIn(storyFile);
+ var stepDefFile = compute(() -> PsiManager.getInstance(getFixture().getProject()).findFile(stepDefVirtualFile));
+ var notReferencedStepDefMethod = compute(() -> ((PsiJavaFile) stepDefFile).getClasses()[0].findMethodsByName("openAUrl", false)[0]);
PsiReference[] references = step.getReferences();
assertThat(references).hasSize(1);
diff --git a/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveJavaMethodUsageSearcherTest.java b/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveJavaMethodUsageSearcherTest.java
index 7e148dc..51eca02 100644
--- a/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveJavaMethodUsageSearcherTest.java
+++ b/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveJavaMethodUsageSearcherTest.java
@@ -9,7 +9,6 @@
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.searches.MethodReferencesSearch;
-import com.intellij.testFramework.junit5.RunInEdt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Test;
@@ -17,7 +16,6 @@
/**
* Integration test for {@link JBehaveJavaMethodUsageSearcher}.
*/
-@RunInEdt
class JBehaveJavaMethodUsageSearcherTest extends ContentEntryTestBase {
@Nullable
@@ -28,8 +26,9 @@ protected String getTestDataPath() {
@Test
void shouldReturnTrueIfThereIsNoStepText() {
+ copySrcDirectoryToProject();
var stepDefFile = getFixture().configureByFile("main/java/StepDefs.java");
- var method = (PsiMethod) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var method = (PsiMethod) getParentOfElementAtCaretIn(stepDefFile);
var queryParameters = new MethodReferencesSearch.SearchParameters(method, GlobalSearchScope.projectScope(getFixture().getProject()), false);
var ref = new Ref();
@@ -43,8 +42,9 @@ void shouldReturnTrueIfThereIsNoStepText() {
@Test
void shouldNotProcessQueryIfStepTextIsEmpty() {
+ copySrcDirectoryToProject();
var stepDefFile = getFixture().configureByFile("main/java/MoreStepDefs.java");
- var method = (PsiMethod) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var method = (PsiMethod) getParentOfElementAtCaretIn(stepDefFile);
var queryParameters = new MethodReferencesSearch.SearchParameters(method, GlobalSearchScope.projectScope(getFixture().getProject()), false);
var ref = new Ref();
@@ -58,8 +58,9 @@ void shouldNotProcessQueryIfStepTextIsEmpty() {
@Test
void shouldNotProcessQueryIfSearchScopeIsNotGlobal() {
+ copySrcDirectoryToProject();
var stepDefFile = getFixture().configureByFile("main/java/OtherStepDefs.java");
- var method = (PsiMethod) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var method = (PsiMethod) getParentOfElementAtCaretIn(stepDefFile);
var queryParameters = new MethodReferencesSearch.SearchParameters(method, new DummyScope(), false);
var ref = new Ref();
diff --git a/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveJavaStepDefinitionSearchTest.java b/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveJavaStepDefinitionSearchTest.java
index 1e27ead..6c71b49 100644
--- a/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveJavaStepDefinitionSearchTest.java
+++ b/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveJavaStepDefinitionSearchTest.java
@@ -6,14 +6,12 @@
import com.intellij.psi.PsiMethod;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.searches.ReferencesSearch;
-import com.intellij.testFramework.junit5.RunInEdt;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Test;
/**
* Integration test for {@link JBehaveJavaStepDefinitionSearch}.
*/
-@RunInEdt
class JBehaveJavaStepDefinitionSearchTest extends ContentEntryTestBase {
@Nullable
@@ -24,8 +22,9 @@ protected String getTestDataPath() {
@Test
void shouldReturnTrueForNonPsiMethodElement() {
+ copySrcDirectoryToProject();
var stepDefFile = getFixture().configureByFile("main/java/OtherStepDefs.java");
- var element = stepDefFile.findElementAt(getFixture().getCaretOffset());
+ var element = stepDefFile.findElementAt(getCaretOffset());
var queryParameters = new ReferencesSearch.SearchParameters(element, GlobalSearchScope.projectScope(getFixture().getProject()), false);
boolean shouldContinue = new JBehaveJavaStepDefinitionSearch().execute(queryParameters, __ -> true);
@@ -35,8 +34,9 @@ void shouldReturnTrueForNonPsiMethodElement() {
@Test
void shouldReturnTrueForNonStepDefinitionMethod() {
+ copySrcDirectoryToProject();
var stepDefFile = getFixture().configureByFile("main/java/StepDefs.java");
- var method = (PsiMethod) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var method = (PsiMethod) getParentOfElementAtCaretIn(stepDefFile);
var queryParameters = new ReferencesSearch.SearchParameters(method, GlobalSearchScope.projectScope(getFixture().getProject()), false);
boolean shouldContinue = new JBehaveJavaStepDefinitionSearch().execute(queryParameters, __ -> true);
@@ -52,8 +52,9 @@ void shouldReturnTrueForNonStepDefinitionMethod() {
@Test
void shouldReturnTrueForValidStepDefinitionMethod() {
+ copySrcDirectoryToProject();
var stepDefFile = getFixture().configureByFile("main/java/MoreStepDefs.java");
- var method = (PsiMethod) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var method = (PsiMethod) getParentOfElementAtCaretIn(stepDefFile);
var queryParameters = new ReferencesSearch.SearchParameters(method, GlobalSearchScope.projectScope(getFixture().getProject()), false);
boolean shouldContinue = new JBehaveJavaStepDefinitionSearch().execute(queryParameters, ref -> true);
@@ -63,8 +64,9 @@ void shouldReturnTrueForValidStepDefinitionMethod() {
@Test
void shouldReturnFalseForValidStepDefinitionMethodAndFalseConsumer() {
+ copySrcDirectoryToProject();
var stepDefFile = getFixture().configureByFile("main/java/MoreStepDefs.java");
- var method = (PsiMethod) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var method = (PsiMethod) getParentOfElementAtCaretIn(stepDefFile);
var queryParameters = new ReferencesSearch.SearchParameters(method, GlobalSearchScope.projectScope(getFixture().getProject()), false);
boolean shouldContinue = new JBehaveJavaStepDefinitionSearch().execute(queryParameters, ref -> false);
diff --git a/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndexTest.java b/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndexTest.java
index 5805331..fe53551 100644
--- a/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndexTest.java
+++ b/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndexTest.java
@@ -1,5 +1,6 @@
package com.github.kumaraman21.intellijbehave.service;
+import static com.intellij.openapi.application.ReadAction.compute;
import static java.util.stream.Collectors.toSet;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
@@ -7,15 +8,14 @@
import com.github.kumaraman21.intellijbehave.ContentEntryTestBase;
import com.github.kumaraman21.intellijbehave.parser.JBehaveStep;
import com.intellij.codeInsight.AnnotationUtil;
+import com.intellij.openapi.application.ReadAction;
import com.intellij.psi.PsiSubstitutor;
import com.intellij.psi.impl.java.stubs.index.JavaFullClassNameIndex;
-import com.intellij.testFramework.junit5.RunInEdt;
import org.junit.jupiter.api.Test;
/**
* Functional test for {@link JBehaveStepsIndex}.
*/
-@RunInEdt
class JBehaveStepsIndexTest extends ContentEntryTestBase {
@Override
@@ -27,6 +27,7 @@ protected String getTestDataPath() {
@Test
void shouldFindsSingleStepDefinition() {
+ copySrcDirectoryToProject();
getFixture().copyFileToProject("main/java/StepDefs.java");
getFixture().copyFileToProject("main/java/OtherStepDefs.java");
@@ -36,8 +37,8 @@ void shouldFindsSingleStepDefinition() {
assertThat(stepDefinitions).hasSize(1);
assertThat(stepDefinitions.iterator().next().getAnnotatedMethod().getContainingClass().getQualifiedName()).isEqualTo("StepDefs");
- assertThat(stepDefinitions.iterator().next().getAnnotatedMethod().getSignature(PsiSubstitutor.EMPTY))
- .hasToString("MethodSignatureBackedByPsiMethod: openAUrl([PsiType:String])");
+ assertThat(compute(() -> stepDefinitions.iterator().next().getAnnotatedMethod().getSignature(PsiSubstitutor.EMPTY).toString()))
+ .isEqualTo("MethodSignatureBackedByPsiMethod: openAUrl([PsiType:String])");
}
//NOTE: at the moment, this only returns the first found step definition, regardless of the step pattern
@@ -45,6 +46,7 @@ void shouldFindsSingleStepDefinition() {
//Supporting returning multiple matching step definitions should be revisited.
@Test
void shouldFindsMultipleStepDefinitions() {
+ copySrcDirectoryToProject();
getFixture().copyFileToProject("main/java/StepDefs.java");
getFixture().copyFileToProject("main/java/OtherStepDefs.java");
getFixture().configureByFile("test/resources/has_multiple_java_step_def.story");
@@ -59,6 +61,7 @@ void shouldFindsMultipleStepDefinitions() {
@Test
void shouldFindsNoStepDefinition() {
+ copySrcDirectoryToProject();
getFixture().copyFileToProject("main/java/StepDefs.java");
getFixture().copyFileToProject("main/java/OtherStepDefs.java");
getFixture().configureByFile("test/resources/has_no_java_step_def.story");
@@ -72,6 +75,7 @@ void shouldFindsNoStepDefinition() {
@Test
void shouldFindAllAnnotations() {
+ copySrcDirectoryToProject();
getFixture().copyFileToProject("main/java/StepDefs.java");
getFixture().copyFileToProject("main/java/OtherStepDefs.java");
getFixture().copyFileToProject("main/kotlin/AnotherStepDefs.kt");
@@ -79,14 +83,14 @@ void shouldFindAllAnnotations() {
getFixture().configureByFile("test/resources/has_java_step_def.story");
var scope = getFixture().getModule().getModuleWithDependenciesAndLibrariesScope(true);
- var thenAnnotations = JavaFullClassNameIndex.getInstance().get("org.jbehave.core.annotations.Then", getFixture().getProject(), scope);
+ var thenAnnotations = ReadAction.compute(() -> JavaFullClassNameIndex.getInstance().getClasses("org.jbehave.core.annotations.Then", getFixture().getProject(), scope));
if (thenAnnotations.isEmpty()) fail("The @Then step def annotation was not found.");
var stepDefinitions = JBehaveStepsIndex.getInstance(getFixture().getProject()).getAllStepAnnotations(thenAnnotations.iterator().next(), scope);
assertThat(stepDefinitions).hasSize(3);
var stepTexts = stepDefinitions.stream()
- .map(annotation -> AnnotationUtil.getStringAttributeValue(annotation, "value"))
+ .map(annotation -> ReadAction.compute(() -> AnnotationUtil.getStringAttributeValue(annotation, "value")))
.collect(toSet());
assertThat(stepTexts).containsExactlyInAnyOrder(
@@ -96,6 +100,6 @@ void shouldFindAllAnnotations() {
}
private JBehaveStep getStep() {
- return (JBehaveStep) getFixture().getFile().findElementAt(getFixture().getCaretOffset()).getParent();
+ return (JBehaveStep) getParentOfElementAtCaretIn(getFixture().getFile());
}
}
diff --git a/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndexWithNoDependencyTest.java b/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndexWithNoDependencyTest.java
index 72ef6e5..e3c758f 100644
--- a/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndexWithNoDependencyTest.java
+++ b/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndexWithNoDependencyTest.java
@@ -2,35 +2,33 @@
import static org.assertj.core.api.Assertions.assertThat;
+import com.github.kumaraman21.intellijbehave.ContentEntryProjectDescriptor;
import com.github.kumaraman21.intellijbehave.ContentEntryTestBase;
import com.github.kumaraman21.intellijbehave.parser.JBehaveStep;
-import com.intellij.testFramework.junit5.RunInEdt;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* Functional test for {@link JBehaveStepsIndex}.
*/
-@RunInEdt
class JBehaveStepsIndexWithNoDependencyTest extends ContentEntryTestBase {
- @Override
- protected String getTestDataPath() {
- return "src/test/testData/stepsindex";
+ public JBehaveStepsIndexWithNoDependencyTest() {
+ //Doesn't load jbehave-core to emulate the missing JBehave
+ super(new ContentEntryProjectDescriptor());
}
@Override
- protected void loadLibraries() {
- //Doesn't load anything to emulate the missing JBehave
+ protected String getTestDataPath() {
+ return "src/test/testData/stepsindex";
}
@Test
void shouldFindNoStepDefinitionDueToNoJBehaveAnnotationsAvailable() {
- getFixture().copyFileToProject("main/java/StepDefs.java");
- getFixture().copyFileToProject("main/java/OtherStepDefs.java");
- getFixture().configureByFile("test/resources/has_java_step_def.story");
+ getFixture().copyFileToProject("src/main/java/StepDefs.java");
+ getFixture().copyFileToProject("src/main/java/OtherStepDefs.java");
+ getFixture().configureByFile("src/test/resources/has_java_step_def.story");
- JBehaveStep step = (JBehaveStep) getFixture().getFile().findElementAt(getFixture().getCaretOffset()).getParent();
+ JBehaveStep step = (JBehaveStep) getParentOfElementAtCaretIn(getFixture().getFile());
var stepDefinitions = JBehaveStepsIndex.getInstance(getFixture().getProject()).findStepDefinitions(step);
assertThat(stepDefinitions).isEmpty();
diff --git a/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveUtilContentsTest.java b/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveUtilContentsTest.java
index d60bf9c..a63ed6e 100644
--- a/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveUtilContentsTest.java
+++ b/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveUtilContentsTest.java
@@ -4,14 +4,12 @@
import com.github.kumaraman21.intellijbehave.ContentEntryTestBase;
import com.intellij.psi.search.GlobalSearchScope;
-import com.intellij.testFramework.junit5.RunInEdt;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Test;
/**
* Integration test for {@link JBehaveUtil}.
*/
-@RunInEdt
class JBehaveUtilContentsTest extends ContentEntryTestBase {
@Nullable
@@ -24,9 +22,10 @@ protected String getTestDataPath() {
@Test
void shouldContinueReferenceSearchForEmptyBiggestWord() {
+ copySrcDirectoryToProject();
var stepDefFile = getFixture().configureByFile("main/java/StepDefs.java");
- var stepDefMethod = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var stepDefMethod = getParentOfElementAtCaretIn(stepDefFile);
boolean findRef = JBehaveUtil.findJBehaveReferencesToElement(
stepDefMethod,
@@ -38,10 +37,11 @@ void shouldContinueReferenceSearchForEmptyBiggestWord() {
@Test
void shouldContinueReferenceSearchForValidMethod() {
+ copySrcDirectoryToProject();
getFixture().copyFileToProject("src/test/resources/reference.story");
var stepDefFile = getFixture().configureByFile("main/java/StepDefs.java");
- var stepDefMethod = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var stepDefMethod = getParentOfElementAtCaretIn(stepDefFile);
boolean findRef = JBehaveUtil.findJBehaveReferencesToElement(
stepDefMethod,
@@ -53,10 +53,11 @@ void shouldContinueReferenceSearchForValidMethod() {
@Test
void shouldNotContinueReferenceSearchForValidMethodWithFalseConsumer() {
+ copySrcDirectoryToProject();
getFixture().copyFileToProject("src/test/resources/reference.story");
var stepDefFile = getFixture().configureByFile("main/java/StepDefs.java");
- var stepDefMethod = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var stepDefMethod = getParentOfElementAtCaretIn(stepDefFile);
boolean findRef = JBehaveUtil.findJBehaveReferencesToElement(
stepDefMethod,
@@ -68,10 +69,11 @@ void shouldNotContinueReferenceSearchForValidMethodWithFalseConsumer() {
@Test
void shouldContinueReferenceSearchForMethodWithNoReference() {
+ copySrcDirectoryToProject();
getFixture().copyFileToProject("src/test/resources/reference.story");
var stepDefFile = getFixture().configureByFile("main/java/OtherStepDefs.java");
- var stepDefMethod = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var stepDefMethod = getParentOfElementAtCaretIn(stepDefFile);
boolean findRef = JBehaveUtil.findJBehaveReferencesToElement(
stepDefMethod,
diff --git a/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveUtilTest.java b/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveUtilTest.java
index 6c44329..ae2cb49 100644
--- a/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveUtilTest.java
+++ b/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveUtilTest.java
@@ -1,12 +1,12 @@
package com.github.kumaraman21.intellijbehave.service;
+import static com.intellij.openapi.application.ReadAction.compute;
import static org.assertj.core.api.Assertions.assertThat;
import com.github.kumaraman21.intellijbehave.JBehaveSupportTestBase;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.util.PsiTreeUtil;
-import com.intellij.testFramework.junit5.RunInEdt;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.When;
import org.jetbrains.annotations.Nullable;
@@ -17,7 +17,6 @@
/**
* Integration test for {@link JBehaveUtil}.
*/
-@RunInEdt
class JBehaveUtilTest extends JBehaveSupportTestBase {
@Nullable
@Override
@@ -39,7 +38,7 @@ void stepDefMethod() {
}
""");
- var annotation = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(annotation).isInstanceOf(PsiAnnotation.class);
assertThat(JBehaveUtil.isJBehaveStepAnnotation((PsiAnnotation) annotation)).isTrue();
@@ -57,7 +56,7 @@ void stepDefMethod() {
}
""");
- var annotation = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(annotation).isInstanceOf(PsiAnnotation.class);
assertThat(JBehaveUtil.isJBehaveStepAnnotation((PsiAnnotation) annotation)).isFalse();
@@ -73,7 +72,7 @@ void stepDefMethod() {
}
""");
- var annotation = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(annotation).isInstanceOf(PsiAnnotation.class);
assertThat(JBehaveUtil.isJBehaveStepAnnotation((PsiAnnotation) annotation)).isFalse();
@@ -93,7 +92,7 @@ void stepDefMethod() {
}
""");
- var annotation = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(annotation).isInstanceOf(PsiAnnotation.class);
assertThat(JBehaveUtil.isAnnotationOfClass((PsiAnnotation) annotation, Given.class)).isTrue();
}
@@ -110,7 +109,7 @@ void stepDefMethod() {
}
""");
- var annotation = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(annotation).isInstanceOf(PsiAnnotation.class);
assertThat(JBehaveUtil.isAnnotationOfClass((PsiAnnotation) annotation, When.class)).isFalse();
}
@@ -125,7 +124,7 @@ void stepDefMethod() {
}
""");
- var annotation = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(annotation).isInstanceOf(PsiAnnotation.class);
assertThat(JBehaveUtil.isAnnotationOfClass((PsiAnnotation) annotation, When.class)).isFalse();
}
@@ -144,7 +143,7 @@ class StepDefinitionMethod {
}
""");
- var method = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var method = getParentOfElementAtCaretIn(stepDefFile);
assertThat(method).isInstanceOf(PsiMethod.class);
assertThat(JBehaveUtil.isStepDefinition((PsiMethod) method)).isTrue();
}
@@ -158,7 +157,7 @@ class StepDefinitionMethod {
}
""");
- var method = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var method = getParentOfElementAtCaretIn(stepDefFile);
assertThat(method).isInstanceOf(PsiMethod.class);
assertThat(JBehaveUtil.isStepDefinition((PsiMethod) method)).isFalse();
}
@@ -175,7 +174,7 @@ class StepDefinitionMethod {
}
""");
- var method = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var method = getParentOfElementAtCaretIn(stepDefFile);
assertThat(method).isInstanceOf(PsiMethod.class);
assertThat(JBehaveUtil.isStepDefinition((PsiMethod) method)).isFalse();
}
@@ -194,7 +193,7 @@ void stepDefMethod(int price) {
}
""");
- var annotation = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(annotation).isInstanceOf(PsiAnnotation.class);
assertThat(JBehaveUtil.getAnnotationTexts((PsiAnnotation) annotation, null)).isEmpty();
}
@@ -211,7 +210,7 @@ void stepDefMethod(int price) {
}
""");
- var annotation = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(annotation).isInstanceOf(PsiAnnotation.class);
assertThat(JBehaveUtil.getAnnotationTexts((PsiAnnotation) annotation, null)).containsExactlyInAnyOrder(
"the price of the product should be $price",
@@ -232,7 +231,7 @@ void stepDefMethod(int price) {
}
""");
- var annotation = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(annotation).isInstanceOf(PsiAnnotation.class);
assertThat(JBehaveUtil.getAnnotationTexts((PsiAnnotation) annotation, PsiTreeUtil.getParentOfType(annotation, PsiMethod.class)))
.containsExactlyInAnyOrder(
@@ -258,7 +257,7 @@ void stepDefMethod(int price) {
}
""");
- var annotation = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(annotation).isInstanceOf(PsiAnnotation.class);
assertThat(JBehaveUtil.getAnnotationTexts((PsiAnnotation) annotation, PsiTreeUtil.getParentOfType(annotation, PsiMethod.class)))
.containsExactlyInAnyOrder(
@@ -286,7 +285,7 @@ void stepDefMethod(int price) {
}
""");
- var annotation = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(annotation).isInstanceOf(PsiAnnotation.class);
assertThat(JBehaveUtil.getAnnotationTexts((PsiAnnotation) annotation, null)).containsExactlyInAnyOrder(
"the product should worth $price",
@@ -311,7 +310,7 @@ class AnnotationTexts {
}
""");
- var method = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var method = getParentOfElementAtCaretIn(stepDefFile);
assertThat(method).isInstanceOf(PsiMethod.class);
assertThat(JBehaveUtil.getAnnotationTexts((PsiMethod) method)).isEmpty();
}
@@ -328,7 +327,7 @@ class AnnotationTexts {
}
""");
- var method = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var method = getParentOfElementAtCaretIn(stepDefFile);
assertThat(method).isInstanceOf(PsiMethod.class);
assertThat(JBehaveUtil.getAnnotationTexts((PsiMethod) method)).containsExactlyInAnyOrder(
"the price of the product should be $price",
@@ -349,7 +348,7 @@ class AnnotationTexts {
}
""");
- var method = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var method = getParentOfElementAtCaretIn(stepDefFile);
assertThat(method).isInstanceOf(PsiMethod.class);
assertThat(JBehaveUtil.getAnnotationTexts((PsiMethod) method)).containsExactlyInAnyOrder(
"the price of the product should be $price",
@@ -374,7 +373,7 @@ class AnnotationTexts {
}
""");
- var method = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var method = getParentOfElementAtCaretIn(stepDefFile);
assertThat(method).isInstanceOf(PsiMethod.class);
assertThat(JBehaveUtil.getAnnotationTexts((PsiMethod) method)).containsExactlyInAnyOrder(
"the price of the product should be $price",
@@ -386,6 +385,7 @@ class AnnotationTexts {
@Test
void shouldGetTextsForMethodWithAliasAndAliases() {
+
var stepDefFile = getFixture().configureByText("AnnotationTexts.java", """
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.Alias;
@@ -401,7 +401,7 @@ class AnnotationTexts {
}
""");
- var method = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var method = getParentOfElementAtCaretIn(stepDefFile);
assertThat(method).isInstanceOf(PsiMethod.class);
assertThat(JBehaveUtil.getAnnotationTexts((PsiMethod) method)).containsExactlyInAnyOrder(
"the product should worth $price",
@@ -426,7 +426,7 @@ void stepDefMethod(int price) {
}
""");
- var annotation = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(annotation).isInstanceOf(PsiAnnotation.class);
assertThat(JBehaveUtil.getAnnotationPriority((PsiAnnotation) annotation)).isEqualTo(0);
}
@@ -443,7 +443,7 @@ void stepDefMethod(int price) {
}
""");
- var annotation = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(annotation).isInstanceOf(PsiAnnotation.class);
assertThat(JBehaveUtil.getAnnotationPriority((PsiAnnotation) annotation)).isEqualTo(30);
}
@@ -460,7 +460,7 @@ void stepDefMethod(int price) {
}
""");
- var annotation = stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(annotation).isInstanceOf(PsiAnnotation.class);
assertThat(JBehaveUtil.getAnnotationPriority((PsiAnnotation) annotation)).isEqualTo(-1);
}
diff --git a/src/test/java/com/github/kumaraman21/intellijbehave/service/JavaStepDefinitionTest.java b/src/test/java/com/github/kumaraman21/intellijbehave/service/JavaStepDefinitionTest.java
index 8d35b01..4491416 100644
--- a/src/test/java/com/github/kumaraman21/intellijbehave/service/JavaStepDefinitionTest.java
+++ b/src/test/java/com/github/kumaraman21/intellijbehave/service/JavaStepDefinitionTest.java
@@ -1,12 +1,11 @@
package com.github.kumaraman21.intellijbehave.service;
+import static com.intellij.openapi.application.ReadAction.compute;
import static org.assertj.core.api.Assertions.assertThat;
import com.github.kumaraman21.intellijbehave.JBehaveSupportTestBase;
import com.github.kumaraman21.intellijbehave.parser.JBehaveStep;
import com.intellij.psi.PsiAnnotation;
-import com.intellij.psi.PsiMethod;
-import com.intellij.testFramework.junit5.RunInEdt;
import org.jbehave.core.steps.StepType;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Test;
@@ -14,7 +13,6 @@
/**
* Integration test for {@link JavaStepDefinition}.
*/
-@RunInEdt
class JavaStepDefinitionTest extends JBehaveSupportTestBase {
@Nullable
@@ -29,7 +27,7 @@ protected String getTestDataPath() {
void shouldMatchStepText() {
var stepDefFile = getFixture().configureByText("JavaStepDefinition.java", """
import org.jbehave.core.annotations.Then;
-
+
class JavaStepDefinition {
@Then(value = "the price should be $price", priority = 500)
void steDefMethod(int price) {
@@ -37,15 +35,15 @@ void steDefMethod(int price) {
}
""");
- var annotation = (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
var storyFile = getFixture().configureByText("matches_step_text.story", """
Scenario: Product price
-
+
Then the price should be 200
""");
- var step = (JBehaveStep) storyFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var step = (JBehaveStep) getParentOfElementAtCaretIn(storyFile);
assertThat(new JavaStepDefinition(annotation).supportsStepAndMatches(step, "the price should be 200")).isTrue();
}
@@ -54,7 +52,7 @@ void steDefMethod(int price) {
void shouldNotMatchStepText() {
var stepDefFile = getFixture().configureByText("JavaStepDefinition.java", """
import org.jbehave.core.annotations.Then;
-
+
class JavaStepDefinition {
@Then(value = "the price should be $price", priority = 500)
void steDefMethod(int price) {
@@ -62,15 +60,15 @@ void steDefMethod(int price) {
}
""");
- var annotation = (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
var storyFile = getFixture().configureByText("matches_step_text.story", """
Scenario: Product price
-
+
Then the price should be 200
""");
- var step = (JBehaveStep) storyFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var step = (JBehaveStep) getParentOfElementAtCaretIn(storyFile);
assertThat(new JavaStepDefinition(annotation).supportsStepAndMatches(step, "the price is 200")).isFalse();
}
@@ -79,7 +77,7 @@ void steDefMethod(int price) {
void shouldSupportStep() {
var stepDefFile = getFixture().configureByText("JavaStepDefinition.java", """
import org.jbehave.core.annotations.Then;
-
+
class JavaStepDefinition {
@Then(value = "the price should be $price", priority = 500)
void steDefMethod(int price) {
@@ -87,15 +85,15 @@ void steDefMethod(int price) {
}
""");
- var annotation = (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
var storyFile = getFixture().configureByText("supports_step.story", """
Scenario: Product price
-
+
Then the price should be 200
""");
- var step = (JBehaveStep) storyFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var step = (JBehaveStep) getParentOfElementAtCaretIn(storyFile);
assertThat(new JavaStepDefinition(annotation).supportsStepAndMatches(step, "the price should be 200")).isTrue();
}
@@ -104,7 +102,7 @@ void steDefMethod(int price) {
void shouldNotSupportStep() {
var stepDefFile = getFixture().configureByText("JavaStepDefinition.java", """
import org.jbehave.core.annotations.Given;
-
+
class JavaStepDefinition {
@Given(value = "the price should be $price", priority = 500)
void steDefMethod(int price) {
@@ -112,15 +110,15 @@ void steDefMethod(int price) {
}
""");
- var annotation = (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
var storyFile = getFixture().configureByText("supports_step.story", """
Scenario: Product price
-
+
Then the price should be 200
""");
- var step = (JBehaveStep) storyFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var step = (JBehaveStep) getParentOfElementAtCaretIn(storyFile);
assertThat(new JavaStepDefinition(annotation).supportsStepAndMatches(step, "the price should be 200")).isFalse();
}
@@ -129,7 +127,7 @@ void steDefMethod(int price) {
void shouldNotSupportStepForAliasAnnotation() {
var stepDefFile = getFixture().configureByText("JavaStepDefinition.java", """
import org.jbehave.core.annotations.Aliases;
-
+
class JavaStepDefinition {
@Aliases(values = {
"the price should be $price",
@@ -140,15 +138,15 @@ void steDefMethod(int price) {
}
""");
- var annotation = (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
var storyFile = getFixture().configureByText("supports_step.story", """
Scenario: Product price
-
+
Then the price should be 200
""");
- var step = (JBehaveStep) storyFile.findElementAt(getFixture().getCaretOffset()).getParent();
+ var step = (JBehaveStep) getParentOfElementAtCaretIn(storyFile);
assertThat(new JavaStepDefinition(annotation).supportsStepAndMatches(step, "the price should be 200")).isFalse();
}
@@ -159,7 +157,7 @@ void steDefMethod(int price) {
void shouldGetAnnotationTextWhenThereIsOneSuchText() {
var stepDefFile = getFixture().configureByText("JavaStepDefinition.java", """
import org.jbehave.core.annotations.Alias;
-
+
class JavaStepDefinition {
@Alias("the price should be $price")
void steDefMethod(int price) {
@@ -167,7 +165,7 @@ void steDefMethod(int price) {
}
""");
- var annotation = (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(new JavaStepDefinition(annotation).getAnnotationTextFor("the price should be 200"))
.isEqualTo("the price should be $price");
}
@@ -176,7 +174,7 @@ void steDefMethod(int price) {
void shouldGetFirstMatchingAnnotationTextFromMultiple() {
var stepDefFile = getFixture().configureByText("JavaStepDefinition.java", """
import org.jbehave.core.annotations.Aliases;
-
+
class JavaStepDefinition {
@Aliases(values = {
"the price should be $price",
@@ -187,7 +185,7 @@ void steDefMethod(int price) {
}
""");
- var annotation = (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(new JavaStepDefinition(annotation).getAnnotationTextFor("the cost should be 200"))
.isEqualTo("the cost should be $price");
}
@@ -196,7 +194,7 @@ void steDefMethod(int price) {
void shouldReturnNoAnnotationTextWhenNotMatching() {
var stepDefFile = getFixture().configureByText("JavaStepDefinition.java", """
import org.jbehave.core.annotations.Alias;
-
+
class JavaStepDefinition {
@Aliases(values = {
"the price should be $price",
@@ -207,7 +205,7 @@ void steDefMethod(int price) {
}
""");
- var annotation = (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(new JavaStepDefinition(annotation).getAnnotationTextFor("non matching text")).isNull();
}
@@ -217,7 +215,7 @@ void steDefMethod(int price) {
void shouldReturnTheAnnotatedMethod() {
var stepDefFile = getFixture().configureByText("JavaStepDefinition.java", """
import org.jbehave.core.annotations.Then;
-
+
class JavaStepDefinition {
@Then("the price should be $price")
void steDefMethod(int price) {
@@ -225,21 +223,21 @@ void steDefMethod(int price) {
}
""");
- var annotation = (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
- assertThat(new JavaStepDefinition(annotation).getAnnotatedMethod()).extracting(PsiMethod::getName).isEqualTo("steDefMethod");
+ var annotation = compute(() -> (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
+ assertThat(new JavaStepDefinition(annotation).getAnnotatedMethod()).extracting(method -> compute(method::getName)).isEqualTo("steDefMethod");
}
@Test
void shouldReturnNullWhenThereIsNoParentMethod() {
var stepDefFile = getFixture().configureByText("JavaStepDefinition.java", """
import org.jbehave.core.annotations.Then;
-
+
class JavaStepDefinition {
@Then("the price should be $price")
}
""");
- var annotation = (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(new JavaStepDefinition(annotation).getAnnotatedMethod()).isNull();
}
@@ -249,7 +247,7 @@ class JavaStepDefinition {
void shouldGetAnnotationType() {
var stepDefFile = getFixture().configureByText("JavaStepDefinition.java", """
import org.jbehave.core.annotations.Then;
-
+
class JavaStepDefinition {
@Then("the price should be $price")
void steDefMethod(int price) {
@@ -257,7 +255,7 @@ void steDefMethod(int price) {
}
""");
- var annotation = (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(new JavaStepDefinition(annotation).getAnnotationType()).isEqualTo(StepType.THEN);
}
@@ -265,7 +263,7 @@ void steDefMethod(int price) {
void shouldReturnNullForNonMappedAnnotationType() {
var stepDefFile = getFixture().configureByText("JavaStepDefinition.java", """
import org.jbehave.core.annotations.Alias;
-
+
class JavaStepDefinition {
@Alias("the price should be $price")
void steDefMethod(int price) {
@@ -273,7 +271,7 @@ void steDefMethod(int price) {
}
""");
- var annotation = (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(new JavaStepDefinition(annotation).getAnnotationType()).isNull();
}
@@ -287,7 +285,7 @@ void steDefMethod(int price) {
void shouldGetAnnotationPriority() {
var stepDefFile = getFixture().configureByText("JavaStepDefinition.java", """
import org.jbehave.core.annotations.Then;
-
+
class JavaStepDefinition {
@Then(value = "the price should be $price", priority = 500)
void steDefMethod(int price) {
@@ -295,7 +293,7 @@ void steDefMethod(int price) {
}
""");
- var annotation = (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent();
+ var annotation = compute(() -> (PsiAnnotation) stepDefFile.findElementAt(getFixture().getCaretOffset()).getParent().getParent());
assertThat(new JavaStepDefinition(annotation).getAnnotationPriority()).isEqualTo(500);
}