mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Java. Logging] Add tests for field based logger
IDEA-345098 GitOrigin-RevId: 5176d6bb359fc804b857951225cc0a3f2afecfa6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0be37f33b6
commit
0eae1f68c1
@@ -0,0 +1,10 @@
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class A {
|
||||
private static final Log log = LogFactory.getLog(A.class);
|
||||
|
||||
void foo() {
|
||||
log
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class A {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(A.class);
|
||||
|
||||
void foo() {
|
||||
log.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class A {
|
||||
private static final Logger log = Logger.getLogger(A.class);
|
||||
|
||||
void foo() {
|
||||
log
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class A {
|
||||
private static final Logger log = LogManager.getLogger(A.class);
|
||||
|
||||
void foo() {
|
||||
log
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class A {
|
||||
private static final Logger log = LogManager.getLogger(A.class);
|
||||
|
||||
void foo() {
|
||||
log
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class A {
|
||||
private static final Logger log = LoggerFactory.getLogger(A.class);
|
||||
|
||||
public static class B {
|
||||
void foo() {
|
||||
log
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class A {
|
||||
private static final Logger log = LoggerFactory.getLogger(A.class);
|
||||
|
||||
void foo() {
|
||||
log
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class A {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(A.class);
|
||||
|
||||
void foo() {
|
||||
int log = 10;
|
||||
A.log
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public class A {
|
||||
void foo() {
|
||||
lo<caret>
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
public class A {
|
||||
|
||||
void foo() {
|
||||
log<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public class A {
|
||||
void foo() {
|
||||
lo<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public class A {
|
||||
void foo() {
|
||||
lo<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public class A {
|
||||
void foo() {
|
||||
lo<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
public class A {
|
||||
public static class B {
|
||||
void foo() {
|
||||
lo<caret>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public class A {
|
||||
void foo() {
|
||||
lo<caret>
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
public class A {
|
||||
|
||||
void foo() {
|
||||
int log = 10;
|
||||
lo<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class A {
|
||||
private static final Logger log = LoggerFactory.getLogger(A.class);
|
||||
|
||||
void foo() {
|
||||
lo<caret>
|
||||
}
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.codeInsight.completion
|
||||
|
||||
import com.intellij.JavaTestUtil
|
||||
import com.intellij.codeInsight.CodeInsightSettings
|
||||
import com.intellij.codeInsight.completion.JvmLoggerLookupElement
|
||||
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase
|
||||
import com.intellij.java.codeInsight.JvmLoggerTestSetupUtil
|
||||
import junit.framework.TestCase
|
||||
|
||||
class LoggerCompletionTest : LightFixtureCompletionTestCase() {
|
||||
fun testSlf4j() {
|
||||
JvmLoggerTestSetupUtil.setupSlf4j(myFixture)
|
||||
doTest(1, "long", "log", "clone")
|
||||
}
|
||||
|
||||
fun testLog4j2() {
|
||||
JvmLoggerTestSetupUtil.setupLog4j2(myFixture)
|
||||
doTest(1, "long", "log", "clone")
|
||||
}
|
||||
|
||||
fun testLog4j() {
|
||||
JvmLoggerTestSetupUtil.setupLog4j(myFixture)
|
||||
doTest(1, "long", "log", "clone")
|
||||
}
|
||||
|
||||
fun testApacheCommons() {
|
||||
JvmLoggerTestSetupUtil.setupApacheCommons(myFixture)
|
||||
doTest(1, "long", "log", "clone")
|
||||
}
|
||||
|
||||
fun testNestedClasses() {
|
||||
JvmLoggerTestSetupUtil.setupSlf4j(myFixture)
|
||||
doTest(1, "long", "log", "clone")
|
||||
}
|
||||
|
||||
fun testMultipleLoggers() {
|
||||
JvmLoggerTestSetupUtil.setupSlf4j(myFixture)
|
||||
JvmLoggerTestSetupUtil.setupLog4j2(myFixture)
|
||||
doTest(2, "long", "log", "log", "clone")
|
||||
}
|
||||
|
||||
fun testLoggerAlreadyExists() {
|
||||
JvmLoggerTestSetupUtil.setupSlf4j(myFixture)
|
||||
val name = getTestName(false)
|
||||
configureByFile("$name.java")
|
||||
assertStringItems("log", "long", "clone")
|
||||
|
||||
TestCase.assertFalse(
|
||||
lookup.items.any {
|
||||
it is JvmLoggerLookupElement
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fun testStaticQualifierWithLocalVariable() {
|
||||
JvmLoggerTestSetupUtil.setupSlf4j(myFixture)
|
||||
doTest(2, "log", "long", "log", "clone")
|
||||
}
|
||||
|
||||
fun testAutoCompletionAfterDot() {
|
||||
var isAutoComplete = true
|
||||
try {
|
||||
isAutoComplete = CodeInsightSettings.getInstance().isSelectAutopopupSuggestionsByChars
|
||||
CodeInsightSettings.getInstance().isSelectAutopopupSuggestionsByChars = true
|
||||
JvmLoggerTestSetupUtil.setupSlf4j(myFixture)
|
||||
val name = getTestName(false)
|
||||
configureByFile("before$name.java")
|
||||
|
||||
myFixture.type(".")
|
||||
checkResultByFile("after$name.java")
|
||||
}
|
||||
finally {
|
||||
CodeInsightSettings.getInstance().isSelectAutopopupSuggestionsByChars = isAutoComplete
|
||||
}
|
||||
}
|
||||
|
||||
override fun getBasePath() = JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/logger"
|
||||
|
||||
private fun doTest(position: Int, vararg names: String) {
|
||||
val name = getTestName(false)
|
||||
configureByFile("before$name.java")
|
||||
assertStringItems(*names)
|
||||
|
||||
val item = lookup.items[position]
|
||||
selectItem(item)
|
||||
checkResultByFile("after$name.java")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user