From 8a9c219a3315fd2b81182a5ae1a304082ca2bbf4 Mon Sep 17 00:00:00 2001 From: Benedek Halasi Date: Thu, 18 May 2023 19:01:10 +0200 Subject: [PATCH] Cannot verify whitespace related requirements as `TestMode.TEXT_MATCH` formats the sources --- .../bugpatterns/MemberOrderingTest.java | 119 +++++++++++++++--- 1 file changed, 105 insertions(+), 14 deletions(-) diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MemberOrderingTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MemberOrderingTest.java index a45e3ec74e8..6642fa35b28 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MemberOrderingTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MemberOrderingTest.java @@ -129,14 +129,12 @@ void replacementFirstSuggestedFix() { .doTest(TestMode.TEXT_MATCH); } - @SuppressWarnings("ErrorProneTestHelperSourceFormat") @Test void replacementSecondSuggestedFix() { BugCheckerRefactoringTestHelper.newInstance(MemberOrdering.class, getClass()) .setFixChooser(SECOND) .addInputLines( "A.java", - "", "class A {", " private static final int X = 1;", " char a = 'a';", @@ -145,7 +143,7 @@ void replacementSecondSuggestedFix() { "", " void m2() {}", "", - " public A () {}", + " public A() {}", "", " private static String BAR = \"bar\";", " char b = 'b';", @@ -153,9 +151,11 @@ void replacementSecondSuggestedFix() { " void m1() {", " System.out.println(\"foo\");", " }", + "", " static int TWO = 2;", "", " class Inner {}", + "", " static class StaticInner {}", "}") .addOutputLines( @@ -171,48 +171,49 @@ void replacementSecondSuggestedFix() { " char a = 'a';", "", " char b = 'b';", - " public A () {}", + "", + " public A() {}", "", " void m2() {}", + "", " void m1() {", " System.out.println(\"foo\");", " }", "", " class Inner {}", + "", " static class StaticInner {}", "}") .doTest(TestMode.TEXT_MATCH); } - @SuppressWarnings("ErrorProneTestHelperSourceFormat") @Test - void replacementSecondSuggestedFixWithDefaultConstructor() { + void replacementSecondSuggestedFixConsidersDefaultConstructor() { BugCheckerRefactoringTestHelper.newInstance(MemberOrdering.class, getClass()) .setFixChooser(SECOND) .addInputLines( "A.java", - "", "class A {", - " void m1 () {}", + " void m1() {}", + "", " char c = 'c';", " private static final String foo = \"foo\";", " static int one = 1;", "}") .addOutputLines( "A.java", - "", "class A {", " private static final String foo = \"foo\";", " static int one = 1;", " char c = 'c';", - " void m1 () {}", + "", + " void m1() {}", "}") .doTest(TestMode.TEXT_MATCH); } - @SuppressWarnings("ErrorProneTestHelperSourceFormat") @Test - void replacementSecondSuggestedFixWithComments() { + void replacementSecondSuggestedFixConsidersComments() { BugCheckerRefactoringTestHelper.newInstance(MemberOrdering.class, getClass()) .setFixChooser(SECOND) .addInputLines( @@ -223,16 +224,18 @@ void replacementSecondSuggestedFixWithComments() { " // Print line 'foo' to stdout.", " System.out.println(\"foo\");", " }", + "", " // foo", " /** Instantiates a new {@link A} instance. */", - " public A () {}", + " public A() {}", "}") .addOutputLines( "A.java", "class A {", " // foo", " /** Instantiates a new {@link A} instance. */", - " public A () {}", + " public A() {}", + "", " // `m1()` comment.", " void m1() {", " // Print line 'foo' to stdout.", @@ -242,6 +245,94 @@ void replacementSecondSuggestedFixWithComments() { .doTest(TestMode.TEXT_MATCH); } + @SuppressWarnings("ErrorProneTestHelperSourceFormat") + @Test + void replacementSecondSuggestedFixDoesNotModifyWhitespace() { + BugCheckerRefactoringTestHelper.newInstance(MemberOrdering.class, getClass()) + .setFixChooser(SECOND) + .addInputLines( + "A.java", + "", + "", + "class A {", + "", + "", + " // `m1()` comment.", + " void m1() {", + " // Print line 'foo' to stdout.", + " System.out.println(\"foo\");", + " }", + " public A () { }", + "", + "", + "}") + .addOutputLines( + "A.java", + "", + "", + "class A {", + "", + "", + "", + " public A () { }", + " // `m1()` comment.", + " void m1() {", + " // Print line 'foo' to stdout.", + " System.out.println(\"foo\");", + " }", + "", + "", + "}") + .doTest(); + } + + @SuppressWarnings("ErrorProneTestHelperSourceFormat") + @Test + void xxx() { // todo: Actually test that the whitespace is preserved. + BugCheckerRefactoringTestHelper.newInstance(MemberOrdering.class, getClass()) + .setFixChooser(SECOND) + .addInputLines( + "A.java", + "", + "", + "class A {", + "", + "", + " // `m1()` comment.", + " void m1() {", + " // Print line 'foo' to stdout.", + " System.out.println(\"foo\");", + " }", + " public A () { }", + "", + "", + "}") + .addOutputLines( + "A.java", + "", + "", + "class A {", + "", + " ", + " ", + " \t \t", + " ", + " ", + "", + " public A () { }", + " // `m1()` comment.", + " void m1", + " ()", + " {", + " // Print line 'foo' to stdout.", + " System.out.println(\"foo\");", + " }", + "", + "", + "}") + .doTest(TestMode.TEXT_MATCH); + } + // todo: Test if second replacement considers annotations. // todo: Chose between with, handles, considers, respects and regards for // replacementSecondSuggestedFixXxxSomething