blob: a5a246170b4352eba651512fda2543f02bf139b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
package com.siyeh.ig.logging;
import com.intellij.codeInspection.LocalInspectionTool;
import com.siyeh.ig.LightInspectionTestCase;
public class PlaceholderCountMatchesArgumentCountInspectionTest extends LightInspectionTestCase {
@Override
protected LocalInspectionTool getInspection() {
return new PlaceholderCountMatchesArgumentCountInspection();
}
@Override
protected String[] getEnvironmentClasses() {
return new String[]{
"package org.slf4j; public interface Logger { void info(String format, Object... arguments); }",
"package org.slf4j; public class LoggerFactory { public static Logger getLogger(Class clazz) { return null; }}"};
}
public void testNoWarn() {
doTest("import org.slf4j.*;\n" +
"class X {\n" +
" void foo() {\n" +
" Logger logger = LoggerFactory.getLogger(X.class);\n" +
" logger.info(\"string {}\", 1);\n" +
" }\n" +
"}"
);
}
public void testMorePlaceholders() {
doTest("import org.slf4j.*;\n" +
"class X {\n" +
" void foo() {\n" +
" Logger logger = LoggerFactory.getLogger(X.class);\n" +
" logger./*'info()' call has fewer arguments (1) than placeholders (2)*/info/**/(\"string {}{}\", 1);\n" +
" }\n" +
"}"
);
}
public void testFewerPlaceholders() {
doTest("import org.slf4j.*;\n" +
"class X {\n" +
" void foo() {\n" +
" Logger logger = LoggerFactory.getLogger(X.class);\n" +
" logger./*'info()' call has more arguments (1) than placeholders (0)*/info/**/(\"string\", 1);\n" +
" }\n" +
"}"
);
}
public void testThrowable() {
doTest("import org.slf4j.*;\n" +
"class X {\n" +
" void foo() {\n" +
" Logger logger = LoggerFactory.getLogger(X.class);\n" +
" logger.info(\"string {}\", 1, new RuntimeException());\n" +
" }\n" +
"}"
);
}
}
|