Skip to content

Commit d853262

Browse files
committed
SONARJAVA-1285 Enable JavaCheckVerifier effortToFix and precise location assertions
1 parent d786530 commit d853262

6 files changed

Lines changed: 13 additions & 21 deletions

File tree

java-checks/src/test/files/checks/ClassComplexityNoncompliant.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
public class HelloWorld { // Noncompliant {{The Cyclomatic Complexity of this class is 4 which is greater than 1 authorized.}}
1+
public class HelloWorld { // Noncompliant [[effortToFix=3]] {{The Cyclomatic Complexity of this class is 4 which is greater than 1 authorized.}}
22

33
public void sayHello() {
44
while (false) {
55
}
66
}
7-
HelloWorld helloWorld = new HelloWorld() { // Noncompliant
7+
HelloWorld helloWorld = new HelloWorld() { // Noncompliant [[effortToFix=1]]
88
@Override
99
public void sayHello() {
1010
while (false){

java-checks/src/test/files/checks/MethodComplexityNoncompliant.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
public class HelloWorld {
22

3-
public void sayHello() { // Noncompliant {{The Cyclomatic Complexity of this method "sayHello" is 2 which is greater than 1 authorized.}}
3+
public void sayHello() { // Noncompliant [[effortToFix=1]] {{The Cyclomatic Complexity of this method "sayHello" is 2 which is greater than 1 authorized.}}
44
while (false) {
55
}
66
}

java-checks/src/test/files/checks/SystemExitCalledCheck.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
class A {
22
void f() {
33
System.exit(0); // Noncompliant {{Remove this call to "exit" or ensure it is really required.}}
4-
int a = System.exit(0); // Noncompliant {{Remove this call to "exit" or ensure it is really required.}}
4+
int a = System.exit(0); // Noncompliant [[sc=13;ec=24]] {{Remove this call to "exit" or ensure it is really required.}}
55
System.gc(); // Compliant
66
System.exit[0]; // Compliant
77
exit(); // Compliant
8-
Runtime.getRuntime().exit(); // Noncompliant {{Remove this call to "exit" or ensure it is really required.}}
8+
Runtime.getRuntime().exit(); // Noncompliant [[sc=5;ec=30]] {{Remove this call to "exit" or ensure it is really required.}}
99
Runtime.getRuntime().foo; // Compliant
1010
Runtime.getRuntime().foo(); // Compliant
1111
Runtime.getRuntime()++; // Compliant

java-checks/src/test/files/checks/SystemOutOrErrUsageCheck.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ class A {
22

33
void f() {
44
System.out.println(""); // Noncompliant {{Replace this usage of System.out or System.err by a logger.}}
5-
System.err.println(""); // Noncompliant {{Replace this usage of System.out or System.err by a logger.}}
5+
System.err.println(""); // Noncompliant [[sc=5;ec=15]]
66

7-
f(System.out); // Noncompliant {{Replace this usage of System.out or System.err by a logger.}}
7+
f(System.out); // Noncompliant
88

99
System.arraycopy(null, 0, null, 0, 0); // Compliant
10-
java.lang.System.out.println(""); // Noncompliant {{Replace this usage of System.out or System.err by a logger.}}
10+
java.lang.System.out.println(""); // Noncompliant [[sc=5;ec=25]]
11+
java.lang. // Noncompliant [[sc=5;el=+1;ec=17]]
12+
System.out.println("");
1113
}
1214

1315
}

java-checks/src/test/java/org/sonar/java/checks/ClassComplexityCheckTest.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@
1919
*/
2020
package org.sonar.java.checks;
2121

22-
import org.sonar.java.checks.verifier.JavaCheckVerifier;
23-
import org.sonar.java.model.VisitorsBridge;
24-
import org.sonar.squidbridge.checks.CheckMessagesVerifier;
2522
import org.junit.Test;
26-
import org.sonar.java.ast.JavaAstScanner;
27-
import org.sonar.squidbridge.api.SourceFile;
28-
29-
import java.io.File;
23+
import org.sonar.java.checks.verifier.JavaCheckVerifier;
3024

3125
public class ClassComplexityCheckTest {
3226

@@ -39,11 +33,7 @@ public void defaults() {
3933
public void test() {
4034
ClassComplexityCheck check = new ClassComplexityCheck();
4135
check.setMax(1);
42-
SourceFile file = JavaAstScanner.scanSingleFile(new File("src/test/files/checks/ClassComplexityNoncompliant.java"), new VisitorsBridge(check));
43-
CheckMessagesVerifier.verify(file.getCheckMessages())
44-
.next().atLine(1).withMessage("The Cyclomatic Complexity of this class is 4 which is greater than 1 authorized.").withCost(3.0)
45-
.next().atLine(7).withMessage("The Cyclomatic Complexity of this class is 2 which is greater than 1 authorized.").withCost(1.0)
46-
.noMore();
36+
JavaCheckVerifier.verify("src/test/files/checks/ClassComplexityNoncompliant.java", check);
4737
}
4838

4939
}

java-checks/src/test/java/org/sonar/java/checks/SystemOutOrErrUsageCheckTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
public class SystemOutOrErrUsageCheckTest {
2626
@Test
27-
public void detected() {
27+
public void test() {
2828
JavaCheckVerifier.verify("src/test/files/checks/SystemOutOrErrUsageCheck.java", new SystemOutOrErrUsageCheck());
2929
}
3030
}

0 commit comments

Comments
 (0)