diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fdccd188..9ecc8380 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,44 +1,61 @@ +# GitHub Actions Workflow is created for testing and preparing the plugin release in the following steps: +# - Validate Gradle Wrapper. +# - Run 'test' and 'verifyPlugin' tasks. +# - Run Qodana inspections. +# - Run the 'buildPlugin' task and prepare artifact for further tests. +# - Run the 'runPluginVerifier' task. +# - Create a draft release. +# +# The workflow is triggered on push and pull_request events. +# +# GitHub Actions reference: https://help.github.com/en/actions +# +## JBIJPPTPL + name: Build on: - # Trigger the workflow on pushes to only the 'main' branch (this avoids duplicate checks being run e.g. for dependabot pull requests) + # Trigger the workflow on pushes to only the 'main' branch (this avoids duplicate checks being run e.g., for dependabot pull requests) push: - branches: [master] + branches: [ master ] # Trigger the workflow on any pull request pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + jobs: - # Run Gradle Wrapper Validation Action to verify the wrapper's checksum - # Run verifyPlugin, IntelliJ Plugin Verifier, and test Gradle tasks - # Build plugin and provide the artifact for the next workflow jobs + # Prepare environment and build the plugin build: name: Build runs-on: ubuntu-latest outputs: version: ${{ steps.properties.outputs.version }} + changelog: ${{ steps.properties.outputs.changelog }} + pluginVerifierHomeDir: ${{ steps.properties.outputs.pluginVerifierHomeDir }} steps: - # Free GitHub Actions Environment Disk Space - - name: Maximize Build Space - run: | - sudo rm -rf /usr/share/dotnet - sudo rm -rf /usr/local/lib/android - sudo rm -rf /opt/ghc - - # Check out current repository + # Check out the current repository - name: Fetch Sources - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Validate wrapper - name: Gradle Wrapper Validation - uses: gradle/wrapper-validation-action@v1.0.5 + uses: gradle/actions/wrapper-validation@v3 - # Setup Java 11 environment for the next steps + # Set up Java environment for the next steps - name: Setup Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: zulu - java-version: 11 + java-version: 17 + + # Setup Gradle + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + gradle-home-cache-cleanup: true # Set environment variables - name: Export Properties @@ -47,16 +64,64 @@ jobs: run: | PROPERTIES="$(./gradlew properties --console=plain -q)" VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')" - NAME="$(echo "$PROPERTIES" | grep "^pluginName:" | cut -f2- -d ' ')" - echo "::set-output name=version::$VERSION" - echo "::set-output name=name::$NAME" - echo "::set-output name=pluginVerifierHomeDir::~/.pluginVerifier" + CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)" + + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "pluginVerifierHomeDir=~/.pluginVerifier" >> $GITHUB_OUTPUT + + echo "changelog<> $GITHUB_OUTPUT + echo "$CHANGELOG" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT - ./gradlew listProductsReleases # prepare list of IDEs for Plugin Verifier + # Build plugin + - name: Build plugin + run: ./gradlew buildPlugin + + # Prepare plugin archive content for creating artifact + - name: Prepare Plugin Artifact + id: artifact + shell: bash + run: | + cd ${{ github.workspace }}/build/distributions + FILENAME=`ls *.zip` + unzip "$FILENAME" -d content + + echo "filename=${FILENAME:0:-4}" >> $GITHUB_OUTPUT + + # Store already-built plugin as an artifact for downloading + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ steps.artifact.outputs.filename }} + path: ./build/distributions/content/*/* + + # Run tests and upload a code coverage report + test: + name: Test + needs: [ build ] + runs-on: ubuntu-latest + steps: + + # Check out the current repository + - name: Fetch Sources + uses: actions/checkout@v4 + + # Set up Java environment for the next steps + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: 17 + + # Setup Gradle + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + gradle-home-cache-cleanup: true # Run tests - - name: Run JUnit 5 Tests - run: ./gradlew test -Pidea.home.path=./intellij-community + - name: Run Tests + run: ./gradlew check # Run tests - name: Run JUnit 3 Tests @@ -65,44 +130,63 @@ jobs: # Collect Tests Result of failed tests - name: Collect Tests Result if: ${{ failure() }} - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: 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 + needs: [ build ] + runs-on: ubuntu-latest + steps: + + # Free GitHub Actions Environment Disk Space + - name: Maximize Build Space + uses: jlumbroso/free-disk-space@main + with: + tool-cache: false + large-packages: false + + # Check out the current repository + - name: Fetch Sources + uses: actions/checkout@v4 + + # Set up Java environment for the next steps + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: 17 + + # Setup Gradle + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + gradle-home-cache-cleanup: true + # Cache Plugin Verifier IDEs - name: Setup Plugin Verifier IDEs Cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: - path: ${{ steps.properties.outputs.pluginVerifierHomeDir }}/ides + path: ${{ needs.build.outputs.pluginVerifierHomeDir }}/ides key: plugin-verifier-${{ hashFiles('build/listProductsReleases.txt') }} # Run Verify Plugin task and IntelliJ Plugin Verifier tool - name: Run Plugin Verification tasks - run: ./gradlew runPluginVerifier -Pplugin.verifier.home.dir=${{ steps.properties.outputs.pluginVerifierHomeDir }} + run: ./gradlew verifyPlugin -Dplugin.verifier.home.dir=${{ needs.build.outputs.pluginVerifierHomeDir }} # Collect Plugin Verifier Result - name: Collect Plugin Verifier Result if: ${{ always() }} - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: pluginVerifier-result path: ${{ github.workspace }}/build/reports/pluginVerifier - - # Prepare plugin archive content for creating artifact - - name: Prepare Plugin Artifact - id: artifact - shell: bash - run: | - cd ${{ github.workspace }}/build/distributions - FILENAME=`ls *.zip` - unzip "$FILENAME" -d content - - echo "::set-output name=filename::${FILENAME:0:-4}" - - # Store already-built plugin as an artifact for downloading - - name: Upload artifact - uses: actions/upload-artifact@v3 - with: - name: ${{ steps.artifact.outputs.filename }} - path: ./build/distributions/content/*/* diff --git a/CHANGELOG.md b/CHANGELOG.md index 35906430..57e75e98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## [Unreleased] +## [1.66.0] +### Changed +- New supported IDE version range: 2023.2.8 - 2024.2.0.2 +- Added code documentation to a handful of Kotlin step definitions related classes. + ## [1.65.0] ### Changed - Added caching for the JBehave step reference resolution and Given-When-Then step annotation lookup. diff --git a/build.gradle.kts b/build.gradle.kts index 2013d3ec..29c6b6b1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -26,13 +26,13 @@ kotlin { dependencies { //https://kotlinlang.org/docs/reflection.html#jvm-dependency - implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.23") + implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.25") implementation("org.jbehave:jbehave-core:5.2.0") - testImplementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.23") + testImplementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.25") testImplementation("org.assertj:assertj-core:3.25.3") - testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.2") - testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.2") + 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 @@ -96,10 +96,6 @@ tasks { 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") } - -// runPluginVerifier { -// ideVersions.set(listOf("IC-232.7754.73")) -// } } tasks.register("testWithJunit3") { diff --git a/gradle.properties b/gradle.properties index 5e1e4d9d..e1d83e0e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,22 +4,23 @@ pluginGroup = com.github.kumaraman21.intellijbehave pluginName = JBehave Support pluginRepositoryUrl = https://github.com/witspirit/IntelliJBehave # SemVer format -> https://semver.org -pluginVersion = 1.65.0 +pluginVersion = 1.66.0 # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html -pluginSinceBuild = 231.9414.13 -pluginUntilBuild = 242.* +pluginSinceBuild = 232.10335.12 +# 2024.2.0.2 +pluginUntilBuild = 242.20224.419 # IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension platformType = IC -platformVersion = 2023.1.6 +platformVersion = 2023.2.8 # 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 = java,Kotlin # Gradle Releases -> https://github.com/gradle/gradle/releases -gradleVersion = 8.6 +gradleVersion = 8.9 # Opt-out flag for bundling Kotlin standard library -> https://jb.gg/intellij-platform-kotlin-stdlib kotlin.stdlib.default.dependency = false diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a80b22ce..09523c0e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew.bat b/gradlew.bat index 6689b85b..7101f8e4 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/psi/NavigableKotlinPsiAnnotation.kt b/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/psi/NavigableKotlinPsiAnnotation.kt index 7b059149..2b5bf999 100644 --- a/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/psi/NavigableKotlinPsiAnnotation.kt +++ b/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/psi/NavigableKotlinPsiAnnotation.kt @@ -5,6 +5,9 @@ import com.intellij.psi.PsiElement import org.jetbrains.kotlin.psi.KtElement /** + * Represents a Kotlin PSI annotation with its PSI and Kotlin element counterparts. + * This type also provides (overrides) some of the navigation behaviours from its parent class. + * * Created by Rodrigo Quesada on 20/09/15. */ class NavigableKotlinPsiAnnotation( diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/psi/NavigableKotlinPsiElement.kt b/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/psi/NavigableKotlinPsiElement.kt index 0c8135dd..b84f2dd4 100644 --- a/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/psi/NavigableKotlinPsiElement.kt +++ b/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/psi/NavigableKotlinPsiElement.kt @@ -6,6 +6,9 @@ import com.intellij.psi.PsiMethod import org.jetbrains.kotlin.psi.KtElement /** + * Represents a Kotlin PSI element with its PSI and Kotlin element counterparts. + * This type also provides (overrides) some of the navigation behaviours from its parent class. + * * Created by Rodrigo Quesada on 20/09/15. */ open class NavigableKotlinPsiElement( @@ -15,6 +18,9 @@ open class NavigableKotlinPsiElement( override fun getTextOffset(): Int = ktElement.textOffset + /** + * Returns the parent element as one of the custom `NavigableKotlin*` element types. + */ override fun getParent(): PsiElement { val psiParent = psiElement.parent val ktParent = ktElement.parent diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/psi/NavigableKotlinPsiMethod.kt b/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/psi/NavigableKotlinPsiMethod.kt index 33c56b8c..4f0b83a7 100644 --- a/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/psi/NavigableKotlinPsiMethod.kt +++ b/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/psi/NavigableKotlinPsiMethod.kt @@ -5,6 +5,9 @@ import com.intellij.psi.PsiMethod import org.jetbrains.kotlin.psi.KtElement /** + * Represents a Kotlin PSI method with its PSI and Kotlin element counterparts. + * This type also provides (overrides) some of the navigation behaviours from its parent class. + * * Created by Rodrigo Quesada on 20/09/15. */ class NavigableKotlinPsiMethod( 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 792fe91b..b5c8a315 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 @@ -15,6 +15,15 @@ import org.jetbrains.kotlin.psi.KtFunction class KotlinAnnotationsLoader private constructor() { companion object { + /** + * Returns all occurrences of the step annotation referenced by [qualifiedName] in Kotlin files, in the given [scope]. + * + * @param qualifiedName a step annotation, e.g. `@org.jbehave.core.annotations.Given` + * @param project the current project + * @param scope the search scope where to look up the annotation usage + * + * @see com.github.kumaraman21.intellijbehave.service.JBehaveStepsIndex.getAllStepAnnotations + */ @JvmStatic fun getAnnotations(qualifiedName: QualifiedName, project: Project, scope: GlobalSearchScope): Collection { val name = qualifiedName.lastComponent diff --git a/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/support/services/KotlinPsiClassesHandler.kt b/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/support/services/KotlinPsiClassesHandler.kt index 678fbce4..50d91ebd 100644 --- a/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/support/services/KotlinPsiClassesHandler.kt +++ b/src/main/java/com/github/kumaraman21/intellijbehave/kotlin/support/services/KotlinPsiClassesHandler.kt @@ -10,11 +10,16 @@ import org.jetbrains.kotlin.psi.KtFile import kotlin.jvm.internal.Ref.BooleanRef /** + * Provides utilities for working with and processing Kotlin files and class. + * * Created by Rodrigo Quesada on 20/09/15. */ class KotlinPsiClassesHandler private constructor() { companion object { + /** + * Returns the classes in [psiFile] if it is a Kotlin files, otherwise returns null. + */ @JvmStatic fun getPsiClasses(psiFile: PsiFile): Array? = if (psiFile is KtFile) { psiFile.classes @@ -23,6 +28,12 @@ class KotlinPsiClassesHandler private constructor() { @JvmStatic fun isKotlinFile(psiFile: PsiFile): Boolean = psiFile is KtFile + /** + * Returns if the provided Kotlin [file] contains any step definition class, + * meaning at least one class that contains at least one step definition method. + * + * If the file is not a Kotlin file, it returns false. + */ @JvmStatic fun visitClasses(file: PsiFile): Boolean { val hasJBehaveStepDefTestClass = BooleanRef() @@ -41,6 +52,9 @@ class KotlinPsiClassesHandler private constructor() { return hasJBehaveStepDefTestClass.element } + /** + * Returns if any of the functions in the provided Kotlin class is a step definition function. + */ private fun isKotlinJBehaveStepDefClass(aClass: KtClass): Boolean { return !aClass.isEnum() && !aClass.isInterface() && aClass.fqName != null && aClass.body?.functions?.any { it.findAnnotation(FqName("org.jbehave.core.annotations.Given")) != null 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 c148f820..8ec8fda3 100644 --- a/src/main/java/com/github/kumaraman21/intellijbehave/resolver/StepDefinitionIterator.java +++ b/src/main/java/com/github/kumaraman21/intellijbehave/resolver/StepDefinitionIterator.java @@ -71,7 +71,7 @@ public boolean processFile(@NotNull VirtualFile virtualFile) { } /** - * Returns the PSI classes from the provided file and class owner + * Returns the PSI classes from the provided file and class owner. * * @param psiFile the Java or Kotlin step definitions file * @param psiClassOwner {@code psiFile} as a {@link PsiClassOwner} 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 be2616f4..f8968f1a 100644 --- a/src/main/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndex.java +++ b/src/main/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndex.java @@ -23,6 +23,7 @@ import com.intellij.psi.util.QualifiedName; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.VisibleForTesting; import java.util.ArrayList; import java.util.Collection; @@ -102,13 +103,14 @@ private static Integer getPriorityByDefinition(@Nullable JavaStepDefinition defi /** * Collects all {@link PsiAnnotation}s in the given {@code scope} that reference the {@code annClass}. * - * @param annClass the PsiClass representing the {@code @Given}, {@code @When} or {@code @Then} step annotations + * @param annClass the PsiClass representing the {@code @Given}, {@code @When} or {@code @Then} step annotations. * Since the annotation classes doesn't change much, unless e.g. updating the library version, * the same PsiClass instance will be available for the same annotations throughout the IDE session, * thus it should be safe to use it as the cache location */ @NotNull - private static Collection getAllStepAnnotations(@NotNull final PsiClass annClass, @NotNull final GlobalSearchScope scope) { + @VisibleForTesting + static Collection getAllStepAnnotations(@NotNull final PsiClass annClass, @NotNull final GlobalSearchScope scope) { return CachedValuesManager.getCachedValue(annClass, (CachedValueProvider>) () -> { Collection annotations = ReadAction.compute(() -> { Project project = annClass.getProject(); diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 89acd64f..10f79f9c 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 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 05aff1dc..5805331b 100644 --- a/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndexTest.java +++ b/src/test/java/com/github/kumaraman21/intellijbehave/service/JBehaveStepsIndexTest.java @@ -1,10 +1,14 @@ package com.github.kumaraman21.intellijbehave.service; +import static java.util.stream.Collectors.toSet; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import com.github.kumaraman21.intellijbehave.ContentEntryTestBase; import com.github.kumaraman21.intellijbehave.parser.JBehaveStep; +import com.intellij.codeInsight.AnnotationUtil; 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; @@ -64,6 +68,33 @@ void shouldFindsNoStepDefinition() { assertThat(stepDefinitions).isEmpty(); } + //getAllStepAnnotations + + @Test + void shouldFindAllAnnotations() { + getFixture().copyFileToProject("main/java/StepDefs.java"); + getFixture().copyFileToProject("main/java/OtherStepDefs.java"); + getFixture().copyFileToProject("main/kotlin/AnotherStepDefs.kt"); + + 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); + 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")) + .collect(toSet()); + + assertThat(stepTexts).containsExactlyInAnyOrder( + "result ends with $text", + "check result size is $size", + "result list size is $size"); + } + private JBehaveStep getStep() { return (JBehaveStep) getFixture().getFile().findElementAt(getFixture().getCaretOffset()).getParent(); } diff --git a/src/test/testData/stepsindex/src/main/kotlin/AnotherStepDefs.kt b/src/test/testData/stepsindex/src/main/kotlin/AnotherStepDefs.kt new file mode 100644 index 00000000..5c7d010e --- /dev/null +++ b/src/test/testData/stepsindex/src/main/kotlin/AnotherStepDefs.kt @@ -0,0 +1,12 @@ +import org.jbehave.core.annotations.Then +import org.jbehave.core.annotations.Named + +class AnotherStepDefs { + @Then("check result size is \$size") + fun checkSize(@Named("size") size: Int) { + } + + @Then("result ends with \$text") + fun checkEnding(@Named("text") text: Int) { + } +} \ No newline at end of file