Skip to content

Commit

Permalink
Simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed Feb 13, 2023
1 parent 1f30ba2 commit 0755f54
Showing 1 changed file with 73 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,19 @@ 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;",
"",
"final class IdentityConversionTest {",
" 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;\",",
Expand All @@ -198,7 +197,7 @@ void bugPatternTestSingleReplacement(@TempDir Path outputDirectory) throws IOExc
" \" ImmutableSet<Object> set = ImmutableSet.of();\",",
" \" }\",",
" \"}\")",
" .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);",
" .doTest(TEXT_MATCH);",
" }",
"}");

Expand All @@ -209,39 +208,38 @@ 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;",
"",
"final class IdentityConversionTest {",
" 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);",
" }",
"}");

Expand All @@ -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;",
Expand All @@ -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);",
" }",
"}");

Expand All @@ -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;",
"",
Expand All @@ -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<Object> set = ImmutableSet.copyOf(ImmutableSet.of());\",",
" \" }\",",
" \"}\")",
" .addOutputLines(",
" \"A.java\",",
" \"import com.google.common.collect.ImmutableSet;\",",
" \"\",",
" \"public final class A {\",",
" \" public void m() {\",",
" \" ImmutableSet<Object> 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<Object> set = ImmutableSet.copyOf(ImmutableSet.of());\",",
" \" }\",",
" \"}\")",
" .addOutputLines(",
" \"A.java\",",
" \"import com.google.common.collect.ImmutableSet;\",",
" \"\",",
" \"public final class A {\",",
" \" public void m() {\",",
" \" ImmutableSet<Object> set = ImmutableSet.of();\",",
" \" }\",",
" \"}\")",
" .doTest(TEXT_MATCH);",
" }",
"}");

Expand All @@ -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;",
"",
Expand Down Expand Up @@ -414,32 +413,32 @@ void bugPatternTestMultipleIdentificationAndReplacement(@TempDir Path outputDire
" \" ImmutableSet<Object> 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<Object> set = ImmutableSet.copyOf(ImmutableSet.of());\",",
" \" }\",",
" \"}\")",
" .addOutputLines(",
" \"B.java\",",
" \"import com.google.common.collect.ImmutableSet;\",",
" \"\",",
" \"public final class B {\",",
" \" public void m() {\",",
" \" ImmutableSet<Object> 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<Object> set = ImmutableSet.copyOf(ImmutableSet.of());\",",
" \" }\",",
" \"}\")",
" .addOutputLines(",
" \"B.java\",",
" \"import com.google.common.collect.ImmutableSet;\",",
" \"\",",
" \"public final class B {\",",
" \" public void m() {\",",
" \" ImmutableSet<Object> set = ImmutableSet.of();\",",
" \" }\",",
" \"}\")",
" .doTest(TEXT_MATCH);",
" }",
"}");

Expand Down

0 comments on commit 0755f54

Please sign in to comment.