diff --git a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ModifiedTraitTest.java b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ModifiedTraitTest.java index 41fac09053f..5e0aa9f6cf2 100644 --- a/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ModifiedTraitTest.java +++ b/smithy-diff/src/test/java/software/amazon/smithy/diff/evaluators/ModifiedTraitTest.java @@ -25,7 +25,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; -import java.util.logging.Logger; import java.util.stream.Collectors; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -203,9 +202,7 @@ public void findsDifferencesInListTraitValues() { .assemble() .unwrap(); List events = TestHelper.findEvents(ModelDiff.compare(modelA, modelB), "ModifiedTrait"); - List messages = events.stream().map(ValidationEvent::getMessage) - .map(message -> message.replaceAll("\r\n", "\n")) // normalize line separators - .collect(Collectors.toList()); + List messages = events.stream().map(ValidationEvent::getMessage).collect(Collectors.toList()); assertThat(events, hasSize(4)); assertThat(events.stream().filter(e -> e.getMessage().contains("Removed")) @@ -216,10 +213,14 @@ public void findsDifferencesInListTraitValues() { "Changed trait contents of `smithy.example#aTrait` at path `/foo/1` from `b` to `B`", "Added trait contents to `smithy.example#aTrait` at path `/foo/3` with value `4`", "Removed trait contents from `smithy.example#aTrait` at path `/foo/2`. Removed value: `3`", - "Removed trait contents from `smithy.example#aTrait` at path `/foo`. Removed value: \n" - + "```\n" - + "[\n \"1\",\n \"2\",\n \"3\"\n]\n" - + "```" + String.format("Removed trait contents from `smithy.example#aTrait` at path `/foo`. Removed value: %n" + + "```%n" + + "[%n" + + " \"1\",%n" + + " \"2\",%n" + + " \"3\"%n" + + "]%n" + + "```%n") )); } @@ -234,9 +235,7 @@ public void findsDifferencesInSetTraitValues() { .assemble() .unwrap(); List events = TestHelper.findEvents(ModelDiff.compare(modelA, modelB), "ModifiedTrait"); - List messages = events.stream().map(ValidationEvent::getMessage) - .map(message -> message.replaceAll("\r\n", "\n")) // normalize line separators - .collect(Collectors.toList()); + List messages = events.stream().map(ValidationEvent::getMessage).collect(Collectors.toList()); assertThat(events, hasSize(4)); assertThat(events.stream().filter(e -> e.getMessage().contains("Removed")) @@ -247,11 +246,15 @@ public void findsDifferencesInSetTraitValues() { "Changed trait contents of `smithy.example#aTrait` at path `/foo/1` from `b` to `B`", "Added trait contents to `smithy.example#aTrait` at path `/foo/3` with value `4`", "Removed trait contents from `smithy.example#aTrait` at path `/foo/2`. Removed value: `3`", - "Removed trait contents from `smithy.example#aTrait` at path `/foo`. " - + "Removed value: \n" - + "```\n" - + "[\n \"1\",\n \"2\",\n \"3\"\n]\n" - + "```" + String.format("Removed trait contents from `smithy.example#aTrait` at path `/foo`. " + + "Removed value: %n" + + "```%n" + + "[%n" + + " \"1\",%n" + + " \"2\",%n" + + " \"3\"%n" + + "]%n" + + "```%n") )); } @@ -266,9 +269,7 @@ public void findsDifferencesInMapTraitValues() { .assemble() .unwrap(); List events = TestHelper.findEvents(ModelDiff.compare(modelA, modelB), "ModifiedTrait"); - List messages = events.stream().map(ValidationEvent::getMessage) - .map(message -> message.replaceAll("\r\n", "\n")) // normalize line separators - .collect(Collectors.toList()); + List messages = events.stream().map(ValidationEvent::getMessage).collect(Collectors.toList()); assertThat(events, hasSize(4)); assertThat(events.stream().filter(e -> e.getMessage().contains("Removed")) @@ -277,11 +278,15 @@ public void findsDifferencesInMapTraitValues() { .filter(e -> e.getSourceLocation().getFilename().endsWith("b.smithy")).count(), equalTo(2L)); assertThat(messages, containsInAnyOrder( "Changed trait contents of `smithy.example#aTrait` at path `/foo/bam` from `b` to `B`", - "Removed trait contents from `smithy.example#aTrait` at path `/foo`. " - + "Removed value: \n" - + "```\n" - + "{\n \"baz\": \"1\",\n \"bam\": \"2\",\n \"boo\": \"3\"\n}\n" - + "```", + String.format("Removed trait contents from `smithy.example#aTrait` at path `/foo`. " + + "Removed value: %n" + + "```%n" + + "{%n" + + " \"baz\": \"1\",%n" + + " \"bam\": \"2\",%n" + + " \"boo\": \"3\"%n" + + "}%n" + + "```%n"), "Added trait contents to `smithy.example#aTrait` at path `/foo/qux` with value `4`", "Removed trait contents from `smithy.example#aTrait` at path `/foo/boo`. Removed value: `3`" )); diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationUtils.java b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationUtils.java index 6b96a0f7955..1f6f5ee8075 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationUtils.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/validation/ValidationUtils.java @@ -99,9 +99,7 @@ public static String tickedList(Stream values) { public static String tickedPrettyPrintedNode(Node node) { String prettyPrinted = Node.prettyPrintJson(node); if (prettyPrinted.contains(System.lineSeparator()) || prettyPrinted.contains("\n")) { - return System.lineSeparator() + "```" + System.lineSeparator() - + prettyPrinted + System.lineSeparator() - + "```"; + return String.format("%n```%n%s%n```%n", prettyPrinted); } else if (prettyPrinted.startsWith("\"") && prettyPrinted.endsWith("\"")) { // for pure strings, replace the quotes with backticks return "`" + prettyPrinted.substring(1, prettyPrinted.length() - 1) + "`";