Skip to content

Commit

Permalink
SONARJAVA-4427 add andExpect to assertions methods patterns to suppor…
Browse files Browse the repository at this point in the history
…t Spring test methods (#4607)
  • Loading branch information
erwan-serandour authored Dec 7, 2023
1 parent ebac5e9 commit 8f7ae0f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions java-checks-test-sources/default/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@
<version>4.1.2.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-test</artifactId>
<version>4.0.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.ResultHandler;
import org.springframework.test.web.servlet.ResultMatcher;
import org.springframework.ws.test.server.MockWebServiceClient;

class SpringTest {

Expand Down Expand Up @@ -35,6 +36,14 @@ public void fakeTest2() throws Exception { // Compliant
public void andExpectAllTest() throws Exception { // Compliant
getResultActions().andDo(getResultHandler()).andExpectAll(getResultMatcher(), getResultMatcher()).andReturn();
}

@Test
public void mockWebServiceClient(){ // Compliant
MockWebServiceClient server = null;
server.sendRequest(null)
.andExpect(null)
.andExpect(null);
}

private ResultActions getResultActions() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
public final class UnitTestUtils {

private static final String ORG_JUNIT_TEST = "org.junit.Test";
public static final Pattern ASSERTION_METHODS_PATTERN = Pattern.compile("(assert|verify|fail|should|check|expect|validate).*");
public static final Pattern ASSERTION_METHODS_PATTERN = Pattern.compile("(assert|verify|fail|should|check|expect|validate|andExpect).*");
public static final Pattern TEST_METHODS_PATTERN = Pattern.compile("test.*|.*Test");

public static final MethodMatchers ASSERTION_INVOCATION_MATCHERS = MethodMatchers.or(
Expand Down

0 comments on commit 8f7ae0f

Please sign in to comment.