Skip to content

Commit

Permalink
CORE-97 Collapse replacement tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdinand-swoboda authored and rickie committed Jun 29, 2022
1 parent 9e81d4d commit 1d81508
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 224 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,263 +96,73 @@ void identification() {
}

@Test
void replacementInImmutableInterface() {
void replacementInImmutable() {
refactoringTestHelper
.addInputLines(
"A.java",
"import org.immutables.value.Value;",
"import com.google.common.collect.ImmutableSortedSet;",
"",
"@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",
"import org.immutables.value.Value;",
"import com.google.common.collect.ImmutableSortedSet;",
"",
"@Value.Immutable",
"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 class A {",
" abstract ImmutableSortedSet<String> sortedSet();",
" ImmutableSortedSet<String> defaultSortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.Default",
" ImmutableSortedSet<String> defaultSortedSet2() {",
" return ImmutableSortedSet.of();",
"",
" @Value.Immutable",
" interface B {",
" ImmutableSortedSet<String> sortedSet();",
" }",
" @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 {",
"abstract class A {",
" @Value.NaturalOrder",
" abstract ImmutableSortedSet<String> sortedSet();",
" ImmutableSortedSet<String> defaultSortedSet() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.Default",
" ImmutableSortedSet<String> defaultSortedSet2() {",
" return ImmutableSortedSet.of();",
"",
" @Value.Immutable",
" interface B {",
" @Value.NaturalOrder",
" ImmutableSortedSet<String> sortedSet();",
" }",
" @Value.NaturalOrder",
" abstract ImmutableSortedSet<String> defaultSortedSet3();",
"}")
.doTest(TestMode.TEXT_MATCH);
}

@Test
void replacementInModifiableAbstractClass() {
void replacementInModifiable() {
refactoringTestHelper
.addInputLines(
"A.java",
"import org.immutables.value.Value;",
"import com.google.common.collect.ImmutableSortedSet;",
"",
"@Value.Modifiable",
"abstract class D {",
"abstract class A {",
" 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.Modifiable",
" interface B {",
" ImmutableSortedSet<String> sortedSet();",
" }",
" @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();",
" }",
"abstract class A {",
" @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.Modifiable",
" interface B {",
" @Value.NaturalOrder",
" ImmutableSortedSet<String> sortedSet();",
" }",
" @Value.Default",
" ImmutableSortedSet<String> defaultSortedSet2() {",
" return ImmutableSortedSet.of();",
" }",
" @Value.NaturalOrder",
" abstract ImmutableSortedSet<String> defaultSortedSet3();",
"}")
.doTest(TestMode.TEXT_MATCH);
}
Expand Down

0 comments on commit 1d81508

Please sign in to comment.