Skip to content

Implement HookDefinition.getHookType and unimplement Location.getLocation #402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ See also the [CHANGELOG](https://github.com/cucumber/cucumber-jvm/blob/master/CH

### Changed

- [Internal] Implement `HookDefinition.getHookType` and unimplement `Location.getLocation`. No impact expected for users.

### Deprecated

### Removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ private[scala] trait HookDsl extends BaseScalaDsl {
}

def apply(body: Scenario => Unit): Unit = {
val details = ScalaHookDetails(tagExpression, order, body, frame)
val details =
ScalaHookDetails(tagExpression, order, body, frame, hookType)
registry.registerDynamicHook(hookType, details)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.cucumber.scala

import io.cucumber.core.backend.{HookDefinition, ScenarioScoped, TestCaseState}
import io.cucumber.scala.ScopedHookType.{AFTER, AFTER_STEP, BEFORE, BEFORE_STEP}

import java.util.Optional
import scala.annotation.nowarn

trait ScalaHookDefinition extends HookDefinition with AbstractGlueDefinition {
Expand All @@ -18,6 +20,16 @@ trait ScalaHookDefinition extends HookDefinition with AbstractGlueDefinition {

override def getOrder: Int = hookDetails.order

override def getHookType: Optional[HookDefinition.HookType] = {
val javaHookType = hookDetails.hookType match {
case BEFORE => HookDefinition.HookType.BEFORE
case AFTER => HookDefinition.HookType.AFTER
case BEFORE_STEP => HookDefinition.HookType.BEFORE_STEP
case AFTER_STEP => HookDefinition.HookType.AFTER_STEP
}
Optional.of(javaHookType)
}

}

object ScalaHookDefinition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ case class ScalaHookDetails(
tagExpression: String,
order: Int,
body: HookDefinitionBody,
stackTraceElement: StackTraceElement
stackTraceElement: StackTraceElement,
hookType: ScopedHookType
)
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ trait ScalaStepDefinition extends StepDefinition with AbstractGlueDefinition {

override def getPattern: String = stepDetails.pattern

// Easier to just print out fileName and lineNumber
override def getLocation(): String =
stepDetails.frame.getFileName + ":" + stepDetails.frame.getLineNumber

}

object ScalaStepDefinition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class ScalaDslStepsTest {
check: => Boolean
): Unit = {
assertEquals(pattern, stepDefinition.getPattern)
assertEquals(location, stepDefinition.getLocation)
assertTrue(stepDefinition.getLocation.contains(location))
stepDefinition.execute(args)
assertTrue(check)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class ScalaDslStepsTest {
check: => Boolean
): Unit = {
assertEquals(pattern, stepDefinition.getPattern)
assertEquals(location, stepDefinition.getLocation)
assertTrue(stepDefinition.getLocation.contains(location))
stepDefinition.execute(args)
assertTrue(check)
}
Expand Down
Loading