Skip to content

Commit

Permalink
SONARJAVA-5256 Add example of test using Spring extension of AssertJ
Browse files Browse the repository at this point in the history
To show a false positive that was present before the fix on this branch.
  • Loading branch information
romainbrenguier committed Feb 12, 2025
1 parent 8dc787d commit 0fe83b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions java-checks-test-sources/default/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@
<type>jar</type>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.spring.initializr/initializr-generator -->
<dependency>
<groupId>io.spring.initializr</groupId>
<artifactId>initializr-generator-test</artifactId>
<version>0.21.0</version>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-acl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package checks.tests.AssertionsInTestsCheck;

import io.spring.initializr.generator.test.buildsystem.maven.MavenBuildAssert;
import java.util.List;
import org.assertj.core.api.AbstractListAssert;
import org.assertj.core.api.Assertions;
Expand All @@ -9,9 +10,22 @@
import org.assertj.core.api.SoftAssertions;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import static com.google.gson.internal.TroubleshootingGuide.createUrl;
import static org.mockito.Mockito.mock;

public abstract class AssertJ {

@Test
public void usingExtendedAssert() {
ResponseEntity<String> response = mock(RestTemplate.class).getForEntity(createUrl("/pom.xml?packaging=war"),
String.class);
MavenBuildAssert pomAssert = new MavenBuildAssert(response.getBody());
pomAssert.hasPackaging("war");
}

interface Visitor {
void visit(Object object);
}
Expand Down

0 comments on commit 0fe83b3

Please sign in to comment.