Skip to content

Commit 91d4819

Browse files
committed
SONARJAVA-1297 Add precise location assertions in unit tests
1 parent d4b5c94 commit 91d4819

12 files changed

Lines changed: 13 additions & 13 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ void foo() {
33
int a = 0; // Compliant
44
a = 0; // Compliant
55
System.out.println(a); // Compliant
6-
System.out.println(a = 0); // Noncompliant {{Extract the assignment out of this expression.}}
6+
System.out.println(a = 0); // Noncompliant [[sc=26;ec=27]] {{Extract the assignment out of this expression.}}
77
System.out.println(a += 0); // Noncompliant {{Extract the assignment out of this expression.}}
88
System.out.println(a == 0); // Compliant
99

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class BadFieldName {
2-
public int BAD_FIELD_NAME; // Noncompliant {{Rename this field "BAD_FIELD_NAME" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.}}
2+
public int BAD_FIELD_NAME; // Noncompliant [[sc=14;ec=28]] {{Rename this field "BAD_FIELD_NAME" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.}}
33
public int goodFieldName;
44
public static int STATIC;
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class BadFieldName {
22
public int BAD_FIELD_NAME;
33
public int goodFieldName;
4-
public static int BAD_FIELD_NAME_STATIC_NON_FINAL; // Noncompliant {{Rename this field "BAD_FIELD_NAME_STATIC_NON_FINAL" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.}}
4+
public static int BAD_FIELD_NAME_STATIC_NON_FINAL; // Noncompliant [[sc=21;ec=52]] {{Rename this field "BAD_FIELD_NAME_STATIC_NON_FINAL" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.}}
55
public static int goodFieldNameStaticNonFinal;
66
public final static int STATIC; // Compliant, final modifier
77

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ public class CallToDeprecatedMethodCheck {
22

33
public CallToDeprecatedMethodCheck() {
44
String string = new String("my string");
5-
string.getBytes(1, 1, new byte[3], 7); // Noncompliant {{Method 'String.getBytes(...)' is deprecated.}}
5+
string.getBytes(1, 1, new byte[3], 7); // Noncompliant [[sc=5;ec=20]] {{Method 'String.getBytes(...)' is deprecated.}}
66
new DeprecatedConstructor(); // Noncompliant {{Constructor 'DeprecatedConstructor(...)' is deprecated.}}
77
new MyDeprecatedClass();
88
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Foo {
44
private int foo1;
55
int foo2;
66
protected int foo3;
7-
public int foo4; // Noncompliant {{Make foo4 a static final constant or non-public and provide accessors if needed.}}
7+
public int foo4; // Noncompliant [[sc=14;ec=18]] {{Make foo4 a static final constant or non-public and provide accessors if needed.}}
88

99
public static int foo5; // Noncompliant {{Make foo5 a static final constant or non-public and provide accessors if needed.}}
1010
public final int foo6; // Compliant
@@ -27,4 +27,4 @@ static interface blah {
2727
interface bar {
2828
public int blah = 0;
2929

30-
}
30+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class A {
44
String[] strArray1 = {"blue"};
55
String[] strArray2 = {"blue"};
66
private void method() {
7-
if (str1 == str2) {} // Noncompliant {{Change this comparison to use the equals method.}}
7+
if (str1 == str2) {} // Noncompliant [[sc=14;ec=16]] {{Change this comparison to use the equals method.}}
88
if(str1 == "green") {} // Noncompliant {{Change this comparison to use the equals method.}}
99
if (str1.equals(str2)) {}
1010
if(strArray1 == strArray2) {}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class A {
2-
// Noncompliant@+1
2+
// Noncompliant@+1 [[sc=10;ec=11]]
33
public A() {
44
}
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
interface MyInterface {
2-
int a = 1, b = 1; // Noncompliant {{Declare "b" on a separate line.}}
2+
int a = 1, b = 1; // Noncompliant [[sc=14;ec=15]] {{Declare "b" on a separate line.}}
33
}
44

55
enum MyEnum {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Foo {
22
public void myMethod() {
33
if(something) {
44
executeTask();
5-
} else if (somethingElse) { // Noncompliant {{Move this "else" keyword to a new dedicated line.}}
5+
} else if (somethingElse) { // Noncompliant [[sc=7;ec=11]] {{Move this "else" keyword to a new dedicated line.}}
66
doSomethingElse();
77
}
88
else { // Compliant

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public void myMethod() {
55
} else if (somethingElse) { // Compliant
66
doSomethingElse();
77
}
8-
else { // Noncompliant {{Move this "else" on the same line that the previous closing curly brace.}}
8+
else { // Noncompliant [[sc=5;ec=9]] {{Move this "else" on the same line that the previous closing curly brace.}}
99
generateError();
1010
}
1111

0 commit comments

Comments
 (0)