-
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.
Add tests for the ConflictDetection utility class
- Loading branch information
1 parent
8350042
commit cf726c2
Showing
2 changed files
with
57 additions
and
1 deletion.
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
56 changes: 56 additions & 0 deletions
56
...-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/ConflictDetectionTest.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,56 @@ | ||
package tech.picnic.errorprone.bugpatterns.util; | ||
|
||
import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; | ||
|
||
import com.google.errorprone.BugPattern; | ||
import com.google.errorprone.CompilationTestHelper; | ||
import com.google.errorprone.VisitorState; | ||
import com.google.errorprone.bugpatterns.BugChecker; | ||
import com.google.errorprone.matchers.Description; | ||
import com.sun.source.tree.MethodTree; | ||
import org.junit.jupiter.api.Test; | ||
|
||
final class ConflictDetectionTest { | ||
@Test | ||
void matcher() { | ||
CompilationTestHelper.newInstance(RenameBlockerFlagger.class, getClass()) | ||
.addSourceLines( | ||
"/A.java", | ||
"class A {", | ||
" private void foo1() {}", | ||
"", | ||
" // BUG: Diagnostic contains: [RenameBlockerFlagger] a method named `foo2t` already exists in this", | ||
" // class", | ||
" private void foo2() {}", | ||
"", | ||
" private void foo2t() {}", | ||
"", | ||
" // BUG: Diagnostic contains: [RenameBlockerFlagger] `foo3t` is already statically imported", | ||
" private void foo3() {}", | ||
"", | ||
" // BUG: Diagnostic contains: [RenameBlockerFlagger] `int` is a reserved keyword", | ||
" private void in() {}", | ||
"}") | ||
.addSourceLines( | ||
"/staticimport/B.java", | ||
"package staticimport;", | ||
"", | ||
"public class B {", | ||
" public static void foo3t() {}", | ||
"}") | ||
.doTest(); | ||
} | ||
|
||
@BugPattern(summary = "Flags blockers for renaming methods", severity = ERROR) | ||
public static final class RenameBlockerFlagger extends BugChecker | ||
implements BugChecker.MethodTreeMatcher { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
public Description matchMethod(MethodTree tree, VisitorState state) { | ||
return ConflictDetection.findMethodRenameBlocker(tree.getName() + "t", state) | ||
.map(blocker -> buildDescription(tree).setMessage(blocker).build()) | ||
.orElse(Description.NO_MATCH); | ||
} | ||
} | ||
} |