Skip to content
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

Support configurable NamingStrategy.ExampleName #32

Merged
merged 1 commit into from
Apr 5, 2024
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 @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Support configurable `NamingStrategy.ExampleName` ([#32](https://github.com/cucumber/cucumber-junit-xml-formatter/pull/32), M.P. Korstanje)

## [0.4.0] - 2024-04-05
### Changed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package io.cucumber.junitxmlformatter;

import io.cucumber.messages.types.Envelope;
import io.cucumber.query.NamingStrategy;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;

import static io.cucumber.query.NamingStrategy.FeatureName.EXCLUDE;
import static io.cucumber.query.NamingStrategy.Strategy.LONG;
import static java.util.Objects.requireNonNull;

/**
Expand All @@ -20,10 +23,23 @@
public class MessagesToJunitXmlWriter implements AutoCloseable {

private final OutputStreamWriter out;
private final XmlReportData data = new XmlReportData();
private final XmlReportData data;
private boolean streamClosed = false;

public MessagesToJunitXmlWriter(OutputStream out) {
this(NamingStrategy.ExampleName.NUMBER, out);
}

public MessagesToJunitXmlWriter(NamingStrategy.ExampleName exampleNameStrategy, OutputStream out) {
this(createNamingStrategy(requireNonNull(exampleNameStrategy)), out);
}

private static NamingStrategy createNamingStrategy(NamingStrategy.ExampleName exampleName) {
return NamingStrategy.strategy(LONG).featureName(EXCLUDE).exampleName(exampleName).build();
}

private MessagesToJunitXmlWriter(NamingStrategy namingStrategy, OutputStream out) {
this.data = new XmlReportData(namingStrategy);
this.out = new OutputStreamWriter(
requireNonNull(out),
StandardCharsets.UTF_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.util.Optional;

import static io.cucumber.messages.types.TestStepResultStatus.PASSED;
import static io.cucumber.query.NamingStrategy.FeatureName.EXCLUDE;
import static io.cucumber.query.NamingStrategy.Strategy.LONG;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.counting;
Expand All @@ -33,13 +31,14 @@
class XmlReportData {

private final Query query = new Query();
private final NamingStrategy namingStrategy = NamingStrategy
.strategy(LONG)
.featureName(EXCLUDE)
.build();
private final NamingStrategy namingStrategy;

private static final long MILLIS_PER_SECOND = SECONDS.toMillis(1L);

public XmlReportData(NamingStrategy namingStrategy) {
this.namingStrategy = namingStrategy;
}

void collect(Envelope envelope) {
query.update(envelope);
}
Expand Down