Skip to content

Commit

Permalink
Merge pull request #112 from InseeFr/feat/jacoco
Browse files Browse the repository at this point in the history
feat: add jacoco maven plugin
  • Loading branch information
EmmanuelDemey authored Dec 17, 2024
2 parents 2931d0b + d12d803 commit e14fe1f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -X -B clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Pcoverage
run: mvn -B clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Pcoverage
24 changes: 23 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<json-simple.version>1.1.1</json-simple.version>
<commons-io.version>2.17.0</commons-io.version>
<io.swagger.version>1.6.14</io.swagger.version>

<jacoco.version>0.8.12</jacoco.version>
<sonar.organization>inseefr</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.projectKey>InseeFr_DDI-Access-Services</sonar.projectKey>
Expand Down Expand Up @@ -184,6 +184,28 @@
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<!-- Prepare the property pointing to the JaCoCo runtime agent which is
passed as VM argument when the Maven Surefire plugin is executed. -->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/fr/insee/rmes/utils/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
import java.util.Arrays;

public class StringUtils {

private StringUtils() {
private StringUtils() {
throw new IllegalStateException("Utility class");
}

public static boolean stringContainsItemFromList(String string, String[] list) {
return Arrays.stream(list).anyMatch(string::contains);
public static boolean stringContainsItemFromList(String token, String[] list) {
return Arrays.stream(list).anyMatch(token::contains);
}


}
58 changes: 58 additions & 0 deletions src/test/java/fr/insee/rmes/utils/StringUtilsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package fr.insee.rmes.utils;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class StringUtilsTest {

@Test
void testStringContainsItemFromList_WhenTokenContainsAnItem_ShouldReturnTrue() {
String token = "hello world";
String[] list = {"hello", "test", "example"};

boolean result = StringUtils.stringContainsItemFromList(token, list);

assertTrue(result, "The token contains an item from the list, so it should return true");
}

@Test
void testStringContainsItemFromList_WhenTokenDoesNotContainAnyItem_ShouldReturnFalse() {
String token = "goodbye world";
String[] list = {"hello", "test", "example"};

boolean result = StringUtils.stringContainsItemFromList(token, list);

assertFalse(result, "The token does not contain any item from the list, so it should return false");
}

@Test
void testStringContainsItemFromList_WhenListIsEmpty_ShouldReturnFalse() {
String token = "hello world";
String[] list = {};

boolean result = StringUtils.stringContainsItemFromList(token, list);

assertFalse(result, "An empty list should always return false");
}

@Test
void testStringContainsItemFromList_WhenTokenIsEmpty_ShouldReturnFalse() {
String token = "";
String[] list = {"hello", "test"};

boolean result = StringUtils.stringContainsItemFromList(token, list);

assertFalse(result, "An empty token should return false");
}

@Test
void testStringContainsItemFromList_WhenBothTokenAndListAreEmpty_ShouldReturnFalse() {
String token = "";
String[] list = {};

boolean result = StringUtils.stringContainsItemFromList(token, list);

assertFalse(result, "An empty token and an empty list should return false");
}
}

0 comments on commit e14fe1f

Please sign in to comment.