Skip to content

Commit

Permalink
refactoring IT classes and add GCI94 IT
Browse files Browse the repository at this point in the history
  • Loading branch information
dedece35 committed Jan 2, 2025
1 parent b84f138 commit 2f490a0
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 112 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@
<version>1.5.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.36</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.greencodeinitiative.creedengo.java.integration.tests;

import org.junit.jupiter.api.Test;
import org.sonarqube.ws.Issues;
import org.sonarqube.ws.Measures;

import java.util.*;

import static java.util.Optional.ofNullable;
import static org.assertj.core.api.Assertions.assertThat;

class BaseIT extends LaunchSonarqubeAndBuildProject {

@Test
void testMeasuresAndIssues() {
String projectKey = analyzedProjects.get(0).getProjectKey();

Map<String, Measures.Measure> measures = getMeasures(projectKey);

assertThat(ofNullable(measures.get("code_smells")).map(Measures.Measure::getValue).map(Integer::parseInt).orElse(0))
.isGreaterThan(1);

List<Issues.Issue> projectIssues = issuesForComponent(projectKey);
assertThat(projectIssues).isNotEmpty();

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.greencodeinitiative.creedengo.java.integration.tests;

import org.junit.jupiter.api.Test;
import org.sonarqube.ws.Issues;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.sonarqube.ws.Common.RuleType.CODE_SMELL;
import static org.sonarqube.ws.Common.Severity.MINOR;

class GCI69IT extends LaunchSonarqubeAndBuildProject {

@Test
void testGCI69() {
String projectKey = analyzedProjects.get(0).getProjectKey();

List<Issues.Issue> issuesForArrayCopyCheck = issuesForFile(projectKey, "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java");

assertThat(issuesForArrayCopyCheck)
.hasSize(1)
.first().satisfies(issue -> verifyIssue(issue, IssueDetails.builder()
.rule("creedengo-java:GCI69")
.message("Do not call a function when declaring a for-type loop")
.line(18)
.startLine(18)
.endLine(18)
.startOffset(15)
.endOffset(27)
.severity(MINOR)
.type(CODE_SMELL)
.debt("5min")
.effort("5min")
.build())
);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.greencodeinitiative.creedengo.java.integration.tests;

import org.junit.jupiter.api.Test;
import org.sonarqube.ws.Issues;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.sonarqube.ws.Common.RuleType.CODE_SMELL;
import static org.sonarqube.ws.Common.Severity.MINOR;

class GCI94IT extends LaunchSonarqubeAndBuildProject {

@Test
void testGCI94() {
String projectKey = analyzedProjects.get(0).getProjectKey();

List<Issues.Issue> issuesForArrayCopyCheck = issuesForFile(projectKey, "src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java");

assertThat(issuesForArrayCopyCheck)
.hasSize(1)
.first().satisfies(issue -> verifyIssue(issue, IssueDetails.builder()
.rule("creedengo-java:GCI94")
.message("Use optional orElseGet instead of orElse.")
.line(25)
.startLine(25)
.endLine(25)
.startOffset(38)
.endOffset(69)
.severity(MINOR)
.type(CODE_SMELL)
.debt("1min")
.effort("1min")
.build())
);

}

}
Loading

0 comments on commit 2f490a0

Please sign in to comment.