File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
java-checks-test-sources/default/src/test/java/checks/tests
java-checks/src/main/java/org/sonar/java/checks/tests Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,10 @@ void foo() {
1717 org .testng .Assert .assertTrue (true , "msg" ); // Compliant
1818 org .testng .Assert .assertTrue (true ); // Noncompliant
1919 org .testng .AssertJUnit .assertTrue (true ); // Noncompliant
20+
21+ org .testng .Assert .fail (); // Noncompliant
22+ org .testng .Assert .fail ("msg" ); // Compliant
23+
2024 org .assertj .core .api .Assertions .assertThat ("" ).usingComparator (null ).as ("a" ).isEqualTo (222 ); // Compliant
2125 org .junit .Assert .assertTrue (true ); // Noncompliant {{Add a message to this assertion.}}
2226// ^^^^^^^^^^
Original file line number Diff line number Diff line change @@ -115,7 +115,14 @@ protected void onMethodInvocationFound(MethodInvocationTree mit) {
115115 * and it is the first of the last argument (depending on the assertion library).
116116 */
117117 private static boolean hasMessageArg (MethodInvocationTree mit , Type type ) {
118- int expectedMessageArgIndex = (type .is ("org.testng.Assert" ) || type .is ("org.testng.AssertJUnit" )) ? 1 : 0 ;
118+ int expectedMessageArgIndex ;
119+ if (mit .methodSymbol ().name ().equals ("fail" )) {
120+ expectedMessageArgIndex = 0 ;
121+ } else if (type .is ("org.testng.Assert" ) || type .is ("org.testng.AssertJUnit" )) {
122+ expectedMessageArgIndex = 1 ;
123+ } else {
124+ expectedMessageArgIndex = 0 ;
125+ }
119126 List <ExpressionTree > args = mit .arguments ();
120127 return expectedMessageArgIndex < args .size () && isString (args .get (expectedMessageArgIndex ));
121128 }
You can’t perform that action at this time.
0 commit comments