Skip to content

Commit e90e626

Browse files
SONARJAVA-4260 add RestAssuredMockMvc assertions to list of test assertions (#4951)
1 parent 861decd commit e90e626

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

java-checks-test-sources/default/pom.xml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@
609609
<scope>provided</scope>
610610
</dependency>
611611
<dependency>
612-
<groupId>com.google.truth.extensions </groupId>
612+
<groupId>com.google.truth.extensions</groupId>
613613
<artifactId>truth-java8-extension</artifactId>
614614
<version>0.39</version>
615615
<scope>provided</scope>
@@ -638,6 +638,12 @@
638638
<version>3.0.2</version>
639639
<scope>provided</scope>
640640
</dependency>
641+
<dependency>
642+
<groupId>io.rest-assured</groupId>
643+
<artifactId>spring-mock-mvc</artifactId>
644+
<version>4.4.0</version>
645+
<scope>test</scope>
646+
</dependency>
641647
<dependency>
642648
<groupId>com.fasterxml.jackson.core</groupId>
643649
<artifactId>jackson-annotations</artifactId>
@@ -921,25 +927,25 @@
921927
<artifactId>aspectjweaver</artifactId>
922928
<version>1.9.9.1</version>
923929
<scope>provided</scope>
924-
</dependency>
925-
<dependency>
926-
<groupId>io.micronaut</groupId>
927-
<artifactId>micronaut-http</artifactId>
928-
<version>3.7.2</version>
929-
<scope>provided</scope>
930-
</dependency>
930+
</dependency>
931+
<dependency>
932+
<groupId>io.micronaut</groupId>
933+
<artifactId>micronaut-http</artifactId>
934+
<version>3.7.2</version>
935+
<scope>provided</scope>
936+
</dependency>
931937
<dependency>
932938
<groupId>com.fasterxml.woodstox</groupId>
933939
<artifactId>woodstox-core</artifactId>
934940
<version>6.4.0</version>
935941
<scope>provided</scope>
936942
</dependency>
937943
<dependency>
938-
<groupId>org.bouncycastle</groupId>
939-
<artifactId>bcprov-jdk15on</artifactId>
940-
<version>1.70</version>
941-
<scope>provided</scope>
942-
</dependency>
944+
<groupId>org.bouncycastle</groupId>
945+
<artifactId>bcprov-jdk15on</artifactId>
946+
<version>1.70</version>
947+
<scope>provided</scope>
948+
</dependency>
943949
<dependency>
944950
<groupId>org.hibernate.javax.persistence</groupId>
945951
<artifactId>hibernate-jpa-2.0-api</artifactId>

java-checks-test-sources/default/src/test/java/checks/tests/AssertionsInTestsCheck/RestAssured.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package checks.tests.AssertionsInTestsCheck;
22

33
import io.restassured.RestAssured;
4+
import io.restassured.module.mockmvc.RestAssuredMockMvc;
45
import io.restassured.builder.ResponseSpecBuilder;
56
import io.restassured.response.ValidatableResponse;
67
import io.restassured.specification.ResponseSpecification;
@@ -10,6 +11,7 @@
1011
import static org.hamcrest.Matchers.equalTo;
1112
import static org.hamcrest.Matchers.is;
1213
import static org.hamcrest.Matchers.lessThan;
14+
import static org.springframework.http.HttpStatus.FORBIDDEN;
1315

1416
class RestAssuredTest {
1517

@@ -130,4 +132,14 @@ public void test_time() { // Compliant
130132
.then()
131133
.time(lessThan(2L), SECONDS);
132134
}
135+
136+
@Test
137+
public void test_status() {
138+
139+
RestAssuredMockMvc.given()
140+
.when()
141+
.get("/api/expedientes")
142+
.then()
143+
.status(FORBIDDEN);
144+
}
133145
}

java-checks/src/main/java/org/sonar/java/checks/helpers/UnitTestUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ public final class UnitTestUtils {
4747
MethodMatchers.create().ofSubTypes("org.fest.assertions.GenericAssert", "org.fest.assertions.api.AbstractAssert").anyName().withAnyParameters().build(),
4848
// rest assured 2.x, 3.x, 4.x
4949
MethodMatchers.create().ofTypes(
50-
"com.jayway.restassured.response.ValidatableResponseOptions", // restassured 2.x
51-
"io.restassured.response.ValidatableResponseOptions" // restassured 3.x and 4.x
52-
)
50+
"com.jayway.restassured.response.ValidatableResponseOptions", // restassured 2.x
51+
"io.restassured.response.ValidatableResponseOptions", // restassured 3.x and 4.x
52+
"io.restassured.module.mockmvc.response.ValidatableMockMvcResponse" // spring mock mvc extending the io.restassured library
53+
)
5354
.name(name -> "body".equals(name) ||
5455
"time".equals(name) ||
5556
name.startsWith("time") ||

0 commit comments

Comments
 (0)