mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
[java-inspections] IDEA-331308 Similar logs inspection
GitOrigin-RevId: 33b43026b651dfee14eaa91e978c0c0c2b793ba2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
da0308f481
commit
8efd59f2ec
@@ -0,0 +1,501 @@
|
||||
package com.intellij.codeInspection.tests.java.logging
|
||||
|
||||
import com.intellij.jvm.analysis.internal.testFramework.logging.LoggingSimilarMessageInspectionTestBase
|
||||
import com.intellij.jvm.analysis.testFramework.JvmLanguage
|
||||
|
||||
class JavaLoggingSimilarMessageInspectionTest : LoggingSimilarMessageInspectionTestBase() {
|
||||
|
||||
fun `test equals log4j2`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = "log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = "log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test not completed log4j2`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = "{}" + i;
|
||||
LOG.info(msg);
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = "{}" + i;
|
||||
LOG.info(msg);
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test not completed 2 log4j2`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = "{} {}";
|
||||
LOG.info(msg);
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = "{} {}";
|
||||
LOG.info(msg);
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test many equals log4j2`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = "log messages2: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = "log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request3(int i) {
|
||||
String msg = "log messages2: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request4(int i) {
|
||||
String msg = "log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request5(int i) {
|
||||
String msg = "log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request6(int i) {
|
||||
String msg = "log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request7(int i) {
|
||||
String msg = "log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request8(int i) {
|
||||
String msg = "log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request9(int i) {
|
||||
String msg = "log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request10(int i) {
|
||||
String msg = "log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test equals slf4j`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.slf4j.*;
|
||||
class Logging {
|
||||
private static Logger LOG = LoggerFactory.getLogger(Logging.class);
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = "log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = "log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
|
||||
fun `test setMessage equals slf4j`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.slf4j.*;
|
||||
class Logging {
|
||||
private static Logger LOG = LoggerFactory.getLogger(Logging.class);
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = "log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = "log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test not equals level slf4j`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.slf4j.*;
|
||||
import org.slf4j.spi.*;
|
||||
class X {
|
||||
|
||||
void foo() {
|
||||
Logger logger = LoggerFactory.getLogger(X.class);
|
||||
|
||||
<weak_warning descr="Similar log messages">logger.atError()
|
||||
.setMessage("aaa {}")
|
||||
.log()</weak_warning>;
|
||||
|
||||
<weak_warning descr="Similar log messages">logger.atError()
|
||||
.setMessage("aaa 2{}")
|
||||
.log()</weak_warning>;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test not equals log4j2`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = "log 2 messages: " + i;
|
||||
LOG.info(msg);
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = "log messages: " + i;
|
||||
LOG.info(msg);
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test not equals end log4j2`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = i + ": log 2 messages";
|
||||
LOG.info(msg);
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = i + ": log messages";
|
||||
LOG.info(msg);
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test endWith log4j2`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = i + "2: log messages";
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = i + ": log messages";
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test endWith2 log4j2`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = i + ": log messages";
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = i + "2: log messages";
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test startWith log4j2`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = "log messages" + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = "log messages2" + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test startWith 2 log4j2`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = "log messages2" + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = "log messages" + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test equals end log4j2`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = i + ": log messages";
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = i + ": log messages";
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test many equals end log4j2 without highlighting`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = i + ": log messages";
|
||||
LOG.info(msg);
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = i + ": log messages";
|
||||
LOG.info(msg);
|
||||
}
|
||||
private static void request3(int i) {
|
||||
String msg = i + ": log messages";
|
||||
LOG.info(msg);
|
||||
}
|
||||
private static void request4(int i) {
|
||||
String msg = i + ": log messages";
|
||||
LOG.info(msg);
|
||||
}
|
||||
private static void request5(int i) {
|
||||
String msg = i + ": log messages";
|
||||
LOG.info(msg);
|
||||
}
|
||||
private static void request6(int i) {
|
||||
String msg = i + ": log messages";
|
||||
LOG.info(msg);
|
||||
}
|
||||
private static void request7(int i) {
|
||||
String msg = i + ": log messages";
|
||||
LOG.info(msg);
|
||||
}
|
||||
private static void request8(int i) {
|
||||
String msg = i + ": log messages";
|
||||
LOG.info(msg);
|
||||
}
|
||||
private static void request9(int i) {
|
||||
String msg = i + ": log messages";
|
||||
LOG.info(msg);
|
||||
}
|
||||
|
||||
private static void request10(int i) {
|
||||
String msg = i + ": log messages";
|
||||
LOG.info(msg);
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test equals middle log4j2`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = i + ": log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = i + ": log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test equals middle contains log4j2`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = i + ": log messages: 2" + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = i + ": log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test equals middle contains 2 log4j2`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = i + ": log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = i + ": log messages: 2" + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test equals middle contains 3 log4j2`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = i + "2: log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = i + ": log messages:" + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test equals middle contains 4 log4j2`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = i + ": log messages:" + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = i + "2: log messages:" + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info(msg)</weak_warning>;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test not equals middle log4j2`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
String msg = i + ": log messages: " + i;
|
||||
LOG.info(msg);
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = i + ": log 2 messages: " + i;
|
||||
LOG.info(msg);
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test equals log4j2 with placeholders`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.apache.logging.log4j.*;
|
||||
class Logging {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
private static void request1(String i) {
|
||||
<weak_warning descr="Similar log messages">LOG.info("log messages: ", i)</weak_warning>;
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
String msg = "log messages: " + i;
|
||||
<weak_warning descr="Similar log messages">LOG.info("log messages: ", i)</weak_warning>;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user