From 03bf6f1865355e294b52d38fc864ca29a1f90100 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Thu, 28 Nov 2024 00:52:17 +0100 Subject: [PATCH] Adopt `AddPropertyComment` in `CommentOutSpringPropertyKey` --- .../spring/CommentOutSpringPropertyKey.java | 4 +-- .../CommentOutSpringPropertyKeyTest.java | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/openrewrite/java/spring/CommentOutSpringPropertyKey.java b/src/main/java/org/openrewrite/java/spring/CommentOutSpringPropertyKey.java index aa81ca615..8fa54ebb4 100644 --- a/src/main/java/org/openrewrite/java/spring/CommentOutSpringPropertyKey.java +++ b/src/main/java/org/openrewrite/java/spring/CommentOutSpringPropertyKey.java @@ -49,9 +49,7 @@ public String getDescription() { @Override public TreeVisitor getVisitor() { - String inlineComment = " # " + comment; - String regex = "(?() { @Override diff --git a/src/test/java/org/openrewrite/java/spring/CommentOutSpringPropertyKeyTest.java b/src/test/java/org/openrewrite/java/spring/CommentOutSpringPropertyKeyTest.java index 3d8782c50..ab27885b0 100644 --- a/src/test/java/org/openrewrite/java/spring/CommentOutSpringPropertyKeyTest.java +++ b/src/test/java/org/openrewrite/java/spring/CommentOutSpringPropertyKeyTest.java @@ -43,7 +43,7 @@ void yamlComment() { } @Test - void shouldInsertInlineCommentsIntoProperties() { + void multipleYamlComments() { rewriteRun( spec -> spec.recipes( new CommentOutSpringPropertyKey("test.propertyKey1", "my comment 1"), @@ -84,6 +84,16 @@ void shouldInsertInlineCommentsIntoProperties() { """ ) ) + ) + ); + } + + @Test + void multiplePropertiesComments() { + rewriteRun( + spec -> spec.recipes( + new CommentOutSpringPropertyKey("test.propertyKey1", "my comment 1"), + new CommentOutSpringPropertyKey("test.propertyKey2", "my comment 2") ), //language=properties properties( @@ -93,18 +103,16 @@ void shouldInsertInlineCommentsIntoProperties() { test.propertyKey3=zzz """, """ - test.propertyKey1=xxx # my comment 1 - test.propertyKey2=yyy # my comment 2 + # my comment 1 + # test.propertyKey1=xxx + # my comment 2 + # test.propertyKey2=yyy test.propertyKey3=zzz """, spec -> spec.path("application.properties") .afterRecipe(file -> - // XXX Right now trailing comments are mapped as part of the value, not as separate comments - assertThat( - ((Properties.Entry) file.getContent().get(1)) - .getValue().getText()) - .isEqualTo("yyy # my comment 2") - ) + assertThat(((Properties.Comment) file.getContent().get(3)).getMessage()) + .isEqualTo(" test.propertyKey2=yyy")) ) ); }