-
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.
Address comments: Add test case for bug checker's flags
- Loading branch information
1 parent
dd55332
commit a54db09
Showing
2 changed files
with
83 additions
and
75 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
106 changes: 59 additions & 47 deletions
106
...one-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclarationTest.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 |
---|---|---|
@@ -1,98 +1,110 @@ | ||
package tech.picnic.errorprone.bugpatterns; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.errorprone.BugCheckerRefactoringTestHelper; | ||
import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; | ||
import com.google.errorprone.CompilationTestHelper; | ||
import org.junit.jupiter.api.Test; | ||
|
||
final class Slf4jLogDeclarationTest { | ||
@Test | ||
void replacement() { | ||
BugCheckerRefactoringTestHelper.newInstance(Slf4jLogDeclaration.class, getClass()) | ||
.addInputLines( | ||
void identification() { | ||
CompilationTestHelper.newInstance(Slf4jLogDeclaration.class, getClass()) | ||
.addSourceLines( | ||
"A.java", | ||
"import org.slf4j.Logger;", | ||
"import org.slf4j.LoggerFactory;", | ||
"", | ||
"// BUG: Diagnostic contains: SLF4J", | ||
"class A {", | ||
" Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(A.class);", | ||
" Logger FOO = LoggerFactory.getLogger(A.class);", | ||
"", | ||
" // BUG: Diagnostic contains: SLF4J", | ||
" static class B {", | ||
" private Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(B.class);", | ||
" private Logger BAR = LoggerFactory.getLogger(B.class);", | ||
" }", | ||
"", | ||
" // BUG: Diagnostic contains: SLF4J", | ||
" static class C {", | ||
" private static Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(C.class);", | ||
" private static Logger BAZ = LoggerFactory.getLogger(C.class);", | ||
" }", | ||
"", | ||
" // BUG: Diagnostic contains: SLF4J", | ||
" static class D {", | ||
" static final Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(D.class);", | ||
" static final Logger QUX = LoggerFactory.getLogger(D.class);", | ||
" }", | ||
"", | ||
" // BUG: Diagnostic contains: SLF4J", | ||
" static class E {", | ||
" private final Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(E.class);", | ||
" private final Logger QUUX = LoggerFactory.getLogger(E.class);", | ||
" }", | ||
"", | ||
" // BUG: Diagnostic contains: SLF4J", | ||
" static class F {", | ||
" private static final Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(F.class);", | ||
" private static final Logger CORGE = LoggerFactory.getLogger(F.class);", | ||
" }", | ||
"", | ||
" // BUG: Diagnostic contains: SLF4J", | ||
" static class G {", | ||
" private static final Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(G.class);", | ||
" private static final Logger GRAPLY = LoggerFactory.getLogger(G.class);", | ||
" }", | ||
"", | ||
" // BUG: Diagnostic contains: SLF4J", | ||
" static class H {", | ||
" private static final Logger LOGGER_WITH_WRONG_CLASS_AS_ARGUMENT =", | ||
" LoggerFactory.getLogger(J.class);", | ||
" private static final Logger WALDO = LoggerFactory.getLogger(J.class);", | ||
" }", | ||
"", | ||
" class J {}", | ||
"", | ||
" // BUG: Diagnostic contains: SLF4J", | ||
" interface K {", | ||
" Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(A.class);", | ||
" Logger FRED = LoggerFactory.getLogger(A.class);", | ||
" }", | ||
"}") | ||
.doTest(); | ||
} | ||
|
||
@Test | ||
void replacementWithDefaultCanonicalizedLoggerName() { | ||
BugCheckerRefactoringTestHelper.newInstance(Slf4jLogDeclaration.class, getClass()) | ||
.addInputLines( | ||
"A.java", | ||
"import org.slf4j.Logger;", | ||
"import org.slf4j.LoggerFactory;", | ||
"", | ||
"class A {", | ||
" Logger FOO = LoggerFactory.getLogger(A.class);", | ||
"}") | ||
.addOutputLines( | ||
"A.java", | ||
"import org.slf4j.Logger;", | ||
"import org.slf4j.LoggerFactory;", | ||
"", | ||
"class A {", | ||
" private static final Logger LOG = LoggerFactory.getLogger(A.class);", | ||
"}") | ||
.doTest(); | ||
} | ||
|
||
@Test | ||
void replacementWithOverriddenCanonicalizedLoggerName() { | ||
BugCheckerRefactoringTestHelper.newInstance(Slf4jLogDeclaration.class, getClass()) | ||
.setArgs(ImmutableList.of("-XepOpt:Slf4jLogDeclaration:CanonicalizedLoggerName=BAR")) | ||
.addInputLines( | ||
"A.java", | ||
"import org.slf4j.Logger;", | ||
"import org.slf4j.LoggerFactory;", | ||
"", | ||
" static class B {", | ||
" private static final Logger LOG = LoggerFactory.getLogger(B.class);", | ||
" }", | ||
"", | ||
" static class C {", | ||
" private static final Logger LOG = LoggerFactory.getLogger(C.class);", | ||
" }", | ||
"", | ||
" static class D {", | ||
" private static final Logger LOG = LoggerFactory.getLogger(D.class);", | ||
" }", | ||
"", | ||
" static class E {", | ||
" private static final Logger LOG = LoggerFactory.getLogger(E.class);", | ||
" }", | ||
"", | ||
" static class F {", | ||
" private static final Logger LOG = LoggerFactory.getLogger(F.class);", | ||
" }", | ||
"", | ||
" static class G {", | ||
" private static final Logger LOG = LoggerFactory.getLogger(G.class);", | ||
" }", | ||
"", | ||
" static class H {", | ||
" private static final Logger LOG = LoggerFactory.getLogger(H.class);", | ||
" }", | ||
"", | ||
" class J {}", | ||
"class A {", | ||
" Logger FOO = LoggerFactory.getLogger(A.class);", | ||
"}") | ||
.addOutputLines( | ||
"A.java", | ||
"import org.slf4j.Logger;", | ||
"import org.slf4j.LoggerFactory;", | ||
"", | ||
" interface K {", | ||
" Logger LOG = LoggerFactory.getLogger(K.class);", | ||
" }", | ||
"class A {", | ||
" private static final Logger BAR = LoggerFactory.getLogger(A.class);", | ||
"}") | ||
.doTest(TestMode.TEXT_MATCH); | ||
.doTest(); | ||
} | ||
} |