diff --git a/examples/calculator-java-cli/pom.xml b/examples/calculator-java-cli/pom.xml
index 1f026bb29c..493a6f4890 100644
--- a/examples/calculator-java-cli/pom.xml
+++ b/examples/calculator-java-cli/pom.xml
@@ -9,7 +9,7 @@
calculator-java-cli
jar
- Examples: Calculator - Annotations - CLI
+ Examples: Calculator - Java - Annotations - CLI
io.cucumber.examples.calculator
diff --git a/examples/calculator-java-junit4/pom.xml b/examples/calculator-java-junit4/pom.xml
index 98c4e651fc..ae7cb1a49a 100644
--- a/examples/calculator-java-junit4/pom.xml
+++ b/examples/calculator-java-junit4/pom.xml
@@ -9,7 +9,7 @@
calculator-java-junit4
jar
- Examples: Calculator - Annotations - Junit4
+ Examples: Calculator - Java - Annotations - Junit4
io.cucumber.examples.calculator
diff --git a/examples/calculator-java-junit5/pom.xml b/examples/calculator-java-junit5/pom.xml
index 2293162cc6..c35b104f07 100644
--- a/examples/calculator-java-junit5/pom.xml
+++ b/examples/calculator-java-junit5/pom.xml
@@ -1,4 +1,5 @@
-
+
4.0.0
@@ -9,10 +10,10 @@
calculator-java-junit5
jar
- Examples: Calculator - Annotations - Junit 5
+ Examples: Calculator - Java - Annotations - Junit 5
- io.cucumber.calculator
+ io.cucumber.examples.calculator
@@ -27,7 +28,7 @@
org.junit
junit-bom
- 5.10.1
+ 5.12.2
pom
import
@@ -38,6 +39,13 @@
pom
import
+
+ org.assertj
+ assertj-bom
+ 3.27.3
+ pom
+ import
+
@@ -57,11 +65,6 @@
junit-platform-suite
test
-
- org.junit.jupiter
- junit-jupiter-api
- test
-
org.junit.platform
junit-platform-console
@@ -72,6 +75,11 @@
jackson-databind
test
+
+ org.assertj
+ assertj-core
+ test
+
@@ -106,14 +114,16 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/examples/calculator-java-junit5/src/test/java/io/cucumber/examples/calculator/DateStepDefinitions.java b/examples/calculator-java-junit5/src/test/java/io/cucumber/examples/calculator/DateStepDefinitions.java
index 4afa561411..7eee81ff73 100644
--- a/examples/calculator-java-junit5/src/test/java/io/cucumber/examples/calculator/DateStepDefinitions.java
+++ b/examples/calculator-java-junit5/src/test/java/io/cucumber/examples/calculator/DateStepDefinitions.java
@@ -6,7 +6,7 @@
import java.util.Date;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
public class DateStepDefinitions {
@@ -25,6 +25,6 @@ public void I_ask_if_date_is_in_the_past(Date date) {
@Then("^the result should be (yes|no)$")
public void the_result_should_be(String expectedResult) {
- assertEquals(expectedResult, result);
+ assertThat(result).isEqualTo(expectedResult);
}
}
diff --git a/examples/calculator-java-junit5/src/test/java/io/cucumber/examples/calculator/RpnCalculatorSteps.java b/examples/calculator-java-junit5/src/test/java/io/cucumber/examples/calculator/RpnCalculatorSteps.java
index 52dcb7031c..af1f313d36 100644
--- a/examples/calculator-java-junit5/src/test/java/io/cucumber/examples/calculator/RpnCalculatorSteps.java
+++ b/examples/calculator-java-junit5/src/test/java/io/cucumber/examples/calculator/RpnCalculatorSteps.java
@@ -11,7 +11,7 @@
import java.util.List;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
public class RpnCalculatorSteps {
@@ -66,7 +66,7 @@ public void I_press(String what) {
@Then("the result is {int}")
public void the_result_is(double expected) {
- assertEquals(expected, calc.value());
+ assertThat(calc.value()).isEqualTo(expected);
}
@Given("the previous entries:")
diff --git a/examples/calculator-java-junit5/src/test/java/io/cucumber/examples/calculator/ShoppingSteps.java b/examples/calculator-java-junit5/src/test/java/io/cucumber/examples/calculator/ShoppingSteps.java
index e171998a6e..84086ae603 100644
--- a/examples/calculator-java-junit5/src/test/java/io/cucumber/examples/calculator/ShoppingSteps.java
+++ b/examples/calculator-java-junit5/src/test/java/io/cucumber/examples/calculator/ShoppingSteps.java
@@ -6,7 +6,7 @@
import java.util.List;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
public class ShoppingSteps {
@@ -28,7 +28,7 @@ public void i_pay(int amount) {
@Then("my change should be {}")
public void my_change_should_be_(int change) {
- assertEquals(-calc.value().intValue(), change);
+ assertThat(-calc.value().intValue()).isEqualTo(change);
}
static class Grocery {
diff --git a/examples/calculator-java-testng/pom.xml b/examples/calculator-java-testng/pom.xml
index b34bdf2531..4e6d3736f4 100644
--- a/examples/calculator-java-testng/pom.xml
+++ b/examples/calculator-java-testng/pom.xml
@@ -9,7 +9,7 @@
calculator-java-testng
jar
- Examples: Calculator - Annotations - TestNG
+ Examples: Calculator - Java - Annotations - TestNG
io.cucumber.examples.calculator
diff --git a/examples/calculator-java8-cli/pom.xml b/examples/calculator-java8-cli/pom.xml
index 346d822ab4..f6c6d1254a 100644
--- a/examples/calculator-java8-cli/pom.xml
+++ b/examples/calculator-java8-cli/pom.xml
@@ -9,7 +9,7 @@
calculator-java8-cli
jar
- Examples: Calculator - Lambda - CLI
+ Examples: Calculator - Java - Lambda - CLI
io.cucumber.examples.calculator
diff --git a/examples/calculator-kotlin-junit5/.gitignore b/examples/calculator-kotlin-junit5/.gitignore
new file mode 100644
index 0000000000..dae4369610
--- /dev/null
+++ b/examples/calculator-kotlin-junit5/.gitignore
@@ -0,0 +1,4 @@
+/.settings
+/.classpath
+/.project
+/test-output/
diff --git a/examples/calculator-kotlin-junit5/pom.xml b/examples/calculator-kotlin-junit5/pom.xml
new file mode 100644
index 0000000000..b7469eb5d9
--- /dev/null
+++ b/examples/calculator-kotlin-junit5/pom.xml
@@ -0,0 +1,158 @@
+
+
+
+ 4.0.0
+
+
+ io.cucumber
+ examples
+ 7.23.0-SNAPSHOT
+
+
+ calculator-kotlin-junit5
+ jar
+ Examples: Calculator - Kotlin - Annotations - Junit 5
+
+
+ official
+ io.cucumber.examples.calculator
+
+
+
+
+
+ io.cucumber
+ cucumber-bom
+ ${project.version}
+ pom
+ import
+
+
+ org.junit
+ junit-bom
+ 5.12.2
+ pom
+ import
+
+
+ org.jetbrains.kotlin
+ kotlin-bom
+ 2.1.21
+ pom
+ import
+
+
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+
+
+ io.cucumber
+ cucumber-java
+ test
+
+
+ io.cucumber
+ cucumber-junit-platform-engine
+ test
+
+
+ org.junit.platform
+ junit-platform-suite
+ test
+
+
+ org.junit.platform
+ junit-platform-console
+ test
+
+
+ org.jetbrains.kotlin
+ kotlin-test
+
+
+
+
+ src/main/kotlin
+ src/test/kotlin
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ 2.1.21
+
+
+ compile
+ compile
+
+ compile
+
+
+
+ test-compile
+ test-compile
+
+ test-compile
+
+
+
+
+
+ maven-failsafe-plugin
+ 3.5.3
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+
+
+ cucumber.junit-platform.naming-strategy=long
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-antrun-plugin
+
+
+
+ cli-test
+ test
+
+ run
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/calculator-kotlin-junit5/src/main/kotlin/io/cucumber/examples/calaculator/DateCalculator.kt b/examples/calculator-kotlin-junit5/src/main/kotlin/io/cucumber/examples/calaculator/DateCalculator.kt
new file mode 100644
index 0000000000..5f3ec14be0
--- /dev/null
+++ b/examples/calculator-kotlin-junit5/src/main/kotlin/io/cucumber/examples/calaculator/DateCalculator.kt
@@ -0,0 +1,12 @@
+package io.cucumber.examples.calaculator
+
+import java.time.LocalDate
+import java.util.*
+
+class DateCalculator(private val now: LocalDate) {
+
+ fun isDateInThePast(date: LocalDate): String {
+ return if (date.isBefore(now)) "yes" else "no"
+ }
+}
+
diff --git a/examples/calculator-kotlin-junit5/src/main/kotlin/io/cucumber/examples/calaculator/RpnCalculator.kt b/examples/calculator-kotlin-junit5/src/main/kotlin/io/cucumber/examples/calaculator/RpnCalculator.kt
new file mode 100644
index 0000000000..d6433bbde2
--- /dev/null
+++ b/examples/calculator-kotlin-junit5/src/main/kotlin/io/cucumber/examples/calaculator/RpnCalculator.kt
@@ -0,0 +1,29 @@
+package io.cucumber.examples.calaculator
+
+class RpnCalculator {
+ private val stack: ArrayDeque = ArrayDeque()
+
+ private val OPS = setOf("+", "-", "*", "/")
+
+ fun push(arg: Any) {
+ if (arg in OPS) {
+ val y = stack.removeLast()
+ val x = if (stack.isEmpty()) 0 else stack.removeLast()
+ val valResult = when (arg) {
+ "-" -> x.toDouble() - y.toDouble()
+ "+" -> x.toDouble() + y.toDouble()
+ "*" -> x.toDouble() * y.toDouble()
+ "/" -> x.toDouble() / y.toDouble()
+ else -> throw IllegalArgumentException("Unknown operation $arg")
+ }
+ push(valResult)
+ } else {
+ stack.addLast(arg as Number)
+ }
+ }
+
+ fun peek(): Number? = stack.lastOrNull()
+
+ fun clear() = stack.clear()
+}
+
diff --git a/examples/calculator-kotlin-junit5/src/test/kotlin/io/cucumber/examples/calculator/DateStepDefinitions.kt b/examples/calculator-kotlin-junit5/src/test/kotlin/io/cucumber/examples/calculator/DateStepDefinitions.kt
new file mode 100644
index 0000000000..538521121b
--- /dev/null
+++ b/examples/calculator-kotlin-junit5/src/test/kotlin/io/cucumber/examples/calculator/DateStepDefinitions.kt
@@ -0,0 +1,36 @@
+package io.cucumber.examples.calculator
+
+import io.cucumber.examples.calaculator.DateCalculator
+import io.cucumber.java.en.Given
+import io.cucumber.java.en.Then
+import io.cucumber.java.en.When
+import java.time.LocalDate
+import java.time.format.DateTimeFormatter
+import java.util.Locale
+import kotlin.test.assertEquals
+
+class DateStepDefinitions {
+
+ private lateinit var result: String
+
+ private lateinit var calculator: DateCalculator
+
+
+ @Given("today is {}")
+ fun todayIs(date: String) {
+ val date1 = LocalDate.parse(date)
+ calculator = DateCalculator(now = date1)
+ }
+
+ @When("I ask if {} is in the past")
+ fun iAskIfDateIsInPast(date: String) {
+ val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("MMM d, yyyy", Locale.ENGLISH)
+ val date2 = LocalDate.parse(date,formatter)
+ result = calculator.isDateInThePast(date2)
+ }
+
+ @Then("the result should be {string}")
+ fun theResultShouldBeYes(answer: String) {
+ assertEquals(answer, result)
+ }
+}
diff --git a/examples/calculator-kotlin-junit5/src/test/kotlin/io/cucumber/examples/calculator/RunCucumberKotlinTest.kt b/examples/calculator-kotlin-junit5/src/test/kotlin/io/cucumber/examples/calculator/RunCucumberKotlinTest.kt
new file mode 100644
index 0000000000..bb3ab9d012
--- /dev/null
+++ b/examples/calculator-kotlin-junit5/src/test/kotlin/io/cucumber/examples/calculator/RunCucumberKotlinTest.kt
@@ -0,0 +1,18 @@
+package io.cucumber.examples.calculator
+
+import io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME
+import org.junit.platform.suite.api.Suite
+import org.junit.platform.suite.api.IncludeEngines
+import org.junit.platform.suite.api.SelectPackages
+import org.junit.platform.suite.api.ConfigurationParameter
+
+/**
+ * Work around. Surefire does not use JUnits Test Engine discovery
+ * functionality. Alternatively execute the
+ * org.junit.platform.console.ConsoleLauncher with the maven-antrun-plugin.
+ */
+@Suite
+@IncludeEngines("cucumber")
+@SelectPackages("io.cucumber.examples.calculator")
+@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "io.cucumber.examples.calculator")
+class RunCucumberKotlinTest
diff --git a/examples/calculator-kotlin-junit5/src/test/kotlin/io/cucumber/examples/calculator/ShoppingStepDefinitions.kt b/examples/calculator-kotlin-junit5/src/test/kotlin/io/cucumber/examples/calculator/ShoppingStepDefinitions.kt
new file mode 100644
index 0000000000..adc5060d1b
--- /dev/null
+++ b/examples/calculator-kotlin-junit5/src/test/kotlin/io/cucumber/examples/calculator/ShoppingStepDefinitions.kt
@@ -0,0 +1,56 @@
+package io.cucumber.examples.calculator
+
+import io.cucumber.datatable.DataTable
+import io.cucumber.examples.calaculator.RpnCalculator
+import io.cucumber.java.DataTableType
+import io.cucumber.java.en.Given
+import io.cucumber.java.en.Then
+import io.cucumber.java.en.When
+import kotlin.test.assertEquals
+
+class ShoppingStepDefinitions {
+ private val rpnCalculator = RpnCalculator()
+ private val groceryList = mutableListOf()
+
+
+
+ @Given("the following groceries")
+ fun givenTheFollowingGroceries(grocery: DataTable){
+ val groceries: List = grocery.asList(Grocery::class.java)
+ groceryList.addAll(groceries)
+ for (gro in groceries){
+ rpnCalculator.push(gro.price.value)
+ rpnCalculator.push("+")
+ }
+ }
+
+ @When("I pay {int}")
+ fun whenIPay(amount: Int) {
+ rpnCalculator.push(amount)
+ rpnCalculator.push("-")
+ }
+
+ @Then("my change should be {int}")
+ fun myChangeShouldBe(change: Int) {
+ rpnCalculator.peek()?.let { assertEquals(change, -it.toInt()) }
+ }
+
+ @DataTableType
+ fun groceryEntry(entry: Map): Grocery {
+ val name = entry["name"] ?: error("Missing name")
+ val price = Price.fromString(entry["price"] ?: error("Missing price"))
+ return Grocery(name, price)
+ }
+
+ data class Grocery(val name: String, val price: Price)
+
+ @JvmInline
+ value class Price(val value: Int) {
+ companion object {
+ fun fromString(value: String): Price {
+ return Price(value.toInt())
+ }
+ }
+ }
+
+}
diff --git a/examples/calculator-kotlin-junit5/src/test/resources/io/cucumber/examples/calculator/date_calculator.feature b/examples/calculator-kotlin-junit5/src/test/resources/io/cucumber/examples/calculator/date_calculator.feature
new file mode 100644
index 0000000000..ed665e833d
--- /dev/null
+++ b/examples/calculator-kotlin-junit5/src/test/resources/io/cucumber/examples/calculator/date_calculator.feature
@@ -0,0 +1,9 @@
+Feature: Dates with different date formats
+ This feature shows you can have different date formats, as long as you annotate the
+ corresponding step definition method accordingly.
+
+ @date
+ Scenario: Determine past date
+ Given today is 2011-01-20
+ When I ask if Jan 19, 2011 is in the past
+ Then the result should be "yes"
diff --git a/examples/calculator-kotlin-junit5/src/test/resources/io/cucumber/examples/calculator/shopping.feature b/examples/calculator-kotlin-junit5/src/test/resources/io/cucumber/examples/calculator/shopping.feature
new file mode 100644
index 0000000000..87089ce083
--- /dev/null
+++ b/examples/calculator-kotlin-junit5/src/test/resources/io/cucumber/examples/calculator/shopping.feature
@@ -0,0 +1,11 @@
+Feature: Shopping
+
+ @shopping
+ Scenario: Give correct change
+ Given the following groceries
+ | name | price |
+ | milk | 9 |
+ | bread | 7 |
+ | soap | 5 |
+ When I pay 25
+ Then my change should be 4
diff --git a/examples/pom.xml b/examples/pom.xml
index 23b830291f..0a906407e0 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -17,6 +17,7 @@
calculator-java-junit4
calculator-java-junit5
calculator-java-testng
+ calculator-kotlin-junit5
spring-java-junit5
wicket-java-junit4
diff --git a/examples/spring-java-junit5/pom.xml b/examples/spring-java-junit5/pom.xml
index 3848cf3647..580766fc8b 100644
--- a/examples/spring-java-junit5/pom.xml
+++ b/examples/spring-java-junit5/pom.xml
@@ -8,7 +8,7 @@
spring-java-junit5
- Examples: Spring Transactions - Java - Junit 5
+ Examples: Spring Transactions - Java - Annotations - Junit 5
io.cucumber.examples.spring.application