Skip to content

Commit

Permalink
Add a note about the use of the guava classpath entry
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed May 11, 2024
1 parent fad2033 commit d188728
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/test/java/com/yourorg/NoGuavaListsNewArrayListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void defaults(RecipeSpec spec) {
spec.recipe(new NoGuavaListsNewArrayList())
.parser(JavaParser.fromJavaVersion()
.logCompilationWarningsAndErrors(true)
// The before/after examples are using Guava classes, so we need to add the Guava library to the classpath
.classpath("guava"));
}

Expand All @@ -52,17 +53,17 @@ void replaceWithNewArrayList() {
java(
"""
import com.google.common.collect.*;
import java.util.List;
class Test {
List<Integer> cardinalsWorldSeries = Lists.newArrayList();
}
""",
"""
import java.util.ArrayList;
import java.util.List;
class Test {
List<Integer> cardinalsWorldSeries = new ArrayList<>();
}
Expand All @@ -78,10 +79,10 @@ void replaceWithNewArrayListIterable() {
java(
"""
import com.google.common.collect.*;
import java.util.Collections;
import java.util.List;
class Test {
List<Integer> l = Collections.emptyList();
List<Integer> cardinalsWorldSeries = Lists.newArrayList(l);
Expand All @@ -91,7 +92,7 @@ class Test {
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Test {
List<Integer> l = Collections.emptyList();
List<Integer> cardinalsWorldSeries = new ArrayList<>(l);
Expand All @@ -108,18 +109,18 @@ void replaceWithNewArrayListWithCapacity() {
java(
"""
import com.google.common.collect.*;
import java.util.ArrayList;
import java.util.List;
class Test {
List<Integer> cardinalsWorldSeries = Lists.newArrayListWithCapacity(2);
}
""",
"""
import java.util.ArrayList;
import java.util.List;
class Test {
List<Integer> cardinalsWorldSeries = new ArrayList<>(2);
}
Expand All @@ -135,10 +136,10 @@ void showNeedForSuperVisitMethodInvocation() {
java(
"""
import com.google.common.collect.*;
import java.util.Collections;
import java.util.List;
class Test {
List<Integer> cardinalsWorldSeries = Collections.unmodifiableList(Lists.newArrayList());
}
Expand All @@ -147,7 +148,7 @@ class Test {
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Test {
List<Integer> cardinalsWorldSeries = Collections.unmodifiableList(new ArrayList<>());
}
Expand All @@ -167,7 +168,7 @@ void noChangeNecessary() {
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Test {
List<Integer> cardinalsWorldSeries = Collections.unmodifiableList(new ArrayList<>());
}
Expand Down

0 comments on commit d188728

Please sign in to comment.