Skip to content

Commit

Permalink
Pipeline pre-commit update
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Feb 26, 2024
1 parent 133320e commit da4a447
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.sonatype.cs.getmetrics.service.PolicyIdsService;
import org.sonatype.cs.getmetrics.service.UtilService;

import java.util.ArrayList;
import java.util.List;

import javax.json.JsonArray;
import javax.json.JsonObject;

Expand Down Expand Up @@ -56,7 +58,7 @@ public static String getLicense(JsonArray reasons) {

for (JsonObject reason : reasons.getValuesAs(JsonObject.class)) {
String licenseFound = reason.getString("reason");
if (licenseFound.isEmpty()){
if (licenseFound.isEmpty()) {
continue;
}
String license =
Expand All @@ -69,16 +71,15 @@ public static String getLicense(JsonArray reasons) {
}
}

if (licenses.size()==0){
if (licenses.size() == 0) {
return "";
}

for (String l : licenses) {
if (licenseList.isEmpty()){
if (licenseList.isEmpty()) {
licenseList = l;
}
else{
licenseList = licenseList + ":" +l;
} else {
licenseList = licenseList + ":" + l;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
package org.sonatype.cs.getmetrics.util;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import javax.json.Json;
import javax.json.JsonArray;

public class ParseReasonsTest {
@Test
void testEmptyLicenseString() {
JsonArray reasons = Json.createArrayBuilder()
.add(Json.createObjectBuilder()
.add("reason", ""))
.build();

JsonArray reasons =
Json.createArrayBuilder().add(Json.createObjectBuilder().add("reason", "")).build();

String actualReason = ParseReasons.getLicense(reasons);
Assertions.assertEquals("", actualReason);
}

@Test
void testSingleLicenseString() {
JsonArray reasons = Json.createArrayBuilder()
.add(Json.createObjectBuilder()
.add("reason", "(license)"))
.build();
JsonArray reasons =
Json.createArrayBuilder()
.add(Json.createObjectBuilder().add("reason", "(license)"))
.build();

String actualReason = ParseReasons.getLicense(reasons);
Assertions.assertEquals("license", actualReason);
}

@Test
void testMultipltLicenseString() {
JsonArray reasons = Json.createArrayBuilder()
.add(Json.createObjectBuilder()
.add("reason", "(license)")
)
.add(Json.createObjectBuilder()
.add("reason", "(license2)")
)
.build();

JsonArray reasons =
Json.createArrayBuilder()
.add(Json.createObjectBuilder().add("reason", "(license)"))
.add(Json.createObjectBuilder().add("reason", "(license2)"))
.build();

String actualReason = ParseReasons.getLicense(reasons);
Assertions.assertEquals("license:license2", actualReason);
}
Expand Down

0 comments on commit da4a447

Please sign in to comment.