diff --git a/spring-modulith-apt/src/test/java/org/springframework/modulith/apt/SpringModulithProcessorUnitTests.java b/spring-modulith-apt/src/test/java/org/springframework/modulith/apt/SpringModulithProcessorUnitTests.java index ea4daf2d6..94887f08c 100644 --- a/spring-modulith-apt/src/test/java/org/springframework/modulith/apt/SpringModulithProcessorUnitTests.java +++ b/spring-modulith-apt/src/test/java/org/springframework/modulith/apt/SpringModulithProcessorUnitTests.java @@ -24,8 +24,11 @@ import io.toolisticon.cute.CuteApi.DoCustomAssertions; import java.io.File; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import org.junit.jupiter.api.Test; +import org.springframework.boot.json.BasicJsonParser; import com.jayway.jsonpath.JsonPath; @@ -71,6 +74,27 @@ void extractsJavadocFromMethodWithClassNestedInInterfaceAsParameter() { }); } + @Test // GH-1685 + void javadocWithDoubleQuotesProducesValidJson() throws Exception { + + assertSucceded(getSourceFile("SampleComponentWithQuotes")); + + var content = Files.readString(new File(JSON_LOCATION).toPath(), StandardCharsets.UTF_8); + + assertThatNoException() + .as("BasicJsonParser must be able to parse the generated JSON without errors") + .isThrownBy(() -> new BasicJsonParser().parseList(content)); + + var context = JsonPath.parse(new File(JSON_LOCATION)); + var comment = context.read( + "$[?(@.name == 'example.SampleComponentWithQuotes')].methods[0].comment", + String[].class)[0]; + + assertThat(comment) + .as("Javadoc comment must preserve literal double-quote characters") + .contains("\"foo\"", "\"bar\""); + } + @Test // GH-1430 void extractsPackageComments() throws Exception { diff --git a/spring-modulith-apt/src/test/resources/example/SampleComponentWithQuotes.java b/spring-modulith-apt/src/test/resources/example/SampleComponentWithQuotes.java new file mode 100644 index 000000000..11798591a --- /dev/null +++ b/spring-modulith-apt/src/test/resources/example/SampleComponentWithQuotes.java @@ -0,0 +1,16 @@ +package example; + +/** + * Component whose method Javadoc contains literal double-quote characters. + */ +class SampleComponentWithQuotes { + + /** + * Finds something by key. Example: + * + *
+	 * findByKey("foo", "bar")
+	 * 
+ */ + void findByKey(String a, String b) {} +}