-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1931898
commit 0d45c3a
Showing
5 changed files
with
94 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...ne-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ClassCastLambdaUsageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package tech.picnic.errorprone.bugpatterns; | ||
|
||
import com.google.errorprone.BugCheckerRefactoringTestHelper; | ||
import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; | ||
import com.google.errorprone.CompilationTestHelper; | ||
import org.junit.jupiter.api.Test; | ||
|
||
final class ClassCastLambdaUsageTest { | ||
@Test | ||
void identification() { | ||
CompilationTestHelper.newInstance(ClassCastLambdaUsage.class, getClass()) | ||
.addSourceLines( | ||
"A.java", | ||
"import com.google.common.collect.ImmutableSet;", | ||
"import java.util.stream.Stream;", | ||
"", | ||
"class A {", | ||
" void m() {", | ||
" Number localVariable = 0;", | ||
"", | ||
" Stream.of(0).map(i -> i);", | ||
" Stream.of(1).map(i -> i + 1);", | ||
" Stream.of(2).map(Integer.class::cast);", | ||
" Stream.of(3).map(i -> (Integer) 2);", | ||
" Stream.of(4).map(i -> (Integer) localVariable);", | ||
" // XXX: Ideally this case is also flagged. Pick this up in the context of merging the", | ||
" // `ClassCastLambdaUsage` and `MethodReferenceUsage` checks, or introduce a separate check that", | ||
" // simplifies unnecessary block lambda expressions.", | ||
" Stream.of(5)", | ||
" .map(", | ||
" i -> {", | ||
" return (Integer) i;", | ||
" });", | ||
" Stream.<ImmutableSet>of(ImmutableSet.of(5)).map(l -> (ImmutableSet<Number>) l);", | ||
" Stream.of(ImmutableSet.of(6)).map(l -> (ImmutableSet<?>) l);", | ||
" Stream.of(7).reduce((a, b) -> (Integer) a);", | ||
"", | ||
" // BUG: Diagnostic contains:", | ||
" Stream.of(8).map(i -> (Integer) i);", | ||
" }", | ||
"}") | ||
.doTest(); | ||
} | ||
|
||
@Test | ||
void replacement() { | ||
BugCheckerRefactoringTestHelper.newInstance(ClassCastLambdaUsage.class, getClass()) | ||
.addInputLines( | ||
"A.java", | ||
"import java.util.stream.Stream;", | ||
"", | ||
"class A {", | ||
" void m() {", | ||
" Stream.of(1).map(i -> (Integer) i);", | ||
" }", | ||
"}") | ||
.addOutputLines( | ||
"A.java", | ||
"import java.util.stream.Stream;", | ||
"", | ||
"class A {", | ||
" void m() {", | ||
" Stream.of(1).map(Integer.class::cast);", | ||
" }", | ||
"}") | ||
.doTest(TestMode.TEXT_MATCH); | ||
} | ||
} |
62 changes: 0 additions & 62 deletions
62
error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ClassCastTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters