Skip to content

Commit 1596373

Browse files
authored
Add Scenario.getLanguage() (#3124)
1 parent 82e3ad4 commit 1596373

File tree

8 files changed

+51
-0
lines changed

8 files changed

+51
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
## [Unreleased]
1313
### Added
1414
- [Core] Upload Cucumber Reports with Gzip encoding ([#3115](https://github.com/cucumber/cucumber-jvm/pull/3115))
15+
- [Java] Add a getter to `Scenario` to return the current language ([cucumber/cucumber-expressions#376](https://github.com/cucumber/cucumber-expressions/issues/376) Stefan Gasterstädt)
1516

1617
## [7.32.0] - 2025-11-21
1718
### Changed

cucumber-core/src/main/java/io/cucumber/core/backend/TestCaseState.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ public interface TestCaseState {
8484
*/
8585
URI getUri();
8686

87+
/**
88+
* @return the language of the Scenario.
89+
*/
90+
String getLanguage();
91+
8792
/**
8893
* @return the line in the feature file of the Scenario. If this is a
8994
* Scenario from Scenario Outlines this will return the line of the

cucumber-core/src/main/java/io/cucumber/core/runner/TestCase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ private String fileColonLine(Integer line) {
130130
return pickle.getUri().getSchemeSpecificPart() + ":" + line;
131131
}
132132

133+
@Override
134+
public String getLanguage() {
135+
return pickle.getLanguage();
136+
}
137+
133138
@Override
134139
public List<String> getTags() {
135140
return pickle.getTags();

cucumber-core/src/main/java/io/cucumber/core/runner/TestCaseState.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ public URI getUri() {
145145
return testCase.getUri();
146146
}
147147

148+
@Override
149+
public String getLanguage() {
150+
return testCase.getLanguage();
151+
}
152+
148153
@Override
149154
public Integer getLine() {
150155
return testCase.getLocation().getLine();

cucumber-core/src/test/java/io/cucumber/core/runner/TestCaseStateTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@ void provides_the_uri_of_the_feature_file() {
3636
assertThat(state.getUri(), is(new File("path/file.feature").toURI()));
3737
}
3838

39+
@Test
40+
void provides_the_language_of_the_feature_file_without_language_declaration() {
41+
Feature feature = TestFeatureParser.parse("file:path/file.feature", "" +
42+
"Feature: Test feature\n" +
43+
" Scenario: Test scenario\n" +
44+
" Given I have 4 cukes in my belly\n");
45+
TestCaseState state = createTestCaseState(feature);
46+
assertThat(state.getLanguage(), is("en"));
47+
}
48+
49+
@Test
50+
void provides_the_language_of_the_feature_file_with_language_declaration() {
51+
Feature feature = TestFeatureParser.parse("file:path/file.feature", "" +
52+
"#language: en\n" +
53+
"Feature: Test feature\n" +
54+
" Scenario: Test scenario\n" +
55+
" Given I have 4 cukes in my belly\n");
56+
TestCaseState state = createTestCaseState(feature);
57+
assertThat(state.getLanguage(), is("en"));
58+
}
59+
3960
private TestCaseState createTestCaseState(Feature feature) {
4061
return new TestCaseState(bus,
4162
UUID.randomUUID(),

cucumber-java/src/main/java/io/cucumber/java/Scenario.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ public URI getUri() {
130130
return delegate.getUri();
131131
}
132132

133+
/**
134+
* @return the language of the Scenario.
135+
*/
136+
public String getLanguage() {
137+
return delegate.getLanguage();
138+
}
139+
133140
/**
134141
* Returns the line in the feature file of the Scenario.
135142
* <p>

cucumber-junit-platform-engine/src/test/java/io/cucumber/junit/platform/engine/TestCaseResultObserverTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ public String getScenarioDesignation() {
6767
return "mock-test-case:12";
6868
}
6969

70+
@Override
71+
public String getLanguage() {
72+
return "en";
73+
}
74+
7075
@Override
7176
public List<String> getTags() {
7277
return emptyList();

cucumber-plugin/src/main/java/io/cucumber/plugin/event/TestCase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public interface TestCase {
3838
@Deprecated
3939
String getScenarioDesignation();
4040

41+
String getLanguage();
42+
4143
List<String> getTags();
4244

4345
List<TestStep> getTestSteps();

0 commit comments

Comments
 (0)