False Positive java:S2699 with rest assured https://rest-assured.io/

  • Operating system:
    Windows 10
  • IDE name and flavor/env:
    Eclipse 4.23.0
  • SonarLint plugin version:
    SonarLint for Eclipse 7.4.0.46482
  • Is connected mode used:
    No
  • Framework:
    Rest Assured 4.4.0

SonarLint supports rest assured ( [SONARJAVA-2230] FP on S2699 (tests should include assert) when using rest-assured framework - SonarSource).

But when make assertion only with status:

...
import static org.springframework.http.HttpStatus.FORBIDDEN;
import org.junit.jupiter.api.Test;
import io.restassured.module.mockmvc.RestAssuredMockMvc;
....
        @Test
	void given_userWithRoleGestor_when_findByIdNoAsignated_then_forbidden(String id) throws Exception {
		RestAssuredMockMvc.given()
		.when()
			.get("/api/expedientes/{id}", id)
		.then()
			.status(FORBIDDEN);
	  // @formatter:on
	}

SonarLint activate java:S2699 rule (Tests should include assertions).

Hi @ma3, and welcome to the community,

Thanks for providing all this info. I had a hard time tracking down the right rest-assured artifact but can you confirm that this is the version of rest-assured that your project depends on?

Hi, yes, is correct. I confirm that spring-mock-mvc 4.4.0 is the artifact that contains io.restassured.module.mockmvc.response.ValidatableMockMvcResponse.status method.

Thanks.

Thanks @ma3 a ticket has been created to handle the issue.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

Great news! The ticket has been implemented, and now we also detect RestAssuredMockMvc. This update should be soon available on SonarQube for Cloud and released with SonarQube Server 10.9.