Skip to content

Commit

Permalink
Fix indentation of comments in failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Nov 26, 2024
1 parent b3accdc commit 7b17b02
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
.map(TextComment.class::cast)
.noneMatch(c -> comment.equals(c.getText()))) {

TextComment textComment = new TextComment(isMultiline, comment, md.getPrefix().getWhitespace(), Markers.EMPTY);
TextComment textComment = new TextComment(Boolean.TRUE.equals(isMultiline), comment, md.getPrefix().getWhitespace(), Markers.EMPTY);
return md.withComments(ListUtils.concat(comments, textComment));
}
return md;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,23 @@
*/
package org.openrewrite.java;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import static org.openrewrite.java.Assertions.java;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import static org.openrewrite.java.Assertions.java;

class AddCommentToMethodTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
}
private static final String SHORT_COMMENT = " Short comment to add";
private static final String LONG_COMMENT = " This is a very long comment to add. The comment uses multiline comments, not single line.";

@DocumentExample
@Test
void addSingleLineComment() {
rewriteRun(
spec -> spec.recipe(new AddCommentToMethod(" Short comment to add", "foo.Foo bar(..)", false)),
spec -> spec.recipe(new AddCommentToMethod(SHORT_COMMENT, "foo.Foo bar(..)", false)),
//language=java
java(
"""
Expand All @@ -52,11 +51,10 @@ public void bar(String arg) {}
);
}

@DocumentExample
@Test
void addLongComment() {
rewriteRun(
spec -> spec.recipe(new AddCommentToMethod(" This is a very long comment to add. The comment uses multiline comments, not single line.", "foo.Foo bar(..)", true)),
spec -> spec.recipe(new AddCommentToMethod(LONG_COMMENT, "foo.Foo bar(..)", true)),
//language=java
java(
"""
Expand All @@ -76,11 +74,10 @@ public void bar(String arg) {}
);
}

@DocumentExample
@Test
void addSingleLineCommentToExistingSingleLineComments() {
rewriteRun(
spec -> spec.recipe(new AddCommentToMethod(" Short comment to add", "foo.Foo bar(..)", false)),
spec -> spec.recipe(new AddCommentToMethod(SHORT_COMMENT, "foo.Foo bar(..)", false)),
//language=java
java(
"""
Expand All @@ -104,65 +101,61 @@ public void bar(String arg) {}
);
}

@DocumentExample
@Test
@Disabled("This test fails due to \\ No newline at end of file https://github.com/openrewrite/rewrite/issues/4344")
void addSingleLineCommentToExistingMultiLineComment() {
rewriteRun(
spec -> spec.recipe(new AddCommentToMethod(" Short comment to add", "foo.Foo bar(..)", false)),
spec -> spec.recipe(new AddCommentToMethod(SHORT_COMMENT, "foo.Foo bar(..)", false)),
//language=java
java(
"""
package foo;
public class Foo {
/**
* Existing multi line
* comment
*/
* Existing multi line
* comment
*/
public void bar(String arg) {}
}
""",
"""
package foo;
public class Foo {
/**
* Existing multi line
* comment
*/
// Short comment to add
/**
* Existing multi line
* comment
*/
// Short comment to add
public void bar(String arg) {}
}
"""
)
);
}

@DocumentExample
@Test
@Disabled("This test fails due to \\ No newline at end of file https://github.com/openrewrite/rewrite/issues/4344")
void addLongCommentToExistingMultiLineComment() {
rewriteRun(
spec -> spec.recipe(new AddCommentToMethod(" This is a very long comment to add. The comment uses multiline comments, not single line.", "foo.Foo bar(..)", true)),
spec -> spec.recipe(new AddCommentToMethod(LONG_COMMENT, "foo.Foo bar(..)", true)),
//language=java
java(
"""
package foo;
public class Foo {
/**
* Existing multi line
* comment
*/
* Existing multi line
* comment
*/
public void bar(String arg) {}
}
""",
"""
package foo;
public class Foo {
/**
* Existing multi line
* comment
*/
/* This is a very long comment to add. The comment uses multiline comments, not single line.*/
/**
* Existing multi line
* comment
*/
/* This is a very long comment to add. The comment uses multiline comments, not single line.*/
public void bar(String arg) {}
}
"""
Expand Down

0 comments on commit 7b17b02

Please sign in to comment.