From ccfaca2e7581a3ee82549dc07ad747bd299d726b Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Wed, 8 Feb 2023 14:47:40 +0100 Subject: [PATCH] Simplify tests --- .../BugPatternTestExtractorTest.java | 147 +++++++++--------- 1 file changed, 73 insertions(+), 74 deletions(-) diff --git a/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest.java b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest.java index 208b09ee0eb..87359db1e8e 100644 --- a/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest.java +++ b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest.java @@ -166,10 +166,10 @@ void bugPatternTestSingleReplacement(@TempDir Path outputDirectory) throws IOExc "IdentityConversionTest.java", "package pkg;", "", + "import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH;", + "", "import com.google.errorprone.BugCheckerRefactoringTestHelper;", - "import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers;", "import com.google.errorprone.bugpatterns.BugChecker;", - "import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;", "import com.google.errorprone.CompilationTestHelper;", "import org.junit.jupiter.api.Test;", "", @@ -177,9 +177,8 @@ void bugPatternTestSingleReplacement(@TempDir Path outputDirectory) throws IOExc " private static class IdentityConversion extends BugChecker {}", "", " @Test", - " void replacementFirstSuggestedFix() {", + " void replacement() {", " BugCheckerRefactoringTestHelper.newInstance(IdentityConversion.class, getClass())", - " .setFixChooser(FixChoosers.FIRST)", " .addInputLines(", " \"A.java\",", " \"import com.google.common.collect.ImmutableSet;\",", @@ -198,7 +197,7 @@ void bugPatternTestSingleReplacement(@TempDir Path outputDirectory) throws IOExc " \" ImmutableSet set = ImmutableSet.of();\",", " \" }\",", " \"}\")", - " .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);", + " .doTest(TEXT_MATCH);", " }", "}"); @@ -209,16 +208,16 @@ void bugPatternTestSingleReplacement(@TempDir Path outputDirectory) throws IOExc } @Test - void bugPatternTestMultipleReplacements(@TempDir Path outputDirectory) throws IOException { + void bugPatternTestMultipleReplacementSources(@TempDir Path outputDirectory) throws IOException { JavacTaskCompilation.compile( outputDirectory, "IdentityConversionTest.java", "package pkg;", "", + "import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH;", + "", "import com.google.errorprone.BugCheckerRefactoringTestHelper;", - "import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers;", "import com.google.errorprone.bugpatterns.BugChecker;", - "import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;", "import com.google.errorprone.CompilationTestHelper;", "import org.junit.jupiter.api.Test;", "", @@ -226,22 +225,21 @@ void bugPatternTestMultipleReplacements(@TempDir Path outputDirectory) throws IO " private static class IdentityConversion extends BugChecker {}", "", " @Test", - " void replacementFirstSuggestedFix() {", + " void replacement() {", " BugCheckerRefactoringTestHelper.newInstance(IdentityConversion.class, getClass())", - " .setFixChooser(FixChoosers.FIRST)", - " .addInputLines(", - " \"A.java\",", - " \"public final class A {}\")", - " .addOutputLines(", - " \"A.java\",", - " \"public final class A {}\")", - " .addInputLines(", - " \"B.java\",", - " \"public final class B {}\")", - " .addOutputLines(", - " \"B.java\",", - " \"public final class B {}\")", - " .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);", + " .addInputLines(", + " \"A.java\",", + " \"public final class A {}\")", + " .addOutputLines(", + " \"A.java\",", + " \"public final class A {}\")", + " .addInputLines(", + " \"B.java\",", + " \"public final class B {}\")", + " .addOutputLines(", + " \"B.java\",", + " \"public final class B {}\")", + " .doTest(TEXT_MATCH);", " }", "}"); @@ -258,6 +256,8 @@ void bugPatternReplacementExpectUnchanged(@TempDir Path outputDirectory) throws "IdentityConversionTest.java", "package pkg;", "", + "import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH;", + "", "import com.google.errorprone.BugCheckerRefactoringTestHelper;", "import com.google.errorprone.bugpatterns.BugChecker;", "import org.junit.jupiter.api.Test;", @@ -266,13 +266,13 @@ void bugPatternReplacementExpectUnchanged(@TempDir Path outputDirectory) throws " private static class IdentityConversion extends BugChecker {}", "", " @Test", - " void replacementFirstSuggestedFix() {", + " void replacement() {", " BugCheckerRefactoringTestHelper.newInstance(IdentityConversion.class, getClass())", - " .addInputLines(", - " \"A.java\",", - " \"public final class A {}\")", - " .expectUnchanged()", - " .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);", + " .addInputLines(", + " \"A.java\",", + " \"public final class A {}\")", + " .expectUnchanged()", + " .doTest(TEXT_MATCH);", " }", "}"); @@ -290,10 +290,10 @@ void bugPatternTestIdentificationAndReplacement(@TempDir Path outputDirectory) "IdentityConversionTest.java", "package pkg;", "", + "import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH;", + "", "import com.google.errorprone.BugCheckerRefactoringTestHelper;", - "import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers;", "import com.google.errorprone.bugpatterns.BugChecker;", - "import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;", "import com.google.errorprone.CompilationTestHelper;", "import org.junit.jupiter.api.Test;", "", @@ -315,28 +315,27 @@ void bugPatternTestIdentificationAndReplacement(@TempDir Path outputDirectory) " }", "", " @Test", - " void replacementFirstSuggestedFix() {", + " void replacement() {", " BugCheckerRefactoringTestHelper.newInstance(IdentityConversion.class, getClass())", - " .setFixChooser(FixChoosers.FIRST)", - " .addInputLines(", - " \"A.java\",", - " \"import com.google.common.collect.ImmutableSet;\",", - " \"\",", - " \"public final class A {\",", - " \" public void m() {\",", - " \" ImmutableSet set = ImmutableSet.copyOf(ImmutableSet.of());\",", - " \" }\",", - " \"}\")", - " .addOutputLines(", - " \"A.java\",", - " \"import com.google.common.collect.ImmutableSet;\",", - " \"\",", - " \"public final class A {\",", - " \" public void m() {\",", - " \" ImmutableSet set = ImmutableSet.of();\",", - " \" }\",", - " \"}\")", - " .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);", + " .addInputLines(", + " \"A.java\",", + " \"import com.google.common.collect.ImmutableSet;\",", + " \"\",", + " \"public final class A {\",", + " \" public void m() {\",", + " \" ImmutableSet set = ImmutableSet.copyOf(ImmutableSet.of());\",", + " \" }\",", + " \"}\")", + " .addOutputLines(", + " \"A.java\",", + " \"import com.google.common.collect.ImmutableSet;\",", + " \"\",", + " \"public final class A {\",", + " \" public void m() {\",", + " \" ImmutableSet set = ImmutableSet.of();\",", + " \" }\",", + " \"}\")", + " .doTest(TEXT_MATCH);", " }", "}"); @@ -355,10 +354,10 @@ void bugPatternTestMultipleIdentificationAndReplacement(@TempDir Path outputDire "package pkg;", "", "import static com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers.SECOND;", + "import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH;", "", "import com.google.errorprone.BugCheckerRefactoringTestHelper;", "import com.google.errorprone.bugpatterns.BugChecker;", - "import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;", "import com.google.errorprone.CompilationTestHelper;", "import org.junit.jupiter.api.Test;", "", @@ -414,32 +413,32 @@ void bugPatternTestMultipleIdentificationAndReplacement(@TempDir Path outputDire " \" ImmutableSet set = ImmutableSet.of();\",", " \" }\",", " \"}\")", - " .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);", + " .doTest(TEXT_MATCH);", " }", "", " @Test", " void replacementSecondSuggestedFix() {", " BugCheckerRefactoringTestHelper.newInstance(IdentityConversion.class, getClass())", - " .setFixChooser(SECOND)", - " .addInputLines(", - " \"B.java\",", - " \"import com.google.common.collect.ImmutableSet;\",", - " \"\",", - " \"public final class B {\",", - " \" public void m() {\",", - " \" ImmutableSet set = ImmutableSet.copyOf(ImmutableSet.of());\",", - " \" }\",", - " \"}\")", - " .addOutputLines(", - " \"B.java\",", - " \"import com.google.common.collect.ImmutableSet;\",", - " \"\",", - " \"public final class B {\",", - " \" public void m() {\",", - " \" ImmutableSet set = ImmutableSet.of();\",", - " \" }\",", - " \"}\")", - " .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);", + " .setFixChooser(SECOND)", + " .addInputLines(", + " \"B.java\",", + " \"import com.google.common.collect.ImmutableSet;\",", + " \"\",", + " \"public final class B {\",", + " \" public void m() {\",", + " \" ImmutableSet set = ImmutableSet.copyOf(ImmutableSet.of());\",", + " \" }\",", + " \"}\")", + " .addOutputLines(", + " \"B.java\",", + " \"import com.google.common.collect.ImmutableSet;\",", + " \"\",", + " \"public final class B {\",", + " \" public void m() {\",", + " \" ImmutableSet set = ImmutableSet.of();\",", + " \" }\",", + " \"}\")", + " .doTest(TEXT_MATCH);", " }", "}");