File tree Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ Feature : Optional capture groups are supported
2+
3+ Scenario : present, using Java's Optional
4+ Given I have the name: Jack
5+
6+ Scenario : absent, using Java's Optional
7+ Given I don't have the name:
Original file line number Diff line number Diff line change 1+ package tests .misc
2+
3+ import java .util .Optional
4+
5+ import io .cucumber .scala .{EN , ScalaDsl }
6+
7+ class OptionalCaptureGroupsSteps extends ScalaDsl with EN {
8+
9+ // Scala 2.13 only
10+ // import scala.jdk.OptionConverters._
11+
12+ import OptionalCaptureGroupsSteps ._
13+
14+ Given (""" ^I have the name:\s?(.+)?$""" ) { (name : Optional [String ]) =>
15+ val option = name.toScala
16+ assert(option.isDefined)
17+ assert(option.getOrElse(" Nope" ) == " Jack" )
18+ }
19+
20+ Given (""" ^I don't have the name:\s?(.+)?$""" ) { (name : Optional [String ]) =>
21+ val option = name.toScala
22+ assert(option.isEmpty)
23+ }
24+
25+ }
26+
27+ object OptionalCaptureGroupsSteps {
28+
29+ implicit class RichOptional [A ](private val o : java.util.Optional [A ]) extends AnyVal {
30+
31+ def toScala : Option [A ] = if (o.isPresent) Some (o.get) else None
32+
33+ }
34+
35+ }
Original file line number Diff line number Diff line change 1+ package tests .misc
2+
3+ import io .cucumber .junit .{Cucumber , CucumberOptions }
4+ import org .junit .runner .RunWith
5+
6+ @ RunWith (classOf [Cucumber ])
7+ @ CucumberOptions (strict = true )
8+ class RunMiscTest
You can’t perform that action at this time.
0 commit comments