diff --git a/java/.mvn/jvm.config b/java/.mvn/jvm.config
new file mode 100644
index 0000000..32599ce
--- /dev/null
+++ b/java/.mvn/jvm.config
@@ -0,0 +1,10 @@
+--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
+--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
+--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
+--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
+--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
+--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
+--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
+--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
+--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
+--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
diff --git a/java/pom.xml b/java/pom.xml
index 9132d83..db76e17 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -5,11 +5,11 @@
io.cucumber
cucumber-parent
- 4.5.0
+ 5.0.0-SNAPSHOT
cucumber-json-formatter
- 0.3.1-SNAPSHOT
+ 0.4.0-SNAPSHOT
jar
Cucumber Json Formatter
Writes Cucumber message into the legacy Cucumber JSON format
@@ -59,12 +59,13 @@
io.cucumber
messages
- [29.0.1,31.0.0)
+ [32.0.0-SNAPSHOT,33.0.0)
+
io.cucumber
query
- [14.0.1,15.0.0)
+ [15.0.0-SNAPSHOT,16.0.0)
@@ -136,6 +137,19 @@
95
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+
+
+ validate
+ validate
+
+ check
+
+
+
+
diff --git a/java/src/main/java/io/cucumber/jsonformatter/CucumberJvmJson.java b/java/src/main/java/io/cucumber/jsonformatter/CucumberJvmJson.java
index e4ff69f..dc0e25a 100644
--- a/java/src/main/java/io/cucumber/jsonformatter/CucumberJvmJson.java
+++ b/java/src/main/java/io/cucumber/jsonformatter/CucumberJvmJson.java
@@ -1,5 +1,7 @@
package io.cucumber.jsonformatter;
+import org.jspecify.annotations.Nullable;
+
import java.util.List;
import static java.util.Objects.requireNonNull;
@@ -10,6 +12,8 @@
* schema.
*/
final class CucumberJvmJson {
+
+ @Nullable
private static List nullIfEmpty(List list) {
return list.isEmpty() ? null : list;
}
@@ -17,6 +21,7 @@ private static List nullIfEmpty(List list) {
enum JvmElementType {
background, scenario
}
+
enum JvmStatus {
passed,
skipped,
@@ -26,19 +31,19 @@ enum JvmStatus {
failed
}
- static class JvmFeature {
- private final Long line;
+ static final class JvmFeature {
+ private final Integer line;
private final String uri;
private final String id;
private final String keyword;
private final String name;
private final String description;
private final List elements;
- private final List tags;
+ private final @Nullable List tags;
JvmFeature(
- String uri, String id, Long line, String keyword, String name, String description,
- List elements, List tags
+ String uri, String id, Integer line, String keyword, String name, String description,
+ List elements, @Nullable List tags
) {
this.uri = requireNonNull(uri);
this.id = requireNonNull(id);
@@ -58,7 +63,7 @@ public String getId() {
return id;
}
- public Long getLine() {
+ public Integer getLine() {
return line;
}
@@ -78,26 +83,26 @@ public List getElements() {
return elements;
}
- public List getTags() {
+ public @Nullable List getTags() {
return tags;
}
}
- static class JvmElement {
- private final String start_timestamp;
- private final Long line;
- private final String id;
+ static final class JvmElement {
+ private final @Nullable String start_timestamp;
+ private final Integer line;
+ private final @Nullable String id;
private final JvmElementType type;
private final String keyword;
private final String name;
private final String description;
private final List steps;
- private final List before;
- private final List after;
- private final List tags;
+ private final @Nullable List before;
+ private final @Nullable List after;
+ private final @Nullable List tags;
JvmElement(
- String start_timestamp, Long line, String id, JvmElementType type, String keyword, String name,
+ @Nullable String start_timestamp, Integer line, @Nullable String id, JvmElementType type, String keyword, String name,
String description, List steps, List before, List after, List tags
) {
this.start_timestamp = start_timestamp;
@@ -113,15 +118,15 @@ static class JvmElement {
this.tags = nullIfEmpty(tags);
}
- public String getStart_timestamp() {
+ public @Nullable String getStart_timestamp() {
return start_timestamp;
}
- public Long getLine() {
+ public Integer getLine() {
return line;
}
- public String getId() {
+ public @Nullable String getId() {
return id;
}
@@ -145,35 +150,35 @@ public List getSteps() {
return steps;
}
- public List getBefore() {
+ public @Nullable List getBefore() {
return before;
}
- public List getAfter() {
+ public @Nullable List getAfter() {
return after;
}
- public List getTags() {
+ public @Nullable List getTags() {
return tags;
}
}
- static class JvmStep {
+ static final class JvmStep {
private final String keyword;
- private final Long line;
- private final JvmMatch match;
+ private final Integer line;
+ private final @Nullable JvmMatch match;
private final String name;
private final JvmResult result;
- private final JvmDocString doc_string;
- private final List rows;
- private final List before;
- private final List after;
- private final List embeddings;
- private final List output;
+ private final @Nullable JvmDocString doc_string;
+ private final @Nullable List rows;
+ private final @Nullable List before;
+ private final @Nullable List after;
+ private final @Nullable List embeddings;
+ private final @Nullable List output;
JvmStep(
- String keyword, Long line, JvmMatch match, String name, JvmResult result, JvmDocString doc_string,
- List rows, List before, List after, List embeddings, List output
+ String keyword, Integer line, @Nullable JvmMatch match, String name, JvmResult result, @Nullable JvmDocString doc_string,
+ @Nullable List rows, List before, List after, List embeddings, List output
) {
this.keyword = requireNonNull(keyword);
this.line = requireNonNull(line);
@@ -192,11 +197,11 @@ public String getKeyword() {
return keyword;
}
- public Long getLine() {
+ public Integer getLine() {
return line;
}
- public JvmMatch getMatch() {
+ public @Nullable JvmMatch getMatch() {
return match;
}
@@ -208,79 +213,79 @@ public JvmResult getResult() {
return result;
}
- public JvmDocString getDoc_string() {
+ public @Nullable JvmDocString getDoc_string() {
return doc_string;
}
- public List getRows() {
+ public @Nullable List getRows() {
return rows;
}
- public List getBefore() {
+ public @Nullable List getBefore() {
return before;
}
- public List getAfter() {
+ public @Nullable List getAfter() {
return after;
}
- public List getEmbeddings() {
+ public @Nullable List getEmbeddings() {
return embeddings;
}
- public List getOutput() {
+ public @Nullable List getOutput() {
return output;
}
}
- static class JvmMatch {
- private final String location;
- private final List arguments;
+ static final class JvmMatch {
+ private final @Nullable String location;
+ private final @Nullable List arguments;
- JvmMatch(String location, List arguments) {
+ JvmMatch(@Nullable String location, @Nullable List arguments) {
this.location = location;
this.arguments = arguments;
}
- public String getLocation() {
+ public @Nullable String getLocation() {
return location;
}
- public List getArguments() {
+ public @Nullable List getArguments() {
return arguments;
}
}
- static class JvmArgument {
- private final String val;
- private final Number offset;
+ static final class JvmArgument {
+ private final @Nullable String val;
+ private final @Nullable Number offset;
- JvmArgument(String val, Number offset) {
+ JvmArgument(@Nullable String val, @Nullable Number offset) {
this.val = val;
this.offset = offset;
}
- public String getVal() {
+ public @Nullable String getVal() {
return val;
}
- public Number getOffset() {
+ public @Nullable Number getOffset() {
return offset;
}
}
- static class JvmResult {
- private final Long duration;
+ static final class JvmResult {
+ private final @Nullable Long duration;
private final JvmStatus status;
- private final String error_message;
+ private final @Nullable String error_message;
- JvmResult(Long duration, JvmStatus status, String error_message) {
+ JvmResult(@Nullable Long duration, JvmStatus status, @Nullable String error_message) {
this.duration = duration;
this.status = requireNonNull(status);
this.error_message = error_message;
}
- public Long getDuration() {
+ public @Nullable Long getDuration() {
return duration;
}
@@ -288,23 +293,23 @@ public JvmStatus getStatus() {
return status;
}
- public String getError_message() {
+ public @Nullable String getError_message() {
return error_message;
}
}
- static class JvmDocString {
- private final Long line;
+ static final class JvmDocString {
+ private final Integer line;
private final String value;
- private final String content_type;
+ private final @Nullable String content_type;
- JvmDocString(Long line, String value, String content_type) {
+ JvmDocString(Integer line, String value, @Nullable String content_type) {
this.line = requireNonNull(line);
this.value = requireNonNull(value);
this.content_type = content_type;
}
- public Long getLine() {
+ public Integer getLine() {
return line;
}
@@ -312,12 +317,12 @@ public String getValue() {
return value;
}
- public String getContent_type() {
+ public @Nullable String getContent_type() {
return content_type;
}
}
- static class JvmDataTableRow {
+ static final class JvmDataTableRow {
private final List cells;
JvmDataTableRow(List cells) {
@@ -329,11 +334,11 @@ public List getCells() {
}
}
- static class JvmHook {
+ static final class JvmHook {
private final JvmMatch match;
private final JvmResult result;
- private final List embeddings;
- private final List output;
+ private final @Nullable List embeddings;
+ private final @Nullable List output;
JvmHook(JvmMatch match, JvmResult result, List embeddings, List output) {
this.match = requireNonNull(match);
@@ -350,21 +355,21 @@ public JvmResult getResult() {
return result;
}
- public List getEmbeddings() {
+ public @Nullable List getEmbeddings() {
return embeddings;
}
- public List getOutput() {
+ public @Nullable List getOutput() {
return output;
}
}
- static class JvmEmbedding {
+ static final class JvmEmbedding {
private final String mime_type;
private final String data;
- private final String name;
+ private final @Nullable String name;
- JvmEmbedding(String mime_type, String data, String name) {
+ JvmEmbedding(String mime_type, String data, @Nullable String name) {
this.mime_type = requireNonNull(mime_type);
this.data = requireNonNull(data);
this.name = name;
@@ -378,12 +383,12 @@ public String getMime_type() {
return mime_type;
}
- public String getName() {
+ public @Nullable String getName() {
return name;
}
}
- static class JvmTag {
+ static final class JvmTag {
private final String name;
JvmTag(String name) {
@@ -395,7 +400,7 @@ public String getName() {
}
}
- static class JvmLocationTag {
+ static final class JvmLocationTag {
private final String name;
private final String type;
private final JvmLocation location;
@@ -419,20 +424,20 @@ public JvmLocation getLocation() {
}
}
- static class JvmLocation {
- private final Long line;
- private final Long column;
+ static final class JvmLocation {
+ private final Integer line;
+ private final Integer column;
- JvmLocation(Long line, Long column) {
+ JvmLocation(Integer line, Integer column) {
this.line = requireNonNull(line);
this.column = requireNonNull(column);
}
- public Long getLine() {
+ public Integer getLine() {
return line;
}
- public Long getColumn() {
+ public Integer getColumn() {
return column;
}
}
diff --git a/java/src/main/java/io/cucumber/jsonformatter/IdNamingVisitor.java b/java/src/main/java/io/cucumber/jsonformatter/IdNamingVisitor.java
index 71796bc..4c872c9 100644
--- a/java/src/main/java/io/cucumber/jsonformatter/IdNamingVisitor.java
+++ b/java/src/main/java/io/cucumber/jsonformatter/IdNamingVisitor.java
@@ -2,7 +2,6 @@
import io.cucumber.messages.types.Examples;
import io.cucumber.messages.types.Feature;
-import io.cucumber.messages.types.Pickle;
import io.cucumber.messages.types.Rule;
import io.cucumber.messages.types.Scenario;
import io.cucumber.messages.types.TableRow;
diff --git a/java/src/main/java/io/cucumber/jsonformatter/JsonReportWriter.java b/java/src/main/java/io/cucumber/jsonformatter/JsonReportWriter.java
index 2303939..b94c656 100644
--- a/java/src/main/java/io/cucumber/jsonformatter/JsonReportWriter.java
+++ b/java/src/main/java/io/cucumber/jsonformatter/JsonReportWriter.java
@@ -50,6 +50,7 @@
import io.cucumber.query.Lineage;
import io.cucumber.query.LineageReducer;
import io.cucumber.query.Query;
+import org.jspecify.annotations.Nullable;
import java.net.URI;
import java.time.Duration;
@@ -65,7 +66,6 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
-import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collector;
@@ -92,11 +92,9 @@ final class JsonReportWriter {
this.uriFormatter = requireNonNull(uriFormatter);
}
- private static BinaryOperator, List>> mergeEntries() {
- return (a, b) -> {
- a.getValue().addAll(b.getValue());
- return a;
- };
+ private static Entry, List> mergeEntries(Entry, List> a, Entry, List> b) {
+ a.getValue().addAll(b.getValue());
+ return a;
}
private static Predicate, List>> isTestCase() {
@@ -107,7 +105,7 @@ private static Predicate, List>> is
return entry -> entry.getKey().isPresent();
}
- private static Long formatDuration(TestStepResult result) {
+ private static @Nullable Long formatDuration(TestStepResult result) {
Duration duration = Convertor.toDuration(result.getDuration());
if (result.getStatus() == TestStepResultStatus.UNDEFINED) {
return null;
@@ -176,21 +174,12 @@ private TestStepData createTestStepData(TestCaseStarted testCaseStarted) {
}
switch (hook) {
- case BEFORE_TEST_RUN:
- case AFTER_TEST_RUN:
- break;
- case BEFORE_TEST_CASE:
- beforeTestCase.add(testStepFinished);
- break;
- case AFTER_TEST_CASE:
- afterTestCase.add(testStepFinished);
- break;
- case BEFORE_TEST_STEP:
- beforeTestStep.add(testStepFinished);
- break;
- case AFTER_TEST_STEP:
- afterTestStep.add(testStepFinished);
- break;
+ case BEFORE_TEST_RUN, AFTER_TEST_RUN -> {
+ }
+ case BEFORE_TEST_CASE -> beforeTestCase.add(testStepFinished);
+ case AFTER_TEST_CASE -> afterTestCase.add(testStepFinished);
+ case BEFORE_TEST_STEP -> beforeTestStep.add(testStepFinished);
+ case AFTER_TEST_STEP -> afterTestStep.add(testStepFinished);
}
}
@@ -208,13 +197,12 @@ private JvmFeature createJvmFeature(List elements) {
document.getUri()
.map(URI::create)
.map(uriFormatter)
- .orElse(null),
+ .orElseThrow(() -> new IllegalStateException("No uri for document")),
formatId(feature.getName()),
feature.getLocation().getLine(),
feature.getKeyword(),
feature.getName(),
- // TODO: Can this be null?
- feature.getDescription() != null ? feature.getDescription() : "",
+ feature.getDescription(),
createJvmElements(elements),
createJvmLocationTags(feature));
}
@@ -237,13 +225,13 @@ private List createJvmElement(JvmElementData data) {
// first.
Optional background = stepsByBackground.entrySet().stream()
.filter(isBackGround())
- .reduce(mergeEntries())
+ .reduce(JsonReportWriter::mergeEntries)
.flatMap(entry -> entry.getKey()
.map(bg -> createBackground(data, bg, entry.getValue())));
Optional testCase = stepsByBackground.entrySet().stream()
.filter(isTestCase())
- .reduce(mergeEntries())
+ .reduce(JsonReportWriter::mergeEntries)
.map(Entry::getValue)
.map(scenarioTestStepsFinished -> createTestCase(data, scenarioTestStepsFinished));
@@ -321,16 +309,14 @@ private List createEmbeddings(List attachments) {
private static String encodeBodyAsBase64(Attachment attachment) {
AttachmentContentEncoding encoding = attachment.getContentEncoding();
String body = attachment.getBody();
- switch (encoding) {
- case IDENTITY:
+ return switch (encoding) {
+ case IDENTITY -> {
byte[] bytes = body.getBytes(UTF_8);
Base64.Encoder encoder = Base64.getEncoder();
- return encoder.encodeToString(bytes);
- case BASE64:
- return body;
- default:
- throw new RuntimeException("Unknown content encoding " + encoding);
- }
+ yield encoder.encodeToString(bytes);
+ }
+ case BASE64 -> body;
+ };
}
private List createOutput(List attachments) {
@@ -347,15 +333,13 @@ private List createOutput(List attachments) {
private static String encodeBodyAsPlainText(Attachment attachment) {
AttachmentContentEncoding encoding = attachment.getContentEncoding();
String body = attachment.getBody();
- switch (encoding) {
- case IDENTITY:
- return body;
- case BASE64:
+ return switch (encoding) {
+ case IDENTITY -> body;
+ case BASE64 -> {
Base64.Decoder decoder = Base64.getDecoder();
- return new String(decoder.decode(body), UTF_8);
- default:
- throw new RuntimeException("Unknown content encoding " + encoding);
- }
+ yield new String(decoder.decode(body), UTF_8);
+ }
+ };
}
private static boolean isTextCucumberLogPlain(String mediaType) {
@@ -374,7 +358,7 @@ private JvmLocationTag createJvmLocationTag(Tag tag) {
"Tag",
new JvmLocation(
tag.getLocation().getLine(),
- tag.getLocation().getColumn().orElse(0L)));
+ tag.getLocation().getColumn().orElse(0)));
}
private JvmElement createBackground(
@@ -433,6 +417,7 @@ private JvmMatch createJvmMatch(TestStep testStep) {
createJvmArguments(testStep));
}
+ @Nullable
private List createJvmArguments(TestStep step) {
return step.getStepMatchArgumentsLists()
// Only include arguments for unambiguous steps
@@ -453,6 +438,7 @@ private JvmArgument createJvmArgument(StepMatchArgument argument) {
group.getStart().orElse(null));
}
+ @Nullable
private List createJvmDataTableRows(Step step) {
return step.getDataTable().map(this::createJvmDataTableRows).orElse(null);
}
@@ -465,6 +451,7 @@ private List createJvmDataTableRows(DataTable argument) {
.collect(toList());
}
+ @Nullable
private JvmDocString createJvmDocString(Step step) {
return step.getDocString().map(this::createJvmDocString).orElse(null);
}
@@ -476,6 +463,7 @@ private JvmDocString createJvmDocString(DocString docString) {
docString.getMediaType().orElse(null));
}
+ @Nullable
private String createLocation(TestStep step) {
return findSourceReference(step)
.flatMap(sourceReferenceFormatter::format)
@@ -509,8 +497,8 @@ private List findBackgroundsBy(Feature feature) {
featureChild.getBackground().ifPresent(backgrounds::add);
featureChild.getRule()
.map(Rule::getChildren)
- .map(Collection::stream)
- .orElseGet(Stream::empty)
+ .stream()
+ .flatMap(Collection::stream)
.map(RuleChild::getBackground)
.filter(Optional::isPresent)
.map(Optional::get)
diff --git a/java/src/main/java/io/cucumber/jsonformatter/MessagesToJsonWriter.java b/java/src/main/java/io/cucumber/jsonformatter/MessagesToJsonWriter.java
index c252304..c0e852a 100644
--- a/java/src/main/java/io/cucumber/jsonformatter/MessagesToJsonWriter.java
+++ b/java/src/main/java/io/cucumber/jsonformatter/MessagesToJsonWriter.java
@@ -51,25 +51,6 @@ public static Builder builder(Serializer serializer) {
return new Builder(serializer);
}
- public static final class Builder {
- private final Serializer serializer;
- private Function uriFormatter = URI::toString;
-
- private Builder(Serializer serializer) {
- this.serializer = requireNonNull(serializer);
- }
-
- public Builder relativizeAgainst(URI uri) {
- this.uriFormatter = new RelativeUriFormatter(uri).andThen(URI::toString);
- return this;
- }
-
- public MessagesToJsonWriter build(OutputStream out) {
- requireNonNull(out);
- return new MessagesToJsonWriter(out, serializer, uriFormatter);
- }
- }
-
/**
* Writes a cucumber message to the xml output.
*
@@ -107,6 +88,25 @@ public void close() throws IOException {
}
}
+ public static final class Builder {
+ private final Serializer serializer;
+ private Function uriFormatter = URI::toString;
+
+ private Builder(Serializer serializer) {
+ this.serializer = requireNonNull(serializer);
+ }
+
+ public Builder relativizeAgainst(URI uri) {
+ this.uriFormatter = new RelativeUriFormatter(uri).andThen(URI::toString);
+ return this;
+ }
+
+ public MessagesToJsonWriter build(OutputStream out) {
+ requireNonNull(out);
+ return new MessagesToJsonWriter(out, serializer, uriFormatter);
+ }
+ }
+
@FunctionalInterface
public interface Serializer {
diff --git a/java/src/main/java/io/cucumber/jsonformatter/RelativeUriFormatter.java b/java/src/main/java/io/cucumber/jsonformatter/RelativeUriFormatter.java
index d8abcfa..ef29538 100644
--- a/java/src/main/java/io/cucumber/jsonformatter/RelativeUriFormatter.java
+++ b/java/src/main/java/io/cucumber/jsonformatter/RelativeUriFormatter.java
@@ -4,10 +4,10 @@
import java.net.URISyntaxException;
import java.util.function.Function;
-class RelativeUriFormatter implements Function {
+final class RelativeUriFormatter implements Function {
private final URI base;
- public RelativeUriFormatter(URI base) {
+ RelativeUriFormatter(URI base) {
this.base = base;
}
diff --git a/java/src/main/java/io/cucumber/jsonformatter/package-info.java b/java/src/main/java/io/cucumber/jsonformatter/package-info.java
new file mode 100644
index 0000000..ba6cf7a
--- /dev/null
+++ b/java/src/main/java/io/cucumber/jsonformatter/package-info.java
@@ -0,0 +1,4 @@
+@NullMarked
+package io.cucumber.jsonformatter;
+
+import org.jspecify.annotations.NullMarked;
\ No newline at end of file
diff --git a/java/src/test/java/io/cucumber/jsonformatter/MessagesToJsonWriterAcceptanceTest.java b/java/src/test/java/io/cucumber/jsonformatter/MessagesToJsonWriterAcceptanceTest.java
index 406cf51..1d86e74 100644
--- a/java/src/test/java/io/cucumber/jsonformatter/MessagesToJsonWriterAcceptanceTest.java
+++ b/java/src/test/java/io/cucumber/jsonformatter/MessagesToJsonWriterAcceptanceTest.java
@@ -33,11 +33,13 @@
import static io.cucumber.jsonformatter.Jackson.OBJECT_MAPPER;
import static io.cucumber.jsonformatter.Jackson.PRETTY_PRINTER;
import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.Objects.requireNonNull;
import static org.assertj.core.api.Assertions.assertThat;
class MessagesToJsonWriterAcceptanceTest {
- private static final NdjsonToMessageIterable.Deserializer deserializer = (json) -> OBJECT_MAPPER.readValue(json, Envelope.class);
+
+ private static final NdjsonToMessageIterable.Deserializer deserializer = json -> OBJECT_MAPPER.readValue(json, Envelope.class);
private static final MessagesToJsonWriter.Serializer serializer = OBJECT_MAPPER.writer(PRETTY_PRINTER)::writeValue;
private static final JsonSchema jsonSchema = readJsonSchema();
private static final Random random = new Random(202509171757L);
@@ -142,15 +144,24 @@ static class TestCase {
TestCase(Path source) {
this.source = source;
- String parent = source.getParent().getFileName().toString();
- if (parent.equals("testdata")) {
- parent = source.getParent().getParent().getFileName().toString();
- }
- this.group = parent;
- String fileName = source.getFileName().toString();
- this.name = fileName.substring(0, fileName.lastIndexOf(".ndjson"));
+ this.group = getGroupName(source);
+ this.name = getFileNameWithNdjsonExtension(source);
// Each cucumber has a different dialect
- this.expected = source.getParent().resolve(name + ".ndjson.jvm.json");
+ this.expected = requireNonNull(source.getParent()).resolve(name + ".ndjson.jvm.json");
+ }
+
+ private static String getFileNameWithNdjsonExtension(Path source) {
+ String fileName = source.getFileName().toString();
+ return fileName.substring(0, fileName.lastIndexOf(".ndjson"));
+ }
+
+ private static String getGroupName(Path source) {
+ Path parent = requireNonNull(source.getParent());
+ String parentName = parent.getFileName().toString();
+ if (parentName.equals("testdata")) {
+ parentName = requireNonNull(parent.getParent()).getFileName().toString();
+ }
+ return parentName;
}
static List fromDirectory(String files) throws IOException {
diff --git a/java/src/test/java/io/cucumber/jsonformatter/MessagesToJsonWriterTest.java b/java/src/test/java/io/cucumber/jsonformatter/MessagesToJsonWriterTest.java
index 885385f..a12d2c3 100644
--- a/java/src/test/java/io/cucumber/jsonformatter/MessagesToJsonWriterTest.java
+++ b/java/src/test/java/io/cucumber/jsonformatter/MessagesToJsonWriterTest.java
@@ -10,7 +10,6 @@
import java.time.Instant;
import static io.cucumber.jsonformatter.Jackson.OBJECT_MAPPER;
-import static io.cucumber.jsonformatter.MessagesToJsonWriter.builder;
import static io.cucumber.messages.Convertor.toMessage;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
@@ -40,16 +39,20 @@ void it_writes_no_message_to_xml() throws IOException {
@Test
void it_throws_when_writing_after_close() throws IOException {
+ Instant started = Instant.ofEpochSecond(10);
+
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
- MessagesToJsonWriter messagesToHtmlWriter = builder(serializer).build(bytes);
+ MessagesToJsonWriter messagesToHtmlWriter = MessagesToJsonWriter.builder(serializer).build(bytes);
messagesToHtmlWriter.close();
- assertThrows(IOException.class, () -> messagesToHtmlWriter.write(null));
+ assertThrows(IOException.class, () -> messagesToHtmlWriter.write(
+ Envelope.of(new TestRunStarted(toMessage(started), "some-id"))
+ ));
}
@Test
void it_can_be_closed_twice() throws IOException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
- MessagesToJsonWriter messagesToHtmlWriter = builder(serializer).build(bytes);
+ MessagesToJsonWriter messagesToHtmlWriter = MessagesToJsonWriter.builder(serializer).build(bytes);
messagesToHtmlWriter.close();
assertDoesNotThrow(messagesToHtmlWriter::close);
}
@@ -62,7 +65,7 @@ public void close() throws IOException {
throw new IOException("Can't close this");
}
};
- MessagesToJsonWriter messagesToHtmlWriter = builder(serializer).build(bytes);
+ MessagesToJsonWriter messagesToHtmlWriter = MessagesToJsonWriter.builder(serializer).build(bytes);
assertThrows(IOException.class, messagesToHtmlWriter::close);
byte[] before = bytes.toByteArray();
assertDoesNotThrow(messagesToHtmlWriter::close);
@@ -73,12 +76,12 @@ public void close() throws IOException {
private String renderAsJson(Envelope... messages) throws IOException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
- try (MessagesToJsonWriter messagesToHtmlWriter = builder(serializer).build(bytes)) {
+ try (MessagesToJsonWriter messagesToHtmlWriter = MessagesToJsonWriter.builder(serializer).build(bytes)) {
for (Envelope message : messages) {
messagesToHtmlWriter.write(message);
}
}
- return new String(bytes.toByteArray(), UTF_8);
+ return bytes.toString(UTF_8);
}
}