@@ -105,18 +105,19 @@ protected void onMethodInvocationFound(MethodInvocationTree mit) {
105105 checkFestLikeAssertion (mit , symbol , reportLocation );
106106 } else if (type .is ("org.junit.jupiter.api.Assertions" )) {
107107 checkJUnit5 (mit , reportLocation );
108- } else if (mit .arguments ().isEmpty () || expectedMessageArgIsNotString (mit , type ) || isAssertingOnStringWithNoMessage (mit )) {
108+ } else if (mit .arguments ().isEmpty () || ! hasMessageArg (mit , type ) || isAssertingOnStringWithNoMessage (mit )) {
109109 reportIssue (reportLocation , MESSAGE );
110110 }
111111 }
112112
113- private static boolean expectedMessageArgIsNotString (MethodInvocationTree mit , Type type ) {
113+ /**
114+ * True if the call has a message argument. Such an argument is a string
115+ * and it is the first of the last argument (depending on the assertion library).
116+ */
117+ private static boolean hasMessageArg (MethodInvocationTree mit , Type type ) {
118+ int expectedMessageArgIndex = (type .is ("org.testng.Assert" ) || type .is ("org.testng.AssertJUnit" )) ? 1 : 0 ;
114119 List <ExpressionTree > args = mit .arguments ();
115- int expectedMessageArgIndex = 0 ;
116- if (type .is ("org.testng.Assert" ) || type .is ("org.testng.AssertJUnit" )){
117- expectedMessageArgIndex = 1 ;
118- }
119- return args .size () < expectedMessageArgIndex + 1 || !isString (args .get (expectedMessageArgIndex ));
120+ return expectedMessageArgIndex < args .size () && isString (args .get (expectedMessageArgIndex ));
120121 }
121122
122123 private void checkFestLikeAssertion (MethodInvocationTree mit , Symbol symbol , IdentifierTree reportLocation ) {
0 commit comments