Skip to content

Commit 670626a

Browse files
committed
Add test case for CDATA
1 parent 869f1b1 commit 670626a

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

java/src/main/java/io/cucumber/junitxmlformatter/XmlReportData.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import io.cucumber.messages.types.TestCaseFinished;
99
import io.cucumber.messages.types.TestCaseStarted;
1010
import io.cucumber.messages.types.TestRunFinished;
11-
import io.cucumber.messages.types.TestRunStarted;
1211
import io.cucumber.messages.types.TestStep;
1312
import io.cucumber.messages.types.TestStepFinished;
1413
import io.cucumber.messages.types.TestStepResult;
@@ -51,7 +50,7 @@ class XmlReportData {
5150
private final Map<String, String> stepAstNodeIdToStepKeyWord = new ConcurrentHashMap<>();
5251

5352
void collect(Envelope envelope) {
54-
envelope.getTestRunStarted().ifPresent(this::testRunStarted);
53+
envelope.getTestRunStarted().ifPresent(event -> this.testRunStarted = timestampToJavaInstant(event.getTimestamp()));
5554
envelope.getTestRunFinished().ifPresent(this::testRunFinished);
5655
envelope.getTestCaseStarted().ifPresent(this::testCaseStarted);
5756
envelope.getTestCaseFinished().ifPresent(this::testCaseFinished);
@@ -61,26 +60,22 @@ void collect(Envelope envelope) {
6160
envelope.getTestCase().ifPresent(this::testCase);
6261
}
6362

64-
void testRunStarted(TestRunStarted event) {
65-
this.testRunStarted = timestampToJavaInstant(event.getTimestamp());
66-
}
67-
68-
void testRunFinished(TestRunFinished event) {
63+
private void testRunFinished(TestRunFinished event) {
6964
this.testRunFinished = timestampToJavaInstant(event.getTimestamp());
7065
}
7166

72-
void testCaseStarted(TestCaseStarted event) {
67+
private void testCaseStarted(TestCaseStarted event) {
7368
this.testCaseStartedIds.add(event.getId());
7469
this.testCaseStartedIdToStartedInstant.put(event.getId(), timestampToJavaInstant(event.getTimestamp()));
7570
this.testCaseStartedIdToTestCaseId.put(event.getId(), event.getTestCaseId());
7671
}
7772

78-
void testCaseFinished(TestCaseFinished event) {
73+
private void testCaseFinished(TestCaseFinished event) {
7974
this.testCaseStartedIdToFinishedInstant.put(event.getTestCaseStartedId(),
8075
timestampToJavaInstant(event.getTimestamp()));
8176
}
8277

83-
void testStepFinished(TestStepFinished event) {
78+
private void testStepFinished(TestStepFinished event) {
8479
testStepIdToTestStepResultStatus.put(event.getTestStepId(), event.getTestStepResult().getStatus());
8580
testCaseStartedIdToResult.compute(event.getTestCaseStartedId(),
8681
(__, previousStatus) -> mostSevereResult(previousStatus, event.getTestStepResult()));
@@ -90,7 +85,7 @@ private TestStepResult mostSevereResult(TestStepResult a, TestStepResult b) {
9085
return testStepResultComparator.compare(a, b) >= 0 ? a : b;
9186
}
9287

93-
void source(GherkinDocument event) {
88+
private void source(GherkinDocument event) {
9489
event.getFeature().ifPresent(feature -> {
9590
feature.getChildren().forEach(featureChild -> {
9691
featureChild.getRule().ifPresent(rule -> {
@@ -113,7 +108,7 @@ void source(GherkinDocument event) {
113108
});
114109
}
115110

116-
void pickle(Pickle event) {
111+
private void pickle(Pickle event) {
117112
pickleIdToPickle.put(event.getId(), event);
118113
// @formatter:off
119114
event.getAstNodeIds().stream()
@@ -122,7 +117,7 @@ void pickle(Pickle event) {
122117
// @formatter:on
123118
}
124119

125-
void testCase(TestCase testCase) {
120+
private void testCase(TestCase testCase) {
126121
testCaseIdToTestCase.put(testCase.getId(), testCase);
127122
}
128123

@@ -168,7 +163,7 @@ public String getFeatureName(String testCaseStartedId) {
168163
return scenarioAstNodeIdToFeatureName.get(astNodeId);
169164
}
170165

171-
public LinkedHashMap<String, String> getStepsAndResult(String testCaseStartedId) {
166+
LinkedHashMap<String, String> getStepsAndResult(String testCaseStartedId) {
172167
String testCaseId = testCaseStartedIdToTestCaseId.get(testCaseStartedId);
173168
TestCase testCase = testCaseIdToTestCase.get(testCaseId);
174169
Pickle pickle = pickleIdToPickle.get(testCase.getPickleId());
@@ -208,16 +203,16 @@ private Function<TestStep, String> renderTestStepText(Pickle pickle) {
208203
};
209204
}
210205

211-
public Deque<String> testCaseStartedIds() {
206+
Deque<String> testCaseStartedIds() {
212207
return testCaseStartedIds;
213208
}
214209

215-
private static final io.cucumber.messages.types.Duration ZERO_DURATION = new io.cucumber.messages.types.Duration(
216-
0L, 0L);
210+
private static final io.cucumber.messages.types.Duration ZERO_DURATION =
211+
new io.cucumber.messages.types.Duration(0L, 0L);
217212
// By definition, but see https://github.com/cucumber/gherkin/issues/11
218213
private static final TestStepResult SCENARIO_WITH_NO_STEPS = new TestStepResult(ZERO_DURATION, null, PASSED);
219214

220-
public TestStepResult getTestCaseStatus(String testCaseStartedId) {
215+
TestStepResult getTestCaseStatus(String testCaseStartedId) {
221216
return testCaseStartedIdToResult.getOrDefault(testCaseStartedId, SCENARIO_WITH_NO_STEPS);
222217
}
223218

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{"meta":{"ci":{"buildNumber":"154666429","git":{"remote":"https://github.com/cucumber-ltd/shouty.rb.git","revision":"99684bcacf01d95875834d87903dcb072306c9ad"},"name":"GitHub Actions","url":"https://github.com/cucumber-ltd/shouty.rb/actions/runs/154666429"},"cpu":{"name":"x64"},"implementation":{"name":"fake-cucumber","version":"16.0.0"},"os":{"name":"linux","version":"5.10.102.1-microsoft-standard-WSL2"},"protocolVersion":"19.1.2","runtime":{"name":"node.js","version":"16.4.0"}}}
2+
{"source":{"data":"Feature: minimal\n \n Cucumber doesn't execute this markdown, but @cucumber/react renders it\n \n * This is\n * a bullet\n * list\n \n Scenario: cukes\n Given I have 42 cukes in my belly\n","mediaType":"text/x.cucumber.gherkin+plain","uri":"samples/minimal/minimal.feature"}}
3+
{"gherkinDocument":{"comments":[],"feature":{"children":[{"scenario":{"description":"","examples":[],"id":"2","keyword":"Scenario","location":{"column":3,"line":9},"name":"cukes","steps":[{"id":"1","keyword":"Given ","keywordType":"Context","location":{"column":5,"line":10},"text":"I have 42 ![CDATA[cukes]] in my belly"}],"tags":[]}}],"description":" Cucumber doesn't execute this markdown, but @cucumber/react renders it\n \n * This is\n * a bullet\n * list","keyword":"Feature","language":"en","location":{"column":1,"line":1},"name":"minimal","tags":[]},"uri":"samples/minimal/minimal.feature"}}
4+
{"pickle":{"astNodeIds":["2"],"id":"4","language":"en","name":"cukes","steps":[{"astNodeIds":["1"],"id":"3","text":"I have <![CDATA[42]]> cukes in my belly","type":"Context"}],"tags":[],"uri":"samples/minimal/minimal.feature"}}
5+
{"stepDefinition":{"id":"0","pattern":{"source":"I have {int} cukes in my belly","type":"CUCUMBER_EXPRESSION"},"sourceReference":{"location":{"line":4},"uri":"samples/minimal/minimal.feature.ts"}}}
6+
{"testRunStarted":{"timestamp":{"nanos":0,"seconds":0}}}
7+
{"testCase":{"id":"6","pickleId":"4","testSteps":[{"id":"5","pickleStepId":"3","stepDefinitionIds":["0"],"stepMatchArgumentsLists":[{"stepMatchArguments":[{"group":{"children":[],"start":7,"value":"42"},"parameterTypeName":"int"}]}]}]}}
8+
{"testCaseStarted":{"attempt":0,"id":"7","testCaseId":"6","timestamp":{"nanos":1000000,"seconds":0}}}
9+
{"testStepStarted":{"testCaseStartedId":"7","testStepId":"5","timestamp":{"nanos":2000000,"seconds":0}}}
10+
{"testStepFinished":{"testCaseStartedId":"7","testStepId":"5","testStepResult":{"duration":{"nanos":1000000,"seconds":0},"status":"PASSED"},"timestamp":{"nanos":3000000,"seconds":0}}}
11+
{"testCaseFinished":{"testCaseStartedId":"7","timestamp":{"nanos":4000000,"seconds":0},"willBeRetried":false}}
12+
{"testRunFinished":{"success":true,"timestamp":{"nanos":5000000,"seconds":0}}}

0 commit comments

Comments
 (0)