Skip to content

Commit

Permalink
CORE-97 Revert redundant replacement tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdinand-swoboda committed Jun 14, 2022
1 parent a0eaa51 commit 8316c1a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.google.errorprone.fixes.SuggestedFix;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.matchers.Matcher;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.MethodTree;
import com.sun.source.tree.Tree;
import org.immutables.value.Value.Immutable;
Expand Down Expand Up @@ -63,16 +62,11 @@ public Description matchMethod(MethodTree tree, VisitorState state) {
// The ImmutableSortedSet has no empty default -> add the `@Value.NaturalOrder` annotation or
// provide a default implementation.
return buildDescription(tree)
.setMessage(
"Methods returning an `ImmutableSortedSet` within an @Value.Immutable or @Value.Modifiable class "
+ "should include additional deserialization information for absent sets. "
+ "Alternatively, specify a default implementation.")
.addFix(SuggestedFix.builder().prefixWith(tree, "@Value.NaturalOrder ").build())
.addFix(
SuggestedFix.builder()
.replace(
ASTHelpers.getStartPosition(tree), ASTHelpers.getStartPosition(tree) + 8, "")
.replace(
state.getEndPosition(tree) - 1,
state.getEndPosition(tree),
"{ return ImmutableSortedSet.of(); }")
.build())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package tech.picnic.errorprone.bugpatterns;

import static com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers.SECOND;

import com.google.errorprone.BugCheckerRefactoringTestHelper;
import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
import com.google.errorprone.CompilationTestHelper;
Expand Down Expand Up @@ -98,7 +96,7 @@ void identification() {
}

@Test
void replacementInImmutableInterface() {
void replacement() {
refactoringTestHelper
.addInputLines(
"A.java",
Expand All @@ -108,15 +106,6 @@ void replacementInImmutableInterface() {
"@Value.Immutable",
"interface A {",
" ImmutableSortedSet<String> sortedSet();",
" default ImmutableSortedSet<String> defaultSortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.Default",
" default ImmutableSortedSet<String> defaultSortedSet2() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.NaturalOrder",
" ImmutableSortedSet<String> defaultSortedSet3();",
"}")
.addOutputLines(
"A.java",
Expand All @@ -127,274 +116,6 @@ void replacementInImmutableInterface() {
"interface A {",
" @Value.NaturalOrder",
" ImmutableSortedSet<String> sortedSet();",
" default ImmutableSortedSet<String> defaultSortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.Default",
" default ImmutableSortedSet<String> defaultSortedSet2() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.NaturalOrder",
" ImmutableSortedSet<String> defaultSortedSet3();",
"}")
.doTest(TestMode.TEXT_MATCH);
}

@Test
void replacementInModifiableInterface() {
refactoringTestHelper
.addInputLines(
"A.java",
"import org.immutables.value.Value;",
"import com.google.common.collect.ImmutableSortedSet;",
"",
"@Value.Modifiable",
"interface B {",
" ImmutableSortedSet<String> sortedSet();",
" default ImmutableSortedSet<String> defaultSortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.Default",
" default ImmutableSortedSet<String> defaultSortedSet2() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.NaturalOrder",
" ImmutableSortedSet<String> defaultSortedSet3();",
"}")
.addOutputLines(
"A.java",
"import org.immutables.value.Value;",
"import com.google.common.collect.ImmutableSortedSet;",
"",
"@Value.Modifiable",
"interface B {",
" @Value.NaturalOrder",
" ImmutableSortedSet<String> sortedSet();",
" default ImmutableSortedSet<String> defaultSortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.Default",
" default ImmutableSortedSet<String> defaultSortedSet2() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.NaturalOrder",
" ImmutableSortedSet<String> defaultSortedSet3();",
"}")
.doTest(TestMode.TEXT_MATCH);
}

@Test
void replacementInImmutableAbstractClass() {
refactoringTestHelper
.addInputLines(
"A.java",
"import org.immutables.value.Value;",
"import com.google.common.collect.ImmutableSortedSet;",
"",
"@Value.Immutable",
"abstract class C {",
" abstract ImmutableSortedSet<String> sortedSet();",
" ImmutableSortedSet<String> defaultSortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.Default",
" ImmutableSortedSet<String> defaultSortedSet2() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.NaturalOrder",
" abstract ImmutableSortedSet<String> defaultSortedSet3();",
"}")
.addOutputLines(
"A.java",
"import org.immutables.value.Value;",
"import com.google.common.collect.ImmutableSortedSet;",
"",
"@Value.Immutable",
"abstract class C {",
" @Value.NaturalOrder",
" abstract ImmutableSortedSet<String> sortedSet();",
" ImmutableSortedSet<String> defaultSortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.Default",
" ImmutableSortedSet<String> defaultSortedSet2() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.NaturalOrder",
" abstract ImmutableSortedSet<String> defaultSortedSet3();",
"}")
.doTest(TestMode.TEXT_MATCH);
}

@Test
void replacementInModifiableAbstractClass() {
refactoringTestHelper
.addInputLines(
"A.java",
"import org.immutables.value.Value;",
"import com.google.common.collect.ImmutableSortedSet;",
"",
"@Value.Modifiable",
"abstract class D {",
" abstract ImmutableSortedSet<String> sortedSet();",
" ImmutableSortedSet<String> defaultSortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.Default",
" ImmutableSortedSet<String> defaultSortedSet2() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.NaturalOrder",
" abstract ImmutableSortedSet<String> defaultSortedSet3();",
"}")
.addOutputLines(
"A.java",
"import org.immutables.value.Value;",
"import com.google.common.collect.ImmutableSortedSet;",
"",
"@Value.Modifiable",
"abstract class D {",
" @Value.NaturalOrder",
" abstract ImmutableSortedSet<String> sortedSet();",
" ImmutableSortedSet<String> defaultSortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.Default",
" ImmutableSortedSet<String> defaultSortedSet2() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.NaturalOrder",
" abstract ImmutableSortedSet<String> defaultSortedSet3();",
"}")
.doTest(TestMode.TEXT_MATCH);
}

@Test
void secondaryReplacementInModifiableInterface() {
refactoringTestHelper
.setFixChooser(SECOND)
.addInputLines(
"A.java",
"import org.immutables.value.Value;",
"import com.google.common.collect.ImmutableSortedSet;",
"",
"@Value.Modifiable",
"interface B {",
" ImmutableSortedSet<String> sortedSet();",
" default ImmutableSortedSet<String> defaultSortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.Default",
" default ImmutableSortedSet<String> defaultSortedSet2() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.NaturalOrder",
" ImmutableSortedSet<String> defaultSortedSet3();",
"}")
.addOutputLines(
"A.java",
"import org.immutables.value.Value;",
"import com.google.common.collect.ImmutableSortedSet;",
"",
"@Value.Modifiable",
"interface B {",
" default ImmutableSortedSet<String> sortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" default ImmutableSortedSet<String> defaultSortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.Default",
" default ImmutableSortedSet<String> defaultSortedSet2() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.NaturalOrder",
" ImmutableSortedSet<String> defaultSortedSet3();",
"}")
.doTest(TestMode.TEXT_MATCH);
}

@Test
void secondaryReplacementInImmutableAbstractClass() {
refactoringTestHelper
.setFixChooser(SECOND)
.addInputLines(
"A.java",
"import org.immutables.value.Value;",
"import com.google.common.collect.ImmutableSortedSet;",
"",
"@Value.Immutable",
"abstract class C {",
" abstract ImmutableSortedSet<String> sortedSet();",
" ImmutableSortedSet<String> defaultSortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.Default",
" ImmutableSortedSet<String> defaultSortedSet2() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.NaturalOrder",
" abstract ImmutableSortedSet<String> defaultSortedSet3();",
"}")
.addOutputLines(
"A.java",
"import org.immutables.value.Value;",
"import com.google.common.collect.ImmutableSortedSet;",
"",
"@Value.Immutable",
"abstract class C {",
" ImmutableSortedSet<String> sortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" ImmutableSortedSet<String> defaultSortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.Default",
" ImmutableSortedSet<String> defaultSortedSet2() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.NaturalOrder",
" abstract ImmutableSortedSet<String> defaultSortedSet3();",
"}")
.doTest(TestMode.TEXT_MATCH);
}

@Test
void noReplacementInNormalClass() {
refactoringTestHelper
.addInputLines(
"A.java",
"import org.immutables.value.Value;",
"import com.google.common.collect.ImmutableSortedSet;",
"",
"abstract class E {",
" abstract ImmutableSortedSet<String> sortedSet();",
" ImmutableSortedSet<String> defaultSortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.Default",
" ImmutableSortedSet<String> defaultSortedSet2() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.NaturalOrder",
" abstract ImmutableSortedSet<String> defaultSortedSet3();",
"}")
.addOutputLines(
"A.java",
"import org.immutables.value.Value;",
"import com.google.common.collect.ImmutableSortedSet;",
"",
"abstract class E {",
" abstract ImmutableSortedSet<String> sortedSet();",
" ImmutableSortedSet<String> defaultSortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.Default",
" ImmutableSortedSet<String> defaultSortedSet2() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.NaturalOrder",
" abstract ImmutableSortedSet<String> defaultSortedSet3();",
"}")
.doTest(TestMode.TEXT_MATCH);
}
Expand Down

0 comments on commit 8316c1a

Please sign in to comment.