From 7f436c9c3e84487ea236dc5fe7307248c8e4f7f9 Mon Sep 17 00:00:00 2001 From: Daniel Miladinov Date: Thu, 5 Dec 2024 08:27:18 -0500 Subject: [PATCH 1/5] Pretty-Print DocStringArgument Step Arguments Signed-off-by: Daniel Miladinov --- .../cucumber/core/plugin/PrettyFormatter.java | 21 ++++-- .../core/plugin/PrettyFormatterTest.java | 66 +++++++++++++++++++ 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/cucumber-core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java b/cucumber-core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java index a37c03513f..029b61e4c9 100644 --- a/cucumber-core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java +++ b/cucumber-core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java @@ -2,6 +2,7 @@ import io.cucumber.core.exception.CucumberException; import io.cucumber.core.gherkin.DataTableArgument; +import io.cucumber.core.gherkin.DocStringArgument; import io.cucumber.datatable.DataTable; import io.cucumber.datatable.DataTableFormatter; import io.cucumber.plugin.ColorAware; @@ -141,18 +142,28 @@ private void printStep(TestStepFinished event) { String locationComment = formatLocationComment(event, testStep, keyword, stepText); out.println(STEP_INDENT + formattedStepText + locationComment); StepArgument stepArgument = testStep.getStep().getArgument(); - if (DataTableArgument.class.isInstance(stepArgument)) { + if (stepArgument instanceof DataTableArgument) { DataTableFormatter tableFormatter = DataTableFormatter - .builder() - .prefixRow(STEP_SCENARIO_INDENT) - .escapeDelimiters(false) - .build(); + .builder() + .prefixRow(STEP_SCENARIO_INDENT) + .escapeDelimiters(false) + .build(); DataTableArgument dataTableArgument = (DataTableArgument) stepArgument; try { tableFormatter.formatTo(DataTable.create(dataTableArgument.cells()), out); } catch (IOException e) { throw new CucumberException(e); } + } else if (stepArgument instanceof DocStringArgument) { + DocStringArgument docStringArgument = (DocStringArgument) stepArgument; + String contentType = docStringArgument.getContentType(); + String printableContentType = contentType == null ? "" : contentType; + out.println(STEP_INDENT + "\"\"\"" + printableContentType); + for (String l : docStringArgument.getContent().split("\\r?\\n|\\r")) { + String s = STEP_INDENT + l; + out.println(s); + } + out.println(STEP_INDENT + "\"\"\""); } } } diff --git a/cucumber-core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java b/cucumber-core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java index f274c2dc70..828c0bbe09 100755 --- a/cucumber-core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java +++ b/cucumber-core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java @@ -16,6 +16,7 @@ import io.cucumber.core.stepexpression.StepExpressionFactory; import io.cucumber.core.stepexpression.StepTypeRegistry; import io.cucumber.datatable.DataTable; +import io.cucumber.docstring.DocString; import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; @@ -611,4 +612,69 @@ void should_print_system_failure_for_failed_hooks() { " " + AnsiEscapes.RED + "the stack trace" + AnsiEscapes.RESET))); } + @Test + void should_print_docstring_without_content_type() { + Feature feature = TestFeatureParser.parse("path/test.feature", "" + + "Feature: Test feature\n" + + " Scenario: Test Scenario\n" + + " Given first step\n" + + " \"\"\"\n" + + " {\"key1\": \"value1\",\n" + + " \"key2\": \"value2\",\n" + + " \"another1\": \"another2\"}\n" + + " \"\"\"\n"); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Runtime.builder() + .withFeatureSupplier(new StubFeatureSupplier(feature)) + .withAdditionalPlugins(new PrettyFormatter(out)) + .withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()) + .withBackendSupplier(new StubBackendSupplier( + new StubStepDefinition("first step", "path/step_definitions.java:7", DocString.class))) + .build() + .run(); + + assertThat(out, bytes(equalToCompressingWhiteSpace("" + + "\n" + + "Scenario: Test Scenario # path/test.feature:2\n" + + " Given first step # path/step_definitions.java:7\n" + + " \"\"\"\n" + + " {\"key1\": \"value1\",\n" + + " \"key2\": \"value2\",\n" + + " \"another1\": \"another2\"}\n" + + " \"\"\"\n"))); + } + + @Test + void should_print_docstring_including_content_type() { + Feature feature = TestFeatureParser.parse("path/test.feature", "" + + "Feature: Test feature\n" + + " Scenario: Test Scenario\n" + + " Given first step\n" + + " \"\"\"json\n" + + " {\"key1\": \"value1\",\n" + + " \"key2\": \"value2\",\n" + + " \"another1\": \"another2\"}\n" + + " \"\"\"\n"); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Runtime.builder() + .withFeatureSupplier(new StubFeatureSupplier(feature)) + .withAdditionalPlugins(new PrettyFormatter(out)) + .withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()) + .withBackendSupplier(new StubBackendSupplier( + new StubStepDefinition("first step", "path/step_definitions.java:7", DocString.class))) + .build() + .run(); + + assertThat(out, bytes(equalToCompressingWhiteSpace("" + + "\n" + + "Scenario: Test Scenario # path/test.feature:2\n" + + " Given first step # path/step_definitions.java:7\n" + + " \"\"\"json\n" + + " {\"key1\": \"value1\",\n" + + " \"key2\": \"value2\",\n" + + " \"another1\": \"another2\"}\n" + + " \"\"\"\n"))); + } } From bd39829a303ac2b175416483b6f4786d4b2feab9 Mon Sep 17 00:00:00 2001 From: Daniel Miladinov Date: Sun, 8 Dec 2024 19:38:28 -0500 Subject: [PATCH 2/5] Apply Code Review Feedback Thanks, @mpkorstanje! Signed-off-by: Daniel Miladinov --- CHANGELOG.md | 2 + .../cucumber/core/plugin/PrettyFormatter.java | 8 +- .../core/plugin/PrettyFormatterTest.java | 92 +++++++++---------- 3 files changed, 52 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a453ff5562..d6adf89359 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - [JUnit Platform Engine] Use JUnit Platform 1.11.3 (JUnit Jupiter 5.11.3) +### Fixed +- [Core] Pretty-Print DocStringArgument Step Arguments([#2953](https://github.com/cucumber/cucumber-jvm/pull/2953) Daniel Miladinov) ## [7.20.1] - 2024-10-09 ### Fixed diff --git a/cucumber-core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java b/cucumber-core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java index 029b61e4c9..973254bb35 100644 --- a/cucumber-core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java +++ b/cucumber-core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java @@ -144,10 +144,10 @@ private void printStep(TestStepFinished event) { StepArgument stepArgument = testStep.getStep().getArgument(); if (stepArgument instanceof DataTableArgument) { DataTableFormatter tableFormatter = DataTableFormatter - .builder() - .prefixRow(STEP_SCENARIO_INDENT) - .escapeDelimiters(false) - .build(); + .builder() + .prefixRow(STEP_SCENARIO_INDENT) + .escapeDelimiters(false) + .build(); DataTableArgument dataTableArgument = (DataTableArgument) stepArgument; try { tableFormatter.formatTo(DataTable.create(dataTableArgument.cells()), out); diff --git a/cucumber-core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java b/cucumber-core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java index 828c0bbe09..3ef77eedd7 100755 --- a/cucumber-core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java +++ b/cucumber-core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java @@ -615,66 +615,66 @@ void should_print_system_failure_for_failed_hooks() { @Test void should_print_docstring_without_content_type() { Feature feature = TestFeatureParser.parse("path/test.feature", "" + - "Feature: Test feature\n" + - " Scenario: Test Scenario\n" + - " Given first step\n" + - " \"\"\"\n" + - " {\"key1\": \"value1\",\n" + - " \"key2\": \"value2\",\n" + - " \"another1\": \"another2\"}\n" + - " \"\"\"\n"); + "Feature: Test feature\n" + + " Scenario: Test Scenario\n" + + " Given first step\n" + + " \"\"\"\n" + + " {\"key1\": \"value1\",\n" + + " \"key2\": \"value2\",\n" + + " \"another1\": \"another2\"}\n" + + " \"\"\"\n"); ByteArrayOutputStream out = new ByteArrayOutputStream(); Runtime.builder() - .withFeatureSupplier(new StubFeatureSupplier(feature)) - .withAdditionalPlugins(new PrettyFormatter(out)) - .withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()) - .withBackendSupplier(new StubBackendSupplier( - new StubStepDefinition("first step", "path/step_definitions.java:7", DocString.class))) - .build() - .run(); + .withFeatureSupplier(new StubFeatureSupplier(feature)) + .withAdditionalPlugins(new PrettyFormatter(out)) + .withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()) + .withBackendSupplier(new StubBackendSupplier( + new StubStepDefinition("first step", "path/step_definitions.java:7", DocString.class))) + .build() + .run(); assertThat(out, bytes(equalToCompressingWhiteSpace("" + - "\n" + - "Scenario: Test Scenario # path/test.feature:2\n" + - " Given first step # path/step_definitions.java:7\n" + - " \"\"\"\n" + - " {\"key1\": \"value1\",\n" + - " \"key2\": \"value2\",\n" + - " \"another1\": \"another2\"}\n" + - " \"\"\"\n"))); + "\n" + + "Scenario: Test Scenario # path/test.feature:2\n" + + " Given first step # path/step_definitions.java:7\n" + + " \"\"\"\n" + + " {\"key1\": \"value1\",\n" + + " \"key2\": \"value2\",\n" + + " \"another1\": \"another2\"}\n" + + " \"\"\"\n"))); } @Test void should_print_docstring_including_content_type() { Feature feature = TestFeatureParser.parse("path/test.feature", "" + - "Feature: Test feature\n" + - " Scenario: Test Scenario\n" + - " Given first step\n" + - " \"\"\"json\n" + - " {\"key1\": \"value1\",\n" + - " \"key2\": \"value2\",\n" + - " \"another1\": \"another2\"}\n" + - " \"\"\"\n"); + "Feature: Test feature\n" + + " Scenario: Test Scenario\n" + + " Given first step\n" + + " \"\"\"json\n" + + " {\"key1\": \"value1\",\n" + + " \"key2\": \"value2\",\n" + + " \"another1\": \"another2\"}\n" + + " \"\"\"\n"); ByteArrayOutputStream out = new ByteArrayOutputStream(); Runtime.builder() - .withFeatureSupplier(new StubFeatureSupplier(feature)) - .withAdditionalPlugins(new PrettyFormatter(out)) - .withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()) - .withBackendSupplier(new StubBackendSupplier( - new StubStepDefinition("first step", "path/step_definitions.java:7", DocString.class))) - .build() - .run(); + .withFeatureSupplier(new StubFeatureSupplier(feature)) + .withAdditionalPlugins(new PrettyFormatter(out)) + .withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()) + .withBackendSupplier(new StubBackendSupplier( + new StubStepDefinition("first step", "path/step_definitions.java:7", DocString.class))) + .build() + .run(); assertThat(out, bytes(equalToCompressingWhiteSpace("" + - "\n" + - "Scenario: Test Scenario # path/test.feature:2\n" + - " Given first step # path/step_definitions.java:7\n" + - " \"\"\"json\n" + - " {\"key1\": \"value1\",\n" + - " \"key2\": \"value2\",\n" + - " \"another1\": \"another2\"}\n" + - " \"\"\"\n"))); + "\n" + + "Scenario: Test Scenario # path/test.feature:2\n" + + " Given first step # path/step_definitions.java:7\n" + + " \"\"\"json\n" + + " {\"key1\": \"value1\",\n" + + " \"key2\": \"value2\",\n" + + " \"another1\": \"another2\"}\n" + + " \"\"\"\n"))); } } From 9e658c0ff6ed5658072285645c60a9097a62c908 Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Sun, 12 Jan 2025 18:45:04 +0100 Subject: [PATCH 3/5] Extract DocStringFormatter --- .../cucumber/core/plugin/PrettyFormatter.java | 22 ++++--- .../core/plugin/PrettyFormatterTest.java | 33 ---------- .../java/io/cucumber/docstring/DocString.java | 10 +-- .../docstring/DocStringFormatter.java | 64 +++++++++++++++++++ .../docstring/DocStringFormatterTest.java | 64 +++++++++++++++++++ .../io/cucumber/docstring/DocStringTest.java | 16 ++--- ...ingTypeRegistryDocStringConverterTest.java | 6 +- 7 files changed, 156 insertions(+), 59 deletions(-) create mode 100644 docstring/src/main/java/io/cucumber/docstring/DocStringFormatter.java create mode 100644 docstring/src/test/java/io/cucumber/docstring/DocStringFormatterTest.java diff --git a/cucumber-core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java b/cucumber-core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java index 973254bb35..a0bb1b74c9 100644 --- a/cucumber-core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java +++ b/cucumber-core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java @@ -5,6 +5,8 @@ import io.cucumber.core.gherkin.DocStringArgument; import io.cucumber.datatable.DataTable; import io.cucumber.datatable.DataTableFormatter; +import io.cucumber.docstring.DocString; +import io.cucumber.docstring.DocStringFormatter; import io.cucumber.plugin.ColorAware; import io.cucumber.plugin.ConcurrentEventListener; import io.cucumber.plugin.event.Argument; @@ -149,21 +151,25 @@ private void printStep(TestStepFinished event) { .escapeDelimiters(false) .build(); DataTableArgument dataTableArgument = (DataTableArgument) stepArgument; + DataTable table = DataTable.create(dataTableArgument.cells()); try { - tableFormatter.formatTo(DataTable.create(dataTableArgument.cells()), out); + tableFormatter.formatTo(table, out); } catch (IOException e) { throw new CucumberException(e); } } else if (stepArgument instanceof DocStringArgument) { + DocStringFormatter docStringFormatter = DocStringFormatter + .builder() + .indentation(STEP_SCENARIO_INDENT) + .build(); DocStringArgument docStringArgument = (DocStringArgument) stepArgument; - String contentType = docStringArgument.getContentType(); - String printableContentType = contentType == null ? "" : contentType; - out.println(STEP_INDENT + "\"\"\"" + printableContentType); - for (String l : docStringArgument.getContent().split("\\r?\\n|\\r")) { - String s = STEP_INDENT + l; - out.println(s); + DocString docString = DocString.create(docStringArgument.getContent(), + docStringArgument.getContentType()); + try { + docStringFormatter.formatTo(docString, out); + } catch (IOException e) { + throw new CucumberException(e); } - out.println(STEP_INDENT + "\"\"\""); } } } diff --git a/cucumber-core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java b/cucumber-core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java index 3ef77eedd7..4a27d0cfe3 100755 --- a/cucumber-core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java +++ b/cucumber-core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java @@ -612,39 +612,6 @@ void should_print_system_failure_for_failed_hooks() { " " + AnsiEscapes.RED + "the stack trace" + AnsiEscapes.RESET))); } - @Test - void should_print_docstring_without_content_type() { - Feature feature = TestFeatureParser.parse("path/test.feature", "" + - "Feature: Test feature\n" + - " Scenario: Test Scenario\n" + - " Given first step\n" + - " \"\"\"\n" + - " {\"key1\": \"value1\",\n" + - " \"key2\": \"value2\",\n" + - " \"another1\": \"another2\"}\n" + - " \"\"\"\n"); - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - Runtime.builder() - .withFeatureSupplier(new StubFeatureSupplier(feature)) - .withAdditionalPlugins(new PrettyFormatter(out)) - .withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()) - .withBackendSupplier(new StubBackendSupplier( - new StubStepDefinition("first step", "path/step_definitions.java:7", DocString.class))) - .build() - .run(); - - assertThat(out, bytes(equalToCompressingWhiteSpace("" + - "\n" + - "Scenario: Test Scenario # path/test.feature:2\n" + - " Given first step # path/step_definitions.java:7\n" + - " \"\"\"\n" + - " {\"key1\": \"value1\",\n" + - " \"key2\": \"value2\",\n" + - " \"another1\": \"another2\"}\n" + - " \"\"\"\n"))); - } - @Test void should_print_docstring_including_content_type() { Feature feature = TestFeatureParser.parse("path/test.feature", "" + diff --git a/docstring/src/main/java/io/cucumber/docstring/DocString.java b/docstring/src/main/java/io/cucumber/docstring/DocString.java index 852062db40..992661667a 100644 --- a/docstring/src/main/java/io/cucumber/docstring/DocString.java +++ b/docstring/src/main/java/io/cucumber/docstring/DocString.java @@ -5,9 +5,7 @@ import java.lang.reflect.Type; import java.util.Objects; -import static java.util.Arrays.stream; import static java.util.Objects.requireNonNull; -import static java.util.stream.Collectors.joining; /** * A doc string. For example: @@ -81,11 +79,9 @@ public boolean equals(Object o) { @Override public String toString() { - return stream(content.split("\n")) - .collect(joining( - "\n ", - " \"\"\"" + contentType + "\n ", - "\n \"\"\"")); + return DocStringFormatter.builder() + .build() + .format(this); } public interface DocStringConverter { diff --git a/docstring/src/main/java/io/cucumber/docstring/DocStringFormatter.java b/docstring/src/main/java/io/cucumber/docstring/DocStringFormatter.java new file mode 100644 index 0000000000..bee647f4cc --- /dev/null +++ b/docstring/src/main/java/io/cucumber/docstring/DocStringFormatter.java @@ -0,0 +1,64 @@ +package io.cucumber.docstring; + +import org.apiguardian.api.API; + +import java.io.IOException; + +import static java.util.Objects.requireNonNull; + +@API(status = API.Status.EXPERIMENTAL) +public final class DocStringFormatter { + + private final String indentation; + + private DocStringFormatter(String indentation) { + requireNonNull(indentation, "indentation should be null"); + this.indentation = indentation; + } + + public static DocStringFormatter.Builder builder() { + return new Builder(); + } + + public String format(DocString docString) { + StringBuilder result = new StringBuilder(); + formatTo(docString, result); + return result.toString(); + } + + public void formatTo(DocString docString, StringBuilder appendable) { + try { + formatTo(docString, (Appendable) appendable); + } catch (IOException e) { + throw new CucumberDocStringException(e.getMessage(), e); + } + } + + public void formatTo(DocString docString, Appendable out) throws IOException { + String printableContentType = docString.getContentType() == null ? "" : docString.getContentType(); + out.append(indentation).append("\"\"\"").append(printableContentType).append("\n"); + for (String l : docString.getContent().split("\\n")) { + out.append(indentation).append(l).append("\n"); + } + out.append(indentation).append("\"\"\"").append("\n"); + } + + public static final class Builder { + + private String indentation = ""; + + private Builder() { + + } + + public Builder indentation(String indentation) { + requireNonNull(indentation, "indentation should be null"); + this.indentation = indentation; + return this; + } + + public DocStringFormatter build() { + return new DocStringFormatter(indentation); + } + } +} diff --git a/docstring/src/test/java/io/cucumber/docstring/DocStringFormatterTest.java b/docstring/src/test/java/io/cucumber/docstring/DocStringFormatterTest.java new file mode 100644 index 0000000000..ce9841a8fa --- /dev/null +++ b/docstring/src/test/java/io/cucumber/docstring/DocStringFormatterTest.java @@ -0,0 +1,64 @@ +package io.cucumber.docstring; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +class DocStringFormatterTest { + + @Test + void should_print_docstring_with_content_type() { + DocString docString = DocString.create("{\n" + + " \"key1\": \"value1\",\n" + + " \"key2\": \"value2\",\n" + + " \"another1\": \"another2\"\n" + + "}\n", + "application/json"); + + DocStringFormatter formatter = DocStringFormatter.builder().build(); + String format = formatter.format(docString); + assertThat(format, equalTo( + "\"\"\"application/json\n" + + "{\n" + + " \"key1\": \"value1\",\n" + + " \"key2\": \"value2\",\n" + + " \"another1\": \"another2\"\n" + + "}\n" + + "\"\"\"\n")); + } + + @Test + void should_print_docstring_without_content_type() { + DocString docString = DocString.create("{\n" + + " \"key1\": \"value1\",\n" + + " \"key2\": \"value2\",\n" + + " \"another1\": \"another2\"\n" + + "}\n"); + + DocStringFormatter formatter = DocStringFormatter.builder().build(); + String format = formatter.format(docString); + assertThat(format, equalTo( + "\"\"\"\n" + + "{\n" + + " \"key1\": \"value1\",\n" + + " \"key2\": \"value2\",\n" + + " \"another1\": \"another2\"\n" + + "}\n" + + "\"\"\"\n")); + } + + @Test + void should_print_docstring_with_indentation() { + DocString docString = DocString.create("Hello", + "text/plain"); + + DocStringFormatter formatter = DocStringFormatter.builder().indentation(" ").build(); + String format = formatter.format(docString); + assertThat(format, equalTo( + " \"\"\"text/plain\n" + + " Hello\n" + + " \"\"\"\n")); + } + +} diff --git a/docstring/src/test/java/io/cucumber/docstring/DocStringTest.java b/docstring/src/test/java/io/cucumber/docstring/DocStringTest.java index dcf8454d0d..68fd10fba8 100644 --- a/docstring/src/test/java/io/cucumber/docstring/DocStringTest.java +++ b/docstring/src/test/java/io/cucumber/docstring/DocStringTest.java @@ -28,11 +28,11 @@ void pretty_prints_doc_string_objects() { "application/json"); assertThat(docString.toString(), is("" + - " \"\"\"application/json\n" + - " {\n" + - " \"hello\":\"world\"\n" + - " }\n" + - " \"\"\"")); + "\"\"\"application/json\n" + + "{\n" + + " \"hello\":\"world\"\n" + + "}\n" + + "\"\"\"\n")); } @Test @@ -60,9 +60,9 @@ void pretty_prints_empty_doc_string_objects() { "application/json"); assertThat(docString.toString(), is("" + - " \"\"\"application/json\n" + - " \n" + - " \"\"\"")); + "\"\"\"application/json\n" + + "\n" + + "\"\"\"\n")); } } diff --git a/docstring/src/test/java/io/cucumber/docstring/DocStringTypeRegistryDocStringConverterTest.java b/docstring/src/test/java/io/cucumber/docstring/DocStringTypeRegistryDocStringConverterTest.java index 0df1b77bd7..50b02c7fbd 100644 --- a/docstring/src/test/java/io/cucumber/docstring/DocStringTypeRegistryDocStringConverterTest.java +++ b/docstring/src/test/java/io/cucumber/docstring/DocStringTypeRegistryDocStringConverterTest.java @@ -151,9 +151,9 @@ void throws_when_conversion_fails() { () -> converter.convert(docString, JsonNode.class)); assertThat(exception.getMessage(), is(equalToCompressingWhiteSpace("" + "'json' could not transform\n" + - " \"\"\"json\n" + - " {\"hello\":\"world\"}\n" + - " \"\"\""))); + " \"\"\"json\n" + + " {\"hello\":\"world\"}\n" + + " \"\"\""))); } @Test From 384cbd8aa23a8cc6fb35c8a596f93e2dece7b180 Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Sun, 12 Jan 2025 18:47:31 +0100 Subject: [PATCH 4/5] Fix non null messages --- .../main/java/io/cucumber/docstring/DocStringFormatter.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docstring/src/main/java/io/cucumber/docstring/DocStringFormatter.java b/docstring/src/main/java/io/cucumber/docstring/DocStringFormatter.java index bee647f4cc..0909f14d4f 100644 --- a/docstring/src/main/java/io/cucumber/docstring/DocStringFormatter.java +++ b/docstring/src/main/java/io/cucumber/docstring/DocStringFormatter.java @@ -12,7 +12,6 @@ public final class DocStringFormatter { private final String indentation; private DocStringFormatter(String indentation) { - requireNonNull(indentation, "indentation should be null"); this.indentation = indentation; } @@ -27,6 +26,8 @@ public String format(DocString docString) { } public void formatTo(DocString docString, StringBuilder appendable) { + requireNonNull(docString, "docString may not be null"); + requireNonNull(appendable, "appendable may not be null"); try { formatTo(docString, (Appendable) appendable); } catch (IOException e) { @@ -52,7 +53,7 @@ private Builder() { } public Builder indentation(String indentation) { - requireNonNull(indentation, "indentation should be null"); + requireNonNull(indentation, "indentation may not be null"); this.indentation = indentation; return this; } From 1914e5befc5983058bbd02c602e669d082bc7272 Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Sun, 12 Jan 2025 19:13:14 +0100 Subject: [PATCH 5/5] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6adf89359..007f523b4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - [JUnit Platform Engine] Use JUnit Platform 1.11.3 (JUnit Jupiter 5.11.3) -### Fixed +### Added - [Core] Pretty-Print DocStringArgument Step Arguments([#2953](https://github.com/cucumber/cucumber-jvm/pull/2953) Daniel Miladinov) ## [7.20.1] - 2024-10-09